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大学生程序设计竞赛

示例程序

分析:

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

官方数据生成:

 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

转载于:https://www.cnblogs.com/jeff-wgc/p/4468261.html

sdutoj 2624 Contest Print Server相关推荐

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

    Rescue The Princess Time Limit: 1000MS    Memory limit: 65536K 题目描述 Several days ago, a beast caught ...

  2. Windows Server 2008 Server Core - 小脚印,大安全

    IT 管理员对自Longhorn时代就被披露的Windows Server 2008的Server Core充满了兴趣,这一命令行版本的Windows Server包含了Windows服务器所需的各种 ...

  3. 精通Server Core系列之一 ---Server Core简介

    和Windows Server 2003不一样的是, 从Windows Server 2008 开始,我们可以安装只具有特定功能最小安装服务器核心(Server Core)版本,它为一些特定服务的正常 ...

  4. debian最小化安装如何安装桌面_如何在Ubuntu Server 18.04上安装GNOME桌面

    如果您已经采用了Ubuntu Server 18.04,你一定会感到非常自豪.然而,无论您多么关注它,您都意识到您的it管理生命中的大部分时间都在使用GUI,并且您不太确定接下来要做什么?如果这样描述 ...

  5. A Quick Guide For Windows 2008 Server Core

    1         Introduction 下图是Windows Server 2008的核心架构 Server Core是Longhorn Server 中一个全新的最小限度服务器安装选项.Ser ...

  6. [Python]再学 socket 之非阻塞 Server

    再学 socket 之非阻塞 Server 本文是基于 python2.7 实现,运行于 Mac 系统下 本篇文章是上一篇初探 socket 的续集, 上一篇文章介绍了:如何建立起一个基本的 sock ...

  7. SQL Server数据库管理常用SQL和T-SQL语句

    1. 查看数据库的版本 select @@version 2.查看数据库所在机器操作系统参数 exec master..xp_msver 3. 查看数据库启动的参数 sp_configure 4.查看 ...

  8. SQL Server 数据库管理常用的SQL和T-SQL语句

    --按姓氏笔画排序: SELECT*FROM TableName ORDERBY CustomerName COLLATE Chinese_PRC_Stroke_ci_as --数据库加密: SELE ...

  9. 域名带后缀_[Python 爬虫]获取顶级域名及对应的 WHOIS Server 及 whoisservers.txt 下载...

    使用 Python 爬虫获取顶级域名及对应的 WHOIS Server 并保存可用于 WhoisCL.exe 的文件 whois-servers.txt. 环境: Windows 10 Python ...

最新文章

  1. 编译Cocos2dx程序 (一)
  2. 毕业生必须知道:干部身份、三方协议、派遣证
  3. MDT跨网段UEFI部署系统
  4. Java【全排列 算法 模板】
  5. Android数据存储之sharedpreferences与Content Provider
  6. 小米平板android最新版本,想要翻身还需努力 小米平板2安卓版评测
  7. 分布式锁在存储系统中的技术实践
  8. 学习笔记之软考数据库系统工程师教程(第一版)
  9. 控制工程基础Chapter2 Mathematical models of systems
  10. php的json_encode函数问题
  11. 用tensorflow实现线性回归算法
  12. 西南科技大学OJ题 循环队列0965
  13. 完整版本的 poj 题目分类 转载
  14. 共模干扰和差模干扰,3招理清
  15. win10下使用Linux(ubuntu18.04)
  16. android studio 模拟器内存不足,Android Studio模拟器的问题及解决办法
  17. 7-31 求圆周长和面积
  18. 一,Weston简介
  19. 好记性不如烂笔头--校园网下Parsec远程控制软件的使用
  20. 自动获取cookie,爬取新浪微博热门评论

热门文章

  1. zabbix nginx error log监控
  2. 取得Servlet文件的絕對路徑;文件讀寫操作
  3. MySQL -> ES 数据同步 配置步骤
  4. SQL SERVER 执行计划各字段注释
  5. 命令行验证apk签名
  6. String,StringBuffer与StringBuilder的区别
  7. 性能测试工具—JMeter分布式启动
  8. Python内置类型—序列
  9. Android魔法(第二弹)——一步步实现淹没、展开效果
  10. 随便聊一些编程开发工具