Jim Ratt has just joined a local fitness center. He’s especially excited about a sequence of 10 machines that
he cycles through three times for his workout. He has a fixed time which he spends on each machine, as well
as a fixed recovery time after using a machine. Jim’s not the brightest guy in the world, but in the absence of
anything else even he would easily be able to calculate how long his workout would take.
But of course, Jim isn’t the only person who uses the fitness center and wouldn’t you know it but when Jim
shows up there are always 10 other people there, each using one of the ten machines exclusively. Like Jim,
each person has a fixed time they use on their machine as well as a fixed recovery time. This will sometimes
cause Jim to have to wait for a particular machine, and Jim’s usage sometimes results in the other people
having to wait as well (though if both Jim and another person want to start using a machine at the same time,
Jim is polite enough to let the other person go first). Jim has gone to the center often enough that he has a
good idea what everyone’s usage and recovery times are, but he has trouble determining how long it will take
him to perform his workout. That’s where you are going to flex your programming muscles.
Input
Input starts with a line containing twenty integers; the first two give Jim’s usage and recovery time for
machine 1, the next two give Jim’s usage and recovery time for machine 2, etc. The next line contains 3
integers u r t; the first two values are the usage and recovery times for the person who is using machine 1,
and t is the time when he/she first starts using the machine. The next 9 lines specify similar information for
machines 2 through 10. All usage and recovery times are positive and ≤ 5 000 000 and all start times t satisfy
|t| ≤ 5 000 000. You should assume that Jim is ready to use machine 1 at time 0.
Output
Display the time when Jim has finished his workout, i.e., the moment when he has finished his usage time on
machine 10 for the third time (don’t count the last recovery time for that machine).
Sample Input 1 Sample Output 1
5 5 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
2 2 1
8 3 0
1 1 0
1 1 0
1 1 0
1 1 0
1 1 0
1 1 0
1 1 0
1 1 0
100
一个人在健身房运动,总共10个器材,除他以外还有10个人,每个人都有运动和休息时间,当然如果他目前位置的人和他在相同的时间用器械,他出于礼貌,会等他运动完才运动,求他第三次到达10号器材所需要的时间;
比较复杂的模拟;
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<string>
#include<bitset>
#include<ctime>
#include<deque>
typedef long long ll;
using namespace std;
typedef unsigned long long int ull;
#define maxn 30005
#define ms(x) memset(x,0,sizeof(x))
#define Inf 0x7fffffff
#define inf 0x3f3f3f3f
const long long int mod = 1e9 + 7;
#define pi acos(-1.0)
#define pii pair<int,int>
#define eps 1e-7
#define pll pair<ll,ll>
ll quickpow(ll a, ll b) {
ll ans = 1;
a = a % mod;
while (b > 0) {
if (b % 2)ans = ans * a;
b = b / 2;
a = a * a;
}
return ans;
}
int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a%b);
}
int use[maxn], rec[maxn];
int uu[maxn], rr[maxn], t[maxn];
int main()
{
ios::sync_with_stdio(false);
int i, j;
for (i = 1; i <= 10; i++) {
cin >> use[i] >> rec[i];
}
int sum = 0;
for (i = 1; i <= 10; i++) {
cin >> uu[i] >> rr[i] >> t[i];
}
for (i = 1; i <= 30; i++) {
if (i % 10 == 0)j = 10;
else j = i % 10;
if (sum >= t[j]) {
int dlt = sum - t[j];
int k = dlt / (uu[j] + rr[j])*(uu[j] + rr[j]);
t[j] += (k + uu[j]);
sum = max(sum, t[j]);
t[j] += rr[j];
}
sum += use[j];
t[j] = max(t[j], sum);
sum += rec[j];
}
cout << sum - rec[10] << endl;
}