[2013山东ACM省赛] Contest Print Server (模拟)

286 篇文章 140 订阅
19 篇文章 0 订阅

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大学生程序设计竞赛

 

解题思路:

这题是第四届省赛的最后一个题,模拟,可以说是水题,但敢保证做过的一定都说坑。

代码:

#include <iostream>  
#include <string.h>  
using namespace std;  
  
struct T  
{  
    string name,re,page;  
    int p;  
}team[105];  
int n,s,x,y,mod;  
  
int main()  
{  
    int t;cin>>t;  
    while(t--)  
    {  
        cin>>n>>s>>x>>y>>mod;  
        for(int i=1;i<=n;i++)  
            cin>>team[i].name>>team[i].re>>team[i].p>>team[i].page;  
        int cnt=0;  
        int ok=0;  
        int j;  
        for(int i=1;i<=n;i++)  
        {  
            if(ok==1)  
                cout<<"0 pages for "<<team[i].name<<endl;  //当上一个队纸张界限刚好到达s时,当前队首先要输出 0 张,坑啊!
            ok=0;  
            for(j=1;j<=team[i].p;j++)  
            {  
                cnt++;  
                if(cnt==s)  
                {  
                    cout<<j<<" pages for "<<team[i].name<<endl;  
                    s=(s*x+y)%mod;  
                    if(s==0)  
                        s=(s*x+y)%mod;  
                    cnt=0;  
                    break;  
                }  
            }  
            if(j<team[i].p)  
                i--;  
            else if(j>team[i].p)  
                cout<<team[i].p<<" pages for "<<team[i].name<<endl;  
            else if(j==team[i].p)  
                ok=1;  
        }  
        cout<<endl;  
    }  
    return 0;  
}  


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值