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