2013年山东省第四届ACM大学生程序设计竞赛J题:Contest Print Server

题目描述

    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

分析:算是一简单题,但是题目比较绕人,英文看的云里雾里的,只能通过不断的提交验证自己的猜想(个人WA了两次),直到AC之后再看就明了了:-
#include<stdio.h>
int main(void)
{
int cases, n, s, x, y, mod, p, count;
char team_name[];
char str[]; // 过滤输入字符串"request"和"page" scanf("%d", &cases);
while(cases--)
{
scanf("%d%d%d%d%d", &n, &s, &x, &y, &mod); count = ;
while(n--)
{
scanf("%s%s%d%s", team_name, str, &p, str);
if(count+p <= s)
printf("%d pages for %s\n", p, team_name);
else
{
printf("%d pages for %s\n", s-count, team_name);
while()
{
s = (s*x+y) % mod;
if(p <= s)
{
printf("%d pages for %s\n", p, team_name);
count = ;
break;
}
else
{
printf("%d pages for %s\n", s, team_name);
}
}
} count += p;
} printf("\n");
} return ;
}
count 变量挪了下位置同样AC:
#include<stdio.h>
int main(void)
{
int cases, n, s, x, y, mod, p, count;
char team_name[];
char str[]; // 过滤输入字符串"request"和"page" scanf("%d", &cases);
while(cases--)
{
scanf("%d%d%d%d%d", &n, &s, &x, &y, &mod); count = ;
while(n--)
{
scanf("%s%s%d%s", team_name, str, &p, str);
count += p;
if(count <= s)
printf("%d pages for %s\n", p, team_name);
else
{
printf("%d pages for %s\n", s-count+p, team_name);
while()
{
s = (s*x+y) % mod;
if(p <= s)
{
printf("%d pages for %s\n", p, team_name);
count = p;
break;
}
else
{
printf("%d pages for %s\n", s, team_name);
}
}
} } printf("\n");
} return ;
}
上一篇:2013年山东省第四届ACM大学生程序设计竞赛 Alice and Bob


下一篇:2013年山东省第四届ACM大学生程序设计竞赛E题:Alice and Bob