山東省第四屆ACM大學生程式設計競賽-Contest Print Server(模擬)

kewlgrl發表於2016-04-12

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;
}


相關文章