http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2624
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.
示例输入
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
示例输出
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
提示
来源
示例程序
分析:
按照这个形式输入第A个队伍需要打印B张纸。
然后定义s=(s*x+y)%mod。
当打印的纸张数>=s时,便会重新打印这个队伍的纸张。按照要求输出。
AC代码:
1 #include<stdio.h> 2 #include<string> 3 #include<iostream> 4 using namespace std; 5 struct sa 6 { 7 int num; 8 string name; 9 }data[1007],cnt; 10 int main() 11 { 12 int t; 13 scanf("%d",&t); 14 while(t--) 15 { 16 int n,s,x,y,mod,i,j,flag; 17 string name,tmp1,tmp2; 18 scanf("%d%d%d%d%d",&n,&s,&x,&y,&mod); 19 getchar(); 20 for(i=1;i<=n;i++) 21 { 22 cin>>name>>tmp1>>flag>>tmp2; 23 data[i].name=name; 24 data[i].num=flag; 25 } 26 int count=0,ans=0; 27 for(i=1;i<=n;i++) 28 { 29 ans=count+data[i].num; 30 if(ans<=s) 31 { 32 count+=data[i].num; 33 cnt=data[i]; 34 } 35 else 36 { 37 cnt.name=data[i].name; 38 cnt.num=s-count; 39 count=0; 40 s=(s*x+y)%mod; 41 if(s==0)s=(s*x+y)%mod; 42 i--; 43 } 44 cout<<cnt.num<<" pages for "<<cnt.name<<endl; 45 } 46 cout<<endl; 47 } 48 return 0; 49 }