Time Limit : 2000/1000ms(Java/Other) Memory Limit : 65535/32768K (Java/Other)
Problem Description
In ACM/ICPC on-sitecontests ,3 students share 1 computer,so you can print your source code anytime. Here you need to write a contest print server to handle all the requests.
Input
In the first line thereis an integer T(T<=10),which indicates the number of test cases.
In each case,the firstline 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, thelength of "Team_Name" is no longer than 20), means the team"Team_Name" need p pages to print, but for some un-know reason theprinter will break down when the printed pages counter reached s(s is generatedby the function s=(s*x+y)%mod ) and then the counter will become 0. In the sametime the last request will be reprint from the very begin if it isn't completeyet(The data guaranteed that every request will be completed in some time).
You can get more fromthe sample.
Output
Every time a request iscompleted or the printer is break down,you should output one line like "ppages for Team_Name",p is the number of pages you give the team"Team_Name".
Please note that youshould print an empty line after each case.
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
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
模拟题,有个坑点。s=0要再执行一次。
#include <iostream>
#include <cstdio>
#include <cstring>
#include<vector>
using namespace std;
char team[25];
int main()
{
int t,s,x,y,mod,i,p,n;
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d%d%d",&n,&s,&x,&y,&mod);
int countn=0;
while(n--)
{
scanf("%s request %d pages",team,&p);
getchar();
int flag=1;
while(flag==1)
{
if(p<=s-countn)
{
printf("%d pages for %s\n",p,team);
countn+=p;
flag=0;
}
else
{
printf("%d pages for %s\n",s-countn,team);
s=(s*x+y)%mod;
if(s==0)
s=(s*x+y)%mod;
countn=0;
}
}
}
printf("\n");
}
return 0;
}