Contest Print Server
Time Limit: 1000MS Memory limit: 65536K
题目描述
输入
In each case,the first line contains 5 integers n,s,x,y,mod (1<=n<=100, 1<=s,x,y,mod<=10007), and n lines of requests follow. The request is like "Team_Name request p pages" (p is integer, 0<p<=10007, the length of "Team_Name" is no longer than
20), means the team "Team_Name" need p pages to print, but for some un-know reason the printer will break down when the printed pages counter reached s(s is generated by the function s=(s*x+y)%mod ) and then the counter will become 0. In the same time the
last request will be reprint from the very begin if it isn't complete yet(The data guaranteed that every request will be completed in some time).
You can get more from the sample.
输出
Please note that you should print an empty line after each case.
示例输入
23 7 5 6 177
Team1 request 1 pages
Team2 request 5 pages
Team3 request 1 pages
3 4 5 6 177
Team1 request 1 pages
Team2 request 5 pages
Team3 request 1 pages
示例输出
1 pages for Team1
5 pages for Team2
1 pages for Team3
1 pages for Team1
3 pages for Team2
5 pages for Team2
1 pages for Team3
分析:这是13年省赛里的一道水题,在重现赛的时候做的时候,一直过不去,根据题意,是判断打印纸张是否够用,够用的话就把需要的打印张数打印出来,如果不够用,就把剩下的纸张打印出来,然后S(s is generated by the function s=(s*x+y)%mod )根据函数式变化,count清零,再判断纸张是否够用,并把没打印完整的重新打印一遍。
当时我自己认为纸张刚好用完的时候,下个队伍申请打印的时候应该S自动变化,不再打印0张的时候,可事实上我是错的,队友给了纠正,交了一遍就AC了
代码如下:
#include <stdio.h>
int main()
{
int T;
int n,s,x,y,mod,temp,count;
int i,j,p;
char str[25];
scanf("%d",&T);
while(T--)
{
scanf("%d %d %d %d %d",&n,&s,&x,&y,&mod);
count=s;
for(i=1;i<=n;i++)
{
if(temp)
scanf("%s request %d pages",str,&p);
temp=1;
if(count>=p)
{
printf("%d pages for %s\n",p,str);
count-=p;
}
else
{
printf("%d pages for %s\n",count,str);
s=(s*x+y)%mod;
count=s;
temp=0;
i--;
}
}
printf("\n");
}
return 0;
}