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. Codevs p1004 四子连棋

                          四子连棋 题目描述 Description 在一个4*4的棋盘上摆放了14颗棋子,其中有7颗白色棋子,7颗黑色棋子,有两个空白地带,任何一颗黑白棋子都可以向 ...

  2. BestCoder Round #77

    T1 xiaoxin juju needs help 计算组合数然后多重集排列乱搞,注意判无解情况(TM我就判错然后FST了). #include<cstdio> #include< ...

  3. Jquery_操作cookies

    首先引入jquery.cookie.js jquery.cookie.js下地址:http://plugins.jquery.com/cookie/ 操作文档: https://github.com/ ...

  4. JQuery插件让图片旋转任意角度且代码极其简单

    引入下方的jquery.rotate.js文件,然后通过$("选择器").rotate(角度);可以旋转任意角度, 例如$("#rotate-image").r ...

  5. [LintCode] Gray Code 格雷码

    The gray code is a binary numeral system where two successive values differ in only one bit. Given a ...

  6. List集合对象根据字段排序

    //把需要比较的对象实现Comparable接口实现compareTo方法 public class Address implements Comparable<Address> { St ...

  7. unity3d插件Daikon Forge GUI 中文教程5-高级控件listbox和progress bar的使用

    3.3.listbox列表框 Atlas 图集: 下面应用到的精灵都是在这里的. ListBox中的内容: 背景精灵 图片的主颜色 Padding边距 Scrollbar 滚动条对象的预制体或者对象, ...

  8. 汇编基础知识之二debug的使用

    DEBUG的使用 (要在win32位习题下进行,win7 64位需要安装DosBox和debug这2个软件): 1:win64位下debug的使用教程: 下载debug.exe,这里我把debug放在 ...

  9. div自定义的滚动条 (水平导航条)

    <!DOCTYPE html> <html> <head> <title></title> <style> div{ /* wi ...

  10. 分布式搜索ElasticSearch单机与服务器环境搭建

    从上方插件官网中下载适合的dist包,然后解压.进入bin目录,可以看到一堆sh脚本.在bin目录下创建一个test.sh: bin=/home/csonezp/Dev/elasticsearch-j ...