标签:att current each note ott increase -- contest fine
BaoBao and DreamGrid are playing a game using a strange button. This button is attached to an LED light (the light is initially off), a counter and a timer and functions as follows:
During the game, BaoBao and DreamGrid will press the button periodically. If the current real time (that is to say, the time elapsed after the game starts, NOT the value of the timer) in seconds is an integer and is a multiple of a given integer a, BaoBao will immediately press the button b times; If the current time in seconds is an integer and is a multiple of another given integer c, DreamGrid will immediately press the button d times.
Note that
The game starts at 0 second and ends after t seconds (if the button will be pressed at t seconds, the game will end after the button is pressed). What‘s the value of the counter when the game ends?
There are multiple test cases. The first line of the input contains an integer T (about 100), indicating the number of test cases. For each test case:
The first and only line contains six integers a, b, c, d, v and t (1≤a,b,c,d≤10?6??, 1≤v,t≤10?12??). Their meanings are described above.
For each test case output one line containing one integer, indicating the value of the counter when the game ends.
2
8 2 5 1 2 18
10 2 5 1 2 10
6
4
We now explain the first sample test case.
求出a和c的最小公倍数,所以0到最小公倍数之间即为一循环节,暴力跑出循环节,最后单独处理即可。
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio> #include <vector> #include <queue> #include <stack> #include <cstdlib> #include <iomanip> #include <cmath> #include <cassert> #include <ctime> #include <map> #include <set> using namespace std; #pragma comment(linker, "/stck:1024000000,1024000000") #define lowbit(x) (x&(-x)) #define max(x,y) (x>=y?x:y) #define min(x,y) (x<=y?x:y) #define MAX 100000000000000000 #define MOD 1000000007 #define pi acos(-1.0) #define ei exp(1) #define PI 3.1415926535897932384626433832 #define ios() ios::sync_with_stdio(true) #define INF 0x3f3f3f3f #define mem(a) ((a,0,sizeof(a))) typedef long long ll; ll t, a, b, c, d, v, T; int main() { scanf("%lld", &T); while(T--) { scanf("%lld%lld%lld%lld%lld%lld", &a, &b, &c, &d, &v, &t); ll g = a/__gcd(a, c)*c; ll ans1=b+d-1,l=a,r=c; ll pos=0; while(l<g || r<g) { if(l<=r && l<g){ if(l-pos>v) ans1+=(b-1); else ans1+=b; pos=l; l+=a; } else if(l>r && r<g){ if(r-pos>v) ans1+=(d-1); else ans1+=d; pos=r; r+=c; } } if(l>=g) l-=a; if(r>=g) r-=c; ll mid=max(l,r); ans1 = t/g*ans1; if(g-mid<=v) ans1+=t/g; t = t%g; ll ans2=b+d-1; pos=0,l=a,r=c; while(l<=t || r<=t) { if(l<=r && l<=t){ if(l-pos>v) ans2+=(b-1); else ans2+=b; pos=l; l+=a; } else if(l>r && r<=t){ if(r-pos>v) ans2+=(d-1); else ans2+=d; pos=r; r+=c; } } printf("%lld\n",ans1+ans2); } return 0; }
The 2018 ACM-ICPC Asia Qingdao Regional Contest, Online J Press the Button
标签:att current each note ott increase -- contest fine
原文地址:https://www.cnblogs.com/shinianhuanniyijuhaojiubujian/p/9656826.html