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代码:

 #include<stdio.h>
#include<string>
#include<iostream>
using namespace std;
struct sa
{
int num;
string name;
}data[],cnt;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,s,x,y,mod,i,j,flag;
string name,tmp1,tmp2;
scanf("%d%d%d%d%d",&n,&s,&x,&y,&mod);
getchar();
for(i=;i<=n;i++)
{
cin>>name>>tmp1>>flag>>tmp2;
data[i].name=name;
data[i].num=flag;
}
int count=,ans=;
for(i=;i<=n;i++)
{
ans=count+data[i].num;
if(ans<=s)
{
count+=data[i].num;
cnt=data[i];
}
else
{
cnt.name=data[i].name;
cnt.num=s-count;
count=;
s=(s*x+y)%mod;
if(s==)s=(s*x+y)%mod;
i--;
}
cout<<cnt.num<<" pages for "<<cnt.name<<endl;
}
cout<<endl;
}
return ;
}

官方标程:

 #include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;
#define MAX_Len 30
struct Request {
char s[MAX_Len];
int p;
Request ( ) {
}
Request ( char *_s, int _p ) {
strcpy(s, _s), p =_p;
}
void In ( ) {
scanf("%s%*s%d%*s", s, &p );
}
};
int n, s, x, y, mod;
queue< Request > que;
void gettask() {
while( !que.empty( ) ) que.pop( );
for ( int i = ; i < n; i ++ ) {
Request tmp;
tmp.In( );
que.push( tmp );
}
}
void dotask() {
int counter = ;
while ( !que.empty( ) ) {
Request now = que.front( );
if ( (s - counter) < now.p ) {
printf("%d pages for %s\n", s - counter, now.s );
s = ( s * x + y ) % mod ;
counter = ;
} else {
counter += now.p;
printf("%d pages for %s\n", now.p, now.s );
que.pop( );
}
}
puts("");
}
int main() {
// freopen("input.in", "r", stdin);
// freopen("output.out", "w", stdout);
int t;
scanf("%d", &t );
while ( t -- ) {
scanf("%d%d%d%d%d", &n, &s, &x, &y, &mod);
gettask( );
dotask( );
}
return ;
}

官方数据生成:

 #include<stdio.h>
#include<string.h>
#include<algorithm>
#include<time.h>
using namespace std;
void ots(){
int xs=rand()%+;
while(xs--) {
int ps=rand()%;
if(ps<=)
printf("%c",rand()%+'a');
else if(ps<=) printf("%c",rand()%+'A');
else if(ps<) printf("%c",rand()%+'');
else printf("_"); }
}
int main(){
srand(time(NULL));
freopen("input.in","w",stdout);
srand(time(NULL));
printf("%d\n", );
printf("100 2 3 1 1007\n");
for(int i=;i<;i++) printf("Team%d request %d pages\n",i+, rand()%+);
int ca=;
while(ca--) {
int n=rand()%+,s=rand()%+,x=rand()%+,y=rand()%+,mod=rand()%+;
printf("%d %d %d %d %d\n",n,s,x,y,mod);
for(int i=;i<n;i++){
ots();
printf(" request %d pages\n", rand()%(mod-)+);
}
}
return ;
}

sdutoj 2624 Contest Print Server的更多相关文章

  1. 模拟 2013年山东省赛 J Contest Print Server

    题目传送门 /* 题意:每支队伍需求打印机打印n张纸,当打印纸数累计到s时,打印机崩溃,打印出当前打印的纸数,s更新为(s*x+y)%mod 累计数清空为0,重新累计 模拟简单题:关键看懂题意 注意: ...

  2. 2013年山东省第四届ACM大学生程序设计竞赛-最后一道大水题:Contest Print Server

    点击打开链接 2226: Contest Print Server Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 53  Solved: 18 [Su ...

  3. 山东省赛J题:Contest Print Server

    Description In ACM/ICPC on-site contests ,3 students share 1 computer,so you can print your source c ...

  4. 2013年山东省第四届ACM大学生程序设计竞赛J题:Contest Print Server

    题目描述     In ACM/ICPC on-site contests ,3 students share 1 computer,so you can print your source code ...

  5. [原]sdut2624 Contest Print Server (大水+大坑)山东省第四届ACM省赛

    本文出自:http://blog.csdn.net/svitter 原题:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&am ...

  6. 山东省第四届ACM省赛

    排名:http://acm.sdut.edu.cn/sd2012/2013.htm 解题报告:http://www.tuicool.com/articles/FnEZJb A.Rescue The P ...

  7. 2013山东省ICPC结题报告

    A.Rescue The Princess 已知一个等边三角形的两个顶点A.B,求第三个顶点C,A.B.C成逆时针方向. 常规的解题思路就是用已知的两个点列出x,y方程,但这样求出方程的解的表达式比较 ...

  8. 山东省第四届ACM大学生程序设计竞赛解题报告(部分)

    2013年"浪潮杯"山东省第四届ACM大学生程序设计竞赛排名:http://acm.upc.edu.cn/ranklist/ 一.第J题坑爹大水题,模拟一下就行了 J:Contes ...

  9. 山东省第四届acm解题报告(部分)

    Rescue The PrincessCrawling in process... Crawling failed   Description Several days ago, a beast ca ...

随机推荐

  1. bug:无法给图片加边框

    一,经历 1.错误代码 _avatarView.layer.cornerRadius = GIFT_AVATAR_WIDTH * 0.5; _avatarView.layer.borderColor ...

  2. 深入浅出 - Android系统移植与平台开发(三)- 编译并运行Android4.0模拟器

    作者:唐老师,华清远见嵌入式学院讲师. 1.   编译Android模拟器 在Ubuntu下,我们可以在源码里编译出自己的模拟器及SDK等编译工具,当然这个和在windows里下载的看起来没有什么区别 ...

  3. man page分類與說明

    轉載自http://itzone.hk/article/article.php?aid=200407152225014657 (如有侵權,請留言或來信告知) 前言 Man page是每位程式設計員及U ...

  4. flex的http URL转码与解码

    private function httpEncoding(param:String):String{    //转码     return encodeURIComponent(param); } ...

  5. 在线阅读android源代码

    这两天一直在寻找android系统的源代码,但是直到一个小时之前,一直未能如愿.但是,令人欣慰的是,现在找到了. 网上有不少帖子介绍如何下载android源代码,包括在linux系统,windows系 ...

  6. push splice filter用法

    checkedData.push(record); 直接在record 这个数组后面添加; var index =jQuery.inArray(record,checkedData);// 获取ind ...

  7. sql to_char 日期转换字符串

    1.转换函数 与date操作关系最大的就是两个转换函数:to_date(),to_char() to_date() 作用将字符类型按一定格式转化为日期类型: 具体用法:to_date('2004-11 ...

  8. sbt Getting org.scala-sbt sbt 0.13.12 ...

    本地仓库被我搞乱了,一气之下整个删掉了本地仓库,再重启sbt卡在Getting这一步. Getting org.scala-sbt sbt 0.13.12 ... 卡住 补充sbt配置文件: 文件结构 ...

  9. HDU1063 大数 java

    Exponentiation Time Limit: 2000/500 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  10. 你应了解的4种JS设计模式

    学习地址: http://mp.weixin.qq.com/s?__biz=MjM5MTA1MjAxMQ==&mid=2651223556&idx=1&sn=8cd7a2272 ...