Contest Print Server(山东省第四届ACM大学生程序设计竞赛 )

本篇博客介绍了一道ACM竞赛背景下的打印服务模拟题,详细解析了题目要求及实现思路。该题涉及如何处理多个团队的打印请求,并在打印机纸张数量有限的情况下进行合理调度。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Problem Description
    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.
Input

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.

Output
    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.

Example Input
23 7 5 6 177Team1 request 1 pagesTeam2 request 5 pagesTeam3 request 1 pages3 4 5 6 177Team1 request 1 pagesTeam2 request 5 pagesTeam3 request 1 pages
Example Output
1 pages for Team15 pages for Team21 pages for Team31 pages for Team13 pages for Team25 pages for Team21 pages for Team3
 

模拟题,读懂题意即可,s是一开始打印机里纸张的数量,就算要用的纸大于s,也得打印以后才会更新,每当s用完以后用s=(s*x+y)%mod 更新s;

一开始看不懂题,卡了好久,看懂以后WA一次排了个坑也就A了;

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <stack>
#define LL long long
#define INF 0x7fffffff
#define MAX 200010
#define PI 3.1415926535897932
#define E 2.718281828459045
using namespace std;
int t,s,x,y,mod,n;
int main()
{
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d%d%d%d",&n,&s,&x,&y,&mod);
        int ss=s;
        for(int i=1; i<=n; i++)
        {
            char name[100],re[100],pa[100];
            int num;
            scanf("%s%s%d%s",name,re,&num,pa);
            if(ss>=num)
            {
                printf("%d %s for %s\n",num,pa,name);
                ss-=num;
            }
            else
            {
                while(ss<num)   //这里是个坑,因为更新s以后,s不一定大于num;
                {
                    printf("%d %s for %s\n",ss,pa,name);
                    s=(s*x+y)%mod;
                    ss=s;
                }
                printf("%d %s for %s\n",num,pa,name);
                ss=ss-num;
            }
        }
        printf("\n");  //空行,也是个坑;
    }

    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值