山东省第四届ACM大学生程序设计竞赛-Contest Print Server(模拟)
2016-04-12 21:11
543 查看
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大学生程序设计竞赛题意:
求每个队打印的纸的张数。
当纸不够的时候先输出剩下够打印多少张,再重新输出这个队一共要打印多少张。
注意前一个对刚好使用完额度的时候,下一个队先输出0张。
注意就算当前置零,p依然可能超过s,所以要重判!!!
一开始是s,当超过s时s变为s=(s*x+y)%mod;
/*
* Copyright (c) 2016, 烟台大学计算机与控制工程学院
* All rights reserved.
* 文件名称:print.cpp
* 作 者:单昕昕
* 完成日期:2016年4月12日
* 版 本 号:v1.0
*/
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <time.h>
#include <stdlib.h>
using namespace std;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,s,x,y,mod,cnt=0,flag=0;
scanf("%d%d%d%d%d",&n,&s,&x,&y,&mod);
while(n--)
{
char s1[20],s2[10],s3[10];
int p;
scanf("%s%s%d%s",s1,s2,&p,s3);
A:
cnt+=p;
if(cnt<=s)
printf("%d pages for %s\n",p,s1);
else
{
cnt-=p;
printf("%d pages for %s\n",s-cnt,s1);
s=(s*x+y)%mod;
cnt=0;//此时当前的p依然有可能超过s所以要goto重判
goto A;
}
}
cout<<endl;
}
return 0;
}
相关文章推荐
- 如何组织构建多文件 C 语言程序(二)
- 如何写好 C main 函数
- 书评:《算法之美( Algorithms to Live By )》
- 动易2006序列号破解算法公布
- Ruby实现的矩阵连乘算法
- C#插入法排序算法实例分析
- Lua和C语言的交互详解
- Transformation 能将 Windows XP/Server 2003 操作系统,完美地模拟成 Windows Vista 的软件
- 超大数据量存储常用数据库分表分库算法总结
- C#数据结构与算法揭秘二
- C#冒泡法排序算法实例分析
- 算法练习之从String.indexOf的模拟实现开始
- C#算法之关于大牛生小牛的问题
- C#实现的算24点游戏算法实例分析
- 用javascript和css模拟select的脚本
- 关于C语言中参数的传值问题
- 简要对比C语言中三个用于退出进程的函数
- 深入C++中API的问题详解
- 基于C语言string函数的详解
- C语言中fchdir()函数和rewinddir()函数的使用详解