Contest Print Server
Time Limit: 1000 MS Memory Limit: 32768 K
Total Submit: 115(27 users) Total Accepted: 36(26 users) Rating: Special Judge: No
Description
In ACM/ICPC on-site contests ,3 students share 1 computer,so you can print your source code any time. Here you need to write a contest print server to handle all the requests.
Input
In the first line there is an integer T(T<=10),which indicates the number of test cases.
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.
Output
Every time a request is completed or the printer is break down,you should output one line like “p pages for Team_Name”,p is the number of pages you give the team “Team_Name”.
Sample Input
2
3 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
Sample Output
Source
HCPC2014校赛训练赛 2
题目大意:ACM竞赛是三人一队并且只有一台电脑的,所以支持打印代码供给选手静态debug。这次竞赛的打印机非常奇怪,它每次开机最多只能打印s张纸,如果超过了S张纸,只能再次开机重新打印队伍的需要,并且在重新开机的时候呢,S会增加,对于增加到的值,有一个公式s=(s*x+y)%mod;对于每一次打印,需要对其输出相应的操作情况。
思路:模拟,这里给出一组很容易wa的数据:
2
4 7 5 6 177
Team1 request 1 pages
Team2 request 5 pages
Team3 request 1 pages
Team4 request 1 pages
另外,每次操作完n次之后别忘记输出一个空行。
AC代码:
#include<stdio.h>
#include<string.h>
using namespace std;
char bb[150];
char cc[150];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,s,x,y,mod;
char ss[25];
int conter=0;
scanf("%d%d%d%d%d",&n,&s,&x,&y,&mod);
int need;
for(int i=0;i<n;i++)
{
scanf("%s%s%d%s",ss,bb,&need,cc);
if(need+conter<=s)
{
printf("%d pages for %s\n",need,ss);
conter+=need;
continue;
}
if(need+conter>s)
{
while(1)
{
if(s>need+conter)break;
printf("%d pages for %s\n",s-conter,ss);
s=(s*x+y)%mod;
conter=0;
}
printf("%d pages for %s\n",need,ss);
conter+=need;
}
// printf("%d\n",conter);
}
puts("");
}
}
/*
2
4 7 5 6 177
Team1 request 1 pages
Team2 request 5 pages
Team3 request 1 pages
Team4 request 1 pages
*/