zoukankan      html  css  js  c++  java
  • 山东省赛J题:Contest Print Server

    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 the first line there is an integer T(T<=10),which indicates the number of test cases.

    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

    Sample Input

    23 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

    Sample Output

    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
     
    题意:一开始打印机能打印s张,每一队有需要打印的纸张数目,如果该队打印完则到下一队,如果该队打印过程中纸张用完,则新的纸张会到达,而新纸张的数目是在原纸张本来数目上进行s=(s*x+y)%mod的运算,新纸张来后,打印序列必须从0开始,输出此过程
    思路:直接模拟即可,但是当时由于题目没理解透,一直卡,而且0张输出也是允许的,坑啊
     
    #include <stdio.h>
    #include <string.h>
    #include <algorithm>
    using namespace std;
    
    struct node
    {
        char name[30];
        int num;
    } team[105];
    
    int main()
    {
        int t,n,s,x,y,mod,i,j,cnt;
        scanf("%d",&t);
        while(t--)
        {
            scanf("%d%d%d%d%d",&n,&s,&x,&y,&mod);
            for(i = 1; i<=n; i++)
                scanf("%s request %d pages",team[i].name,&team[i].num);
                cnt = s;
            for(i = 1; i<=n; i++)
            {
                while(1)
                {
                    if(team[i].num<=cnt)
                    {
                        printf("%d pages for %s
    ",team[i].num,team[i].name);
                        cnt-=team[i].num;
                        break;
                    }
                    else
                    {
                        printf("%d pages for %s
    ",cnt,team[i].name);
                        s = (s*x+y)%mod;
                        if(s==0)
                            s = (s*x+y)%mod;
                            cnt = s;
                    }
                }
            }
            printf("
    ");
        }
    
        return 0;
    }
    
  • 相关阅读:
    赋值问题
    构造方法的作用
    this的使用
    三目运算符和形参的使用
    构造方法作用:给所有对象进行相同的初始化操作
    成员变量和局部变量
    相关开发的书籍名汇集
    html ---- web sql 例子
    让input表单输入框不记录输入过信息的方法
    css实现两端对齐的3种方法
  • 原文地址:https://www.cnblogs.com/pangblog/p/3260381.html
Copyright © 2011-2022 走看看