sdutoj 2624 Contest Print Server
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2624
?
Contest Print Server
?
Time Limit: 1000ms?? Memory limit: 65536K??有疑問?點這里^_^
題目描述
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.輸入
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.
輸出
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".? ? 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 Team31 pages for Team1 3 pages for Team2 5 pages for Team2 1 pages for Team3提示
來源
2013年山東省第四屆ACM大學(xué)生程序設(shè)計競賽示例程序
?
分析:
按照這個形式輸入第A個隊伍需要打印B張紙。
然后定義s=(s*x+y)%mod。
當(dāng)打印的紙張數(shù)>=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 } View Code?
?
官方標(biāo)程:
1 #include<stdio.h> 2 #include<string.h> 3 #include<algorithm> 4 #include<queue> 5 using namespace std; 6 #define MAX_Len 30 7 struct Request { 8 char s[MAX_Len]; 9 int p; 10 Request ( ) { 11 } 12 Request ( char *_s, int _p ) { 13 strcpy(s, _s), p =_p; 14 } 15 void In ( ) { 16 scanf("%s%*s%d%*s", s, &p ); 17 } 18 }; 19 int n, s, x, y, mod; 20 queue< Request > que; 21 void gettask() { 22 while( !que.empty( ) ) que.pop( ); 23 for ( int i = 0; i < n; i ++ ) { 24 Request tmp; 25 tmp.In( ); 26 que.push( tmp ); 27 } 28 } 29 void dotask() { 30 int counter = 0; 31 while ( !que.empty( ) ) { 32 Request now = que.front( ); 33 if ( (s - counter) < now.p ) { 34 printf("%d pages for %s\n", s - counter, now.s ); 35 s = ( s * x + y ) % mod ; 36 counter = 0; 37 } else { 38 counter += now.p; 39 printf("%d pages for %s\n", now.p, now.s ); 40 que.pop( ); 41 } 42 } 43 puts(""); 44 } 45 int main() { 46 // freopen("input.in", "r", stdin); 47 // freopen("output.out", "w", stdout); 48 int t; 49 scanf("%d", &t ); 50 while ( t -- ) { 51 scanf("%d%d%d%d%d", &n, &s, &x, &y, &mod); 52 gettask( ); 53 dotask( ); 54 } 55 return 0; 56 } View Code?
?
官方數(shù)據(jù)生成:
1 #include<stdio.h> 2 #include<string.h> 3 #include<algorithm> 4 #include<time.h> 5 using namespace std; 6 void ots(){ 7 int xs=rand()%20+1; 8 while(xs--) { 9 int ps=rand()%101; 10 if(ps<=40) 11 printf("%c",rand()%26+'a'); 12 else if(ps<=70) printf("%c",rand()%26+'A'); 13 else if(ps<98) printf("%c",rand()%10+'0'); 14 else printf("_"); 15 16 } 17 } 18 int main(){ 19 srand(time(NULL)); 20 freopen("input.in","w",stdout); 21 srand(time(NULL)); 22 printf("%d\n", 10); 23 printf("100 2 3 1 1007\n"); 24 for(int i=0;i<100;i++) printf("Team%d request %d pages\n",i+1, rand()%200+800); 25 int ca=9; 26 while(ca--) { 27 int n=rand()%51+50,s=rand()%10007+1,x=rand()%10007+1,y=rand()%10007+1,mod=rand()%9007+1000; 28 printf("%d %d %d %d %d\n",n,s,x,y,mod); 29 for(int i=0;i<n;i++){ 30 ots(); 31 printf(" request %d pages\n", rand()%(mod-500)+1); 32 } 33 } 34 return 0; 35 } View Code?
轉(zhuǎn)載于:https://www.cnblogs.com/jeff-wgc/p/4468261.html
總結(jié)
以上是生活随笔為你收集整理的sdutoj 2624 Contest Print Server的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SQL Server中截取字符串常用函数
- 下一篇: 使用literal语法格式化字符串