sdutoj 2624 Contest Print Server
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2624
Contest Print Server
Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^
题目描述
输入
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.
输出
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
提示
来源
示例程序
分析:
按照这个形式输入第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的更多相关文章
- 模拟 2013年山东省赛 J Contest Print Server
题目传送门 /* 题意:每支队伍需求打印机打印n张纸,当打印纸数累计到s时,打印机崩溃,打印出当前打印的纸数,s更新为(s*x+y)%mod 累计数清空为0,重新累计 模拟简单题:关键看懂题意 注意: ...
- 2013年山东省第四届ACM大学生程序设计竞赛-最后一道大水题:Contest Print Server
点击打开链接 2226: Contest Print Server Time Limit: 1 Sec Memory Limit: 128 MB Submit: 53 Solved: 18 [Su ...
- 山东省赛J题:Contest Print Server
Description In ACM/ICPC on-site contests ,3 students share 1 computer,so you can print your source c ...
- 2013年山东省第四届ACM大学生程序设计竞赛J题:Contest Print Server
题目描述 In ACM/ICPC on-site contests ,3 students share 1 computer,so you can print your source code ...
- [原]sdut2624 Contest Print Server (大水+大坑)山东省第四届ACM省赛
本文出自:http://blog.csdn.net/svitter 原题:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&am ...
- 山东省第四届ACM省赛
排名:http://acm.sdut.edu.cn/sd2012/2013.htm 解题报告:http://www.tuicool.com/articles/FnEZJb A.Rescue The P ...
- 2013山东省ICPC结题报告
A.Rescue The Princess 已知一个等边三角形的两个顶点A.B,求第三个顶点C,A.B.C成逆时针方向. 常规的解题思路就是用已知的两个点列出x,y方程,但这样求出方程的解的表达式比较 ...
- 山东省第四届ACM大学生程序设计竞赛解题报告(部分)
2013年"浪潮杯"山东省第四届ACM大学生程序设计竞赛排名:http://acm.upc.edu.cn/ranklist/ 一.第J题坑爹大水题,模拟一下就行了 J:Contes ...
- 山东省第四届acm解题报告(部分)
Rescue The PrincessCrawling in process... Crawling failed Description Several days ago, a beast ca ...
随机推荐
- 【noiOJ】p6253
t6253:用二分法求方程的根 查看 提交 统计 提问 总时间限制: 1000ms 内存限制: 65536kB 描述 用二分法求下面方程在(-10, 10)之间的一个根. 2x3- 4x2+ 3x ...
- BZOJ3456: 城市规划
Description 刚刚解决完电力网络的问题, 阿狸又被领导的任务给难住了. 刚才说过, 阿狸的国家有n个城市, 现在国家需要在某些城市对之间建立一些贸易路线, 使得整个国家的任意两个城市都直接或 ...
- jQuery取得select选中的值
$("#sxselect").change(function(){ alert($("#sxselect option:selected").val()); } ...
- HDU 5877 dfs+ 线段树(或+树状树组)
1.HDU 5877 Weak Pair 2.总结:有多种做法,这里写了dfs+线段树(或+树状树组),还可用主席树或平衡树,但还不会这两个 3.思路:利用dfs遍历子节点,同时对于每个子节点au, ...
- 应用的启动视图 LauchView
@interface AppDelegate () @property(strong,nonatomic) UIImageView *launchImaViewO; @property(strong, ...
- PHP Pthread多线程 操作
<?php class vote extends Thread { public $res = ''; public $url = array(); public $name = ''; pub ...
- 获取IP(windows和linux)
#ifdef _WIN32 #include <winsock2.h> #include <Ws2tcpip.h> #pragma comment(lib,"ws2_ ...
- linux下获取本机IP
转载:http://blog.chinaunix.net/uid-20593763-id-1620213.html 源代码级Unix/Linux 通用网卡IP地址获取方法 在Unix和Linux系统下 ...
- 3ds Max Shortcuts 快捷键大全
主界面 [Q]选择循环改变方式 [W]移动 [E]旋转 [R]缩放循环改变方式 [7]物体面数 [8]Environment [9]Advanced lighting [0]Render to Tex ...
- Hibernate框架配置
API package com.hanqi.test; import static org.junit.Assert.*; import org.hibernate.SessionFactory; ...