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. C#操作XML文档---基础

    增查改删代码如下 public void CreateXML() { XmlDocument xml = new XmlDocument(); xml.AppendChild(xml.CreateXm ...

  2. CentOS转的服务器磁盘规划

    我的服务器是500G.最重要的是/var分区一定要大(不论postfix邮件,还是LAMP的WEB 服务器等).最好是400G以上.具体的/boot 只要100M就足够了.下面是我的分区方案:硬盘50 ...

  3. 在线阅读android源代码

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

  4. 通过jquery获取ul中第一个li的属性

    当加载列表时,默认希望选中第一条.top_menu 为ul的ID 通过 $("#top_menu li:first") 就可以获取到 ul下第一个li标签.然后就可以利用 例如 修 ...

  5. orcale 动态执行语句

    create or replace function fn_test2(tablename in varchar2) return number is rtn number; begin --通用的获 ...

  6. 打造移动终端的 WebApp(一):搭建一个舞台

    最近随着 Apple iOS 和 Android 平台的盛行,一个新的名词 WebApp 也逐渐火了起来,这里我也趁着热潮做一个关于 WebApp 系列的学习笔记,分享平时的一些研究以及项目中的经验, ...

  7. 玩坏JVM很简单--toString的递归调用

    在JVM的内存管理机制下很少发生内存溢出的情况.至少我碰见的少,好像在SSH我多次发布项目时候出现过一次.今天看见一个特简单的方法让内存溢出(好吧,我似乎作死了--!): public class I ...

  8. redis与memcache的区别2

    总结一: memcache官方定义 Free & open source, high-performance, distributed memory object caching system ...

  9. IOS第三天

    第三天 ******** 九宫格代码的现实 @interface HMViewController () /** 应用程序列表 */ @property (nonatomic, strong) NSA ...

  10. 剑指offer?

    1. 在一个m*n二维数组中,每一行都按照从左到右的递增顺排序,每一列都按照从上到下的顺序排序,请完成一个函数,输入这样一个二维数组和一个整数,判断数组中是否含有该整数.1 2 8 92 4 9 12 ...