Problem D: Problem D: Demerit Points

Time Limit: 1 Sec   Memory Limit: 128 MB

​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

19820508

19830606 2

19830607 2

19891212 15

Sample Output

1982-05-08 No merit or demerit points.

1983-06-06 2 demerit point(s).

1983-06-07 4 demerit point(s).

1984-06-07 2 demerit point(s).

1985-06-07 No merit or demerit points.

1987-06-07 1 merit point(s).

1989-06-07 2 merit point(s).

1989-12-12 11 demerit point(s).

1990-12-12 5 demerit point(s).

1991-12-12 2 demerit point(s).

1992-12-12 No merit or demerit points.

1994-12-12 1 merit point(s).

1996-12-12 2 merit point(s).

1998-12-12 3 merit point(s).

2000-12-12 4 merit point(s).

2002-12-12 5 merit point(s).

【分析】

模拟题...难在读题了...

给出拿证的日期,第一行..直接输出一下就行了

然后后面按时间顺序依次给出在某个日期扣了几分,在这中途:

每一个没有违规的整年,都可以让自己的demerit减少max(2,demerit/2),直到罚分为0。如果罚分为0,那么每两个没有违规的整年,就可以加一分merit。

对每次罚分的时候,如果merit不为0,那么每一分merit可以抵消2分demerit,如果只有1分demerit,也需要用1分merit抵消,这是强制的...

当所有罚单处理完之后,继续输出直到merit到5分,然后结束...

代码非常裸,就是几个处理...写的清楚就可以了.不敢相信我居然读的清这种题目....


【代码】

#include <stdio.h>
#include <algorithm>
using namespace std;
int now,year,month,day,n,m,mer=0,demer=0;;

void init()
{
int nn=now;
year=nn/10000;nn%=10000;month=nn/100;day=nn%100;
}


int main()
{
scanf("%d",&n);now=n;init();
printf("%04d-%02d-%02d No merit or demerit points.\n",year,month,day);
while (~scanf("%d%d",&n,&m))
{
int t=0;
for (now+=10000;now<=n;now+=10000)
if (demer>0)
{
demer-=max(2,(int)((demer+1)/2));
init();
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 (t%2)
{
mer++;
init();
printf("%04d-%02d-%02d %d merit point(s).\n",year,month,day,mer);
}
t++;
}
now=n;demer+=m;init();
if (mer)
{
while (demer>0 && mer>0) mer--,demer-=2;
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)
{
now+=10000;init();
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<6;mer++)
if (mer)
{
now+=20000;
init();
printf("%04d-%02d-%02d %d merit point(s).\n",year,month,day,mer);
}
return 0;
}