zoukankan      html  css  js  c++  java
  • 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 Team3
    
    1 pages for Team1
    3 pages for Team2
    5 pages for Team2
    1 pages for Team3

    提示

     

    来源

     2013年山东省第四届ACM大学生程序设计竞赛

    示例程序

    分析:

    按照这个形式输入第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 }
    View Code

    官方标程:

     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
    ", 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
    ", 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

    官方数据生成:

     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
    ", 10);
    23     printf("100 2 3 1 1007
    ");
    24     for(int i=0;i<100;i++) printf("Team%d request %d pages
    ",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,s,x,y,mod);
    29         for(int i=0;i<n;i++){
    30             ots();
    31             printf(" request %d pages
    ", rand()%(mod-500)+1);
    32         }
    33     }
    34     return 0;
    35 } 
    View Code
  • 相关阅读:
    spring cloud网关gateway
    maven将依赖第三方包打包(package)到jar中
    spring boot创建多模块聚合工程
    spring cloud服务间调用feign
    取模和取余的区别
    实现多线程编程的三种方式
    打开eclipse编译后的.class文件
    对中断interrupt的理解
    对final和static的理解
    对synchronized的一点理解
  • 原文地址:https://www.cnblogs.com/jeff-wgc/p/4468261.html
Copyright © 2011-2022 走看看