1800: Problem D: Demerit Points
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 4 Solved: 3
[ Submit][ Status][ Web Board]
Description
Problem D: Demerit Points
A province to our west, which shall remain nameless, but whose name does not start with A, B, or S, has a unique system for driver's license demerit and merit points. The system works (more or less) as follows.
A new driver starts with no merit or demerit points. When the driver is convicted of a driving offense, he or she is given between 2 and 15 demerit points, depending on the severity of the offense.
A merit point is given, to a maximum of five, for each interval of two years in which a driver has no offenses and no demerit points. Each merit point cancels up to two demerit points. If a subsequent offense occurs and the number of demerit points exceeds double the number of merit points, the number of demerit points is reduced by double the number of merit points, and the number of merit points is set to 0. If a subsequent offense occurs and the number of demerit points is less than or equal to double the number of merit points, the number of demerit points is reduced to 0, and the number of merit points is reduced by half the number of demerit points. Any fractional merit points are discarded.
Demerit points are reduced whenever a driver has one year free of any driving offense. This reduction decreases the number of demerits by half or by 2, whichever is more. Any fractional or negative demerit points are discarded. This reduction takes place on each anniversary of the most recent offense until no points remain.
If a new offense occurs on the same day as a demerit point reduction or merit point award, the reduction/award is done before the new demerit points are given.
Your job is to read a set of information records for a driver, and to print the number of merit or demerit points at any given time.
The first line of input contains the date of issue of the license (yyyymmdd) Subsequent lines contain information on offenses, in chronological order. Each such line contains the offense date (yyyymmdd) and the number of points applied (an integer between 2 and 15). On the day the license is issued, and on every occasion that the number of merit or demerit points changes, output a line giving the date and the number of points, in the format below. Output terminates when 5 merit points are accumulated following the last offense.
Input
Output
Sample Input
Sample Output
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
int year,month,day,mer,demer;
void facs(int n)
{
year=n/10000;//计算年份月份日子
n%=10000;
month=n/100;
day=n%100;
}
int main()
{
int n,m,k;
scanf("%d",&n);
k=n;
facs(k);
printf("%04d-%02d-%02d No merit or demerit points.\n",year,month,day);//先输出最开始的
while(~scanf("%d%d",&n,&m))
{
int count1=0;
for(k+=10000;k<=n;k+=10000)//从K日期开始到n结束
{
if(demer>0)
{
demer-=max(2,int(demer+1)/2);//
facs(k);
if (demer>0) printf("%04d-%02d-%02d %d demerit point(s).\n",year,month,day,demer);
else
{
demer=0;
printf("%04d-%02d-%02d No merit or demerit points.\n",year,month,day);
}
}
else
{
if (count1%2!=0)//count1从0开始,变成1的时候代表已经第二年是demerit为0了
{
mer++;
facs(k);
printf("%04d-%02d-%02d %d merit point(s).\n",year,month,day,mer);
}
count1++;
}
}
k=n;
demer+=m;
facs(k);
if (mer)//如果merit不为零就可以抵消demerit
{
while (demer>0 && mer>0)
mer--,demer-=2;//并且要清空merit为0
mer=0;
}
if (mer>0)
printf("%04d-%02d-%02d %d merit point(s).\n",year,month,day,mer);
if (demer>0)
printf("%04d-%02d-%02d %d demerit point(s).\n",year,month,day,demer);
if (demer==0 && mer==0)
printf("%04d-%02d-%02d No merit or demerit points.\n",year,month,day);
}
while (demer!=0)
{
k+=10000;
facs(k);
demer-=max(2,(int)((demer+1)/2));
if (demer>0) printf("%04d-%02d-%02d %d demerit point(s).\n",year,month,day,demer);
else
{
demer=0;
printf("%04d-%02d-%02d No merit or demerit points.\n",year,month,day);
}
}
for (mer=0;mer<6;mer++)//从0开始
if (mer)
{
k+=20000;
facs(k);
printf("%04d-%02d-%02d %d merit point(s).\n",year,month,day,mer);
}
return 0;
}