UPC:2226 Contest Print Server(模拟)

题意:模拟。

思路:注意比较坑的地方。如果Team1请求打印,而此时计数达到s,那应该先输出一个Team1 request 0 pages

#include <iostream>
#include <vector>
#include <cstring>
#include <cstdio>
using namespace std;
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n,s,x,y,mod;
        scanf("%d%d%d%d%d",&n,&s,&x,&y,&mod);
        int rest=s;
        while(n--)
        {
            char team[30];
            int need;
            scanf("%s request %d pages",team,&need);
            while(true)
            {
                if(need<=rest)
                {
                    printf("%d pages for %s\n",need,team);
                    rest-=need;
                    break;
                }
                else
                {
                    printf("%d pages for %s\n",rest,team);
                    rest=0;
                }
                if(rest==0)
                    rest=s=(s*x+y)%mod;
            }
        }
        printf("\n");
    }
    return 0;
}


你可能感兴趣的:(UPC:2226 Contest Print Server(模拟))