您的位置:首页 > 编程语言 > C语言/C++

山东省第四届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语言 算法 模拟 acm