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. This application is modifying the autolayout engine from a background thread, which can lead to engine corruption and weird crashes. This will cause an exception in a future release.

    一,经历 <1> 使用SDWebImage下载 成功图片后,将图片设置给 self.imageView.image,提示如题所示的错误提示. <2>第一反应就是慢慢注释掉代码进 ...

  2. Application Initialization Module for IIS 7.5

    http://www.iis.net/downloads/microsoft/application-initialization IIS7.5也有Warm Up功能 让ASP.NET第一次Reque ...

  3. 看好你的门-客户端传数据-用java修改referer

    1.简单说明 Referer.origin用来表明,浏览器向WEB服务器表明自己来自哪里.但是就它本身而言,并非完全安全. 写一个例子,可以任意修改http信息头中的referer.origin 2. ...

  4. JAVA I/O系统

    一.流的分类 1.按照方向分为: (1)输入流:从数据源读取数据到程序中.只能从中读取数据,不能向其中写入数据.IO包中的输入流都继承自抽象类InputStream或Reader. (2)输出流:经数 ...

  5. Android基于XMPP的即时通讯2-文件传输

    本文是在上一篇博文Android基于XMPP的即时通讯1-基本对话的基础上,添加新的功能,文件传输 1.初始化文件传输管理类 public static FileTransferManager get ...

  6. [LintCode] Maximum Gap 求最大间距

    Given an unsorted array, find the maximum difference between the successive elements in its sorted f ...

  7. Maven3下的java web项目

    咱们使用Maven3构建一个j2ee项目,项目的成果是一个war包,只需把它部署在服务器上,就可以使用浏览器访问. 具体详细信息 参考  http://www.mossle.com/docs/mave ...

  8. Java实现智能机器自动操作电脑

    package com.tz.util; import java.awt.Robot; import java.awt.event.InputEvent; import java.awt.event. ...

  9. javascript阻止事件冒泡的兼容写法及其相关示例

    //阻止事件冒泡的兼容写法 function stopBubble(e){ //如果提供了事件对象,则是一个非IE浏览器 if(e && e.stopPropagation) //因此 ...

  10. SubmitText 中配置lua 运行环境

    一 新建编译系统 二.使用新建的编译系统 三配置 { "cmd": ["lua", "$file"], "file_regex&q ...