Press the Button


Time Limit: 1 Second      Memory Limit: 131072 KB

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:

  • When the button is pressed, the timer is set to seconds (no matter what the value of the timer is before the button is pressed), where is a given integer, and starts counting down;

  • When the button is pressed with the LED light off, the LED light will be lit up;

  • When the button is pressed with the LED light on, the value of the counter will be increased by 1;

  • When the timer counts down to 0, the LED light turns off.

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 , BaoBao will immediately press the button times; If the current time in seconds is an integer and is a multiple of another given integer , DreamGrid will immediately press the button times.

Note that

  • 0 is a multiple of every integer;

  • Both BaoBao and DreamGrid are good at pressing the button, so it takes no time for them to finish pressing;

  • If BaoBao and DreamGrid are scheduled to press the button at the same second, DreamGrid will begin pressing the button times after BaoBao finishes pressing the button times.

The game starts at 0 second and ends after seconds (if the button will be pressed at seconds, the game will end after the button is pressed). What's the value of the counter when the game ends?

Input

There are multiple test cases. The first line of the input contains an integer (about 100), indicating the number of test cases. For each test case:

The first and only line contains six integers , , , , and (, ). Their meanings are described above.

Output

For each test case output one line containing one integer, indicating the value of the counter when the game ends.

Sample Input

2
8 2 5 1 2 18
10 2 5 1 2 10

Sample Output

6
4

Hint

We now explain the first sample test case.

  • At 0 second, the LED light is initially off. After BaoBao presses the button 2 times, the LED light turns on and the value of the counter changes to 1. The value of the timer is also set to 2.5 seconds. After DreamGrid presses the button 1 time, the value of the counter changes to 2.

  • At 2.5 seconds, the timer counts down to 0 and the LED light is off.

  • At 5 seconds, after DreamGrid presses the button 1 time, the LED light is on, and the value of the timer is set to 2.5 seconds.

  • At 7.5 seconds, the timer counts down to 0 and the LED light is off.

  • At 8 seconds, after BaoBao presses the button 2 times, the LED light is on, the value of the counter changes to 3, and the value of the timer is set to 2.5 seconds.

  • At 10 seconds, after DreamGrid presses the button 1 time, the value of the counter changes to 4, and the value of the timer is changed from 0.5 seconds to 2.5 seconds.

  • At 12.5 seconds, the timer counts down to 0 and the LED light is off.

  • At 15 seconds, after DreamGrid presses the button 1 time, the LED light is on, and the value of the timer is set to 2.5 seconds.

  • At 16 seconds, after BaoBao presses the button 2 times, the value of the counter changes to 6, and the value of the timer is changed from 1.5 seconds to 2.5 seconds.

  • At 18 seconds, the game ends.

题意:

每a秒(c)就会按下按钮b次(d),每次计时器就会重置成v+0.5, 在这段时间内灯亮着,0时刻按下(b+d)次。

当灯亮着的时候,计数器加上你按下的次数的值

当灯灭的时候,会先消耗一次让灯亮起,然后将后续按压的次数记下

求出a和c最小的公倍数之内的计数器次数,然后把剩下的单独求一次就可以了

嗯  当时在现场的时候就有想到这样的做法,但是当时脑子秀逗了,感觉求出他们的最小公倍数那也是1e12,肯定tle,我简直就是睿智,因为a和c最大1e6,也就是说最坏情况只有1e6而已,orz

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll T,a,b,c,d,v,t; ll gcd(ll a,ll b)
{
return !b?a:gcd(b,a%b);
}
int main()
{
scanf("%lld",&T);
while(T--)
{
ll ans = ;
scanf("%lld%lld%lld%lld%lld%lld",&a,&b,&c,&d,&v,&t);
ll lcm = a*c/gcd(a,c);
if(v >= a || v >= c)
{
ans += t/a*b+t/c*d +(b+d-);
}
else
{
ll num = t / lcm;
ll cnt = v;
ll tmpa = a;
ll tmpb = c;
while(tmpa <= lcm || tmpb <= lcm)
{
if(tmpa < tmpb)
{
ans += b;
if(tmpa > cnt)ans --;
cnt = tmpa + v;
tmpa += a; }
else
{
ans += d;
if(tmpb > cnt)ans--;
cnt = tmpb + v;
tmpb += c;
}
}
ans *= num;
t %= lcm;
tmpa = a;
tmpb = c;
cnt = v;
while(tmpa <= t || tmpb <= t)
{
if(tmpa < tmpb)
{
ans += b;
if(tmpa > cnt)ans--;
cnt = tmpa + v;
tmpa += a;
}
else
{
ans += d;
if(tmpb > cnt)ans --;
cnt = tmpb + v;
tmpb += c;
}
}
ans += b+d-;
}
printf("%lld\n",ans);
}
return ;
}

2018 icpc 青岛网络赛 J.Press the Button的更多相关文章

  1. 2018 ICPC青岛网络赛 B. Red Black Tree(倍增lca好题)

    BaoBao has just found a rooted tree with n vertices and (n-1) weighted edges in his backyard. Among ...

  2. 2018 ICPC 沈阳网络赛

    2018 ICPC 沈阳网络赛 Call of Accepted 题目描述:求一个算式的最大值与最小值. solution 按普通算式计算方法做,只不过要同时记住最大值和最小值而已. Convex H ...

  3. 2018 ICPC 徐州网络赛

    2018 ICPC 徐州网络赛 A. Hard to prepare 题目描述:\(n\)个数围成一个环,每个数是\(0\)~\(2^k-1\),相邻两个数的同或值不为零,问方案数. solution ...

  4. 2018 ICPC 焦作网络赛 E.Jiu Yuan Wants to Eat

    题意:四个操作,区间加,区间每个数乘,区间的数变成 2^64-1-x,求区间和. 题解:2^64-1-x=(2^64-1)-x 因为模数为2^64,-x%2^64=-1*x%2^64 由负数取模的性质 ...

  5. ACM-ICPC 2018 青岛赛区网络预赛 J. Press the Button(数学)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4056 题意:有一个按钮,时间倒计器和计数器,在时间[0,t]内, ...

  6. 2018 ICPC南京网络赛 L Magical Girl Haze 题解

    大致题意: 给定一个n个点m条边的图,在可以把路径上至多k条边的权值变为0的情况下,求S到T的最短路. 数据规模: N≤100000,M≤200000,K≤10 建一个立体的图,有k层,每一层是一份原 ...

  7. 2018.9青岛网络预选赛(J)

    传送门:Problem J https://www.cnblogs.com/violet-acmer/p/9664805.html 题目大意: BaoBao和DreamGrid玩游戏,轮流按灯的按钮, ...

  8. 2018 icpc 徐州网络赛 F Features Track

    这个题,我也没想过我这样直接就过了 #include<bits/stdc++.h> using namespace std; ; typedef pair<int,int> p ...

  9. 2018 ACM-ICPC 青岛网络赛

    最近打比赛不知道为什么总是怀疑自己 写完之后不敢交,一定跟学长说一遍自己的思路 然后发现"哦原来我是对的" 然后就A掉了…… 所以还是要有自信 Problem A 最大值直接输出m ...

随机推荐

  1. 锤子科技"临死前"被"接盘" ,内部人士爆料已改签今日头条母公司

    就在昨天,据据锤子科技内部人士透露,部分锤子科技员工在昨天已经接到了相关的临时通知,要求改签劳动合同至今日头条的母公司——字节跳动.至于这是锤子科技真正再度复活还是借尸还魂都不重要,重要的是,作为忠实 ...

  2. 一篇文章让你了解Android各个版本的历程

    2008年--至今 Android 1.5(Cupcake纸杯蛋糕): 智能虚拟键盘:使用widgets实现桌面个性化:在线文件夹(Live Folder)快速浏览在线数据:视频录制和分享:图片上传: ...

  3. Google开发者大会:你不得不知的Tensorflow小技巧

    Google开发者大会:你不得不知的Tensorflow小技巧 同步滚动:开   Google Development Days China 2018近日在中国召开了.非常遗憾,小编因为不可抗性因素滞 ...

  4. Confluence 6 log4j 日志级别

    日志级别 DEBUG - 被设计为用来获得最多的信息和事件,在对应用程序进行调试的时候,这个日志级别通常能够提供最多的有效信息(查看应用程序怎么了) INFO - 有关系统正常运行-计划任务运行,服务 ...

  5. Confluence 6 为外部用户管理获得支持

    本页面描述了如果你在配置外部用户管理的时候遇到了问题,如何向 Atlassian 支持项目组寻求帮助.外部用户目录挂你包括 Active Directory,其他 LDAP 服务器,Atlassian ...

  6. 前端图片缓存之通过img标签加载GIF只能播放一次问题(转载)

    最近项目中要求再网页中插入一张gif图片,让用户每次到达该位置时动一次,所以我们就制作了一张只动一次的gif图片通过img标签引入.当用户进入该位置时,通过remove()清除图片然后重新append ...

  7. 【mongoDB高级篇①】聚集运算之group与aggregate

    group 语法   db.collection.group({ key:{field:1},//按什么字段进行分组 initial:{count:0},//进行分组前变量初始化,该处声明的变量可以在 ...

  8. javadoc 标签功能

    CMD文档注释编译命令: javadoc -d text Helloword2.java(text 是保存标签文档的文件夹,可以写) javadoc -d doc -encoding UTF-8 -c ...

  9. laravel 路由缓存

    使用路由缓存之前,需要知晓路由缓存只能用于控制器路由,不能用于闭包路由,如果路由定义中包含闭包路由将无法进行路由缓存,只有将所有路由定义转化为控制器路由或资源路由后才能执行路由缓存命令: php ar ...

  10. burpsuite使用教程和实战详解(一)

    1.最近做渗透测试,其实使用一种方式很难全面的对一个web或者app等安全服务器做安全评估,所以要尽可能的对网络安全的渗透测试有一个较全面的认知.不光要熟悉前端和 后天的编程,还有掌握基于这两种编程的 ...