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 (v+0.5) seconds (no matter what the value of the timer is before the button is pressed), where v 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 goes out (that is to say, the light is 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 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

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 d times after BaoBao finishes pressing the button b times.

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?

Input

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≤1e6 , 1≤v,t≤1e12 ). 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次灯,如果灯关,则灯亮,如果灯亮count加一,每次按得时候,倒计时v+0.5启动,倒计时结束,灯灭,求进过t秒,count是多少

因为过了a,c的最小公倍数的时候,一切又重头,所以会有循环,因此先求一次0到最小公倍数,其他的,按比例算就好了,最后剩下的时间在算一遍

.。。中间不知道为什么,不用ll就是会爆

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iomanip>
#include<cmath>
#include<float.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#define sf scanf
#define pf printf
#define scf(x) scanf("%d",&x)
#define scff(x,y) scanf("%d%d",&x,&y)
#define scfff(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define prf(x) printf("%d\n",x)
#define mm(x,b) memset((x),(b),sizeof(x))
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
typedef long long ll;
const ll mod=1e9+7;
const double eps=1e-8;
const int inf=0x3f3f3f3f;
using namespace std;
const double pi=acos(-1.0);
const int N=1e7+10;
ll node1[N],node2[N];
ll gcd(ll a,ll b)
{
return b==0?a:gcd(b,a%b);
}
int main()
{
int re;scf(re);
while(re--)
{
ll a,b,c,d;
ll t,v,sum;
ll ans=0;
sf("%lld%lld%lld%lld%lld%lld",&a,&b,&c,&d,&v,&t);
sum=a*c/gcd(a,c);//求最小公倍数
ll num1=sum/a,num2=sum/c;//ac各需要按几次
rep(i,1,num1+1)//记录a要按得时间
node1[i]=i*a;
rep(i,1,num2+1)//记录c要按得时间
node2[i]=i*c;
double val;
ll pos1=1,pos2=1;
ans=b+d-1;val=v+0.5;
ll now=0;//当前的时间
ll jieshu=0;//结束标记
while(1)
{
//cout<<"1"<<" "<<"pos1:"<<node1[pos1]<<" pos2:"<<node2[pos2]<<endl;
if(node1[pos1]<node2[pos2])
{
if(pos1==num1&&pos2==num2)//以防a=c的时候死循环
break;
if(t<node1[pos1])//如果t在0到最小公倍数之间,可以提前结束,下同
{
jieshu=1;
pf("%lld\n",ans);
break;
}
if(node1[pos1]-now<=val)//下个时间到当前时间倒计时有没有结束
ans+=b;
else
ans+=b-1; now=node1[pos1];
pos1++;
}else
{
if(pos1==num1&&pos2==num2)
break;
if(t<node2[pos2])
{
jieshu=1;
pf("%lld\n",ans);
break;
}
if(node2[pos2]-now<=val)
ans+=d;
else
ans+=d-1; now=node2[pos2];
pos2++;
}
if(pos1==num1&&pos2==num2)
break;
}
if(jieshu) continue;
int temp=0;
if(node1[num1]-now<=val)//开始循环的时候,灯还亮吗
temp=1;
ll cishu=t/node1[num1];//循环次数
ans+=(cishu-1)*(ans+temp);
pos1=pos2=1;
t%=node1[num1];//剩下的时间
ans+=temp-1+b+d;
now=0;//重置时间
while(1)//继续走
{
if(node1[pos1]<node2[pos2])
{
if(t<node1[pos1])
break;
if(node1[pos1]-now<=val)
ans+=b;
else
ans+=b-1; now=node1[pos1];
pos1++;
}else
{
if(t<node2[pos2]) break;
if(node2[pos2]-now<=val)
ans+=d;
else
ans+=d-1;
val=v+0.5;
now=node2[pos2];
pos2++;
}
if(pos1==num1&&pos2==num2)
break;
}
pf("%lld\n",ans);
}
return 0;
}

J Press the Button的更多相关文章

  1. 2018 icpc 青岛网络赛 J.Press the Button

    Press the Button Time Limit: 1 Second      Memory Limit: 131072 KB BaoBao and DreamGrid are playing ...

  2. The 2018 ACM-ICPC Asia Qingdao Regional Contest, Online J Press the Button

    BaoBao and DreamGrid are playing a game using a strange button. This button is attached to an LED li ...

  3. The 2018 ACM-ICPC Asia Qingdao Regional Contest, Online J - Press the Button(思维)

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4056 题意 有一个按钮.一个灯.一个计时器和一个计数器,每按一次按钮,计时 ...

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

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

  5. [Android Tips] 2. Disable recent apps dialog on long press home button

    public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); Log.d(&qu ...

  6. The 2018 ACM-ICPC Asia Qingdao Regional Contest, Online Solution

    A    Live Love 水. #include<bits/stdc++.h> using namespace std; typedef long long ll; ; const i ...

  7. The 2018 ACM-ICPC Asia Qingdao Regional Contest(青岛网络赛)

    A Live Love 水 #include <algorithm> #include<cstdio> #include<cstring> using namesp ...

  8. Windows phone常用控件之Button

    Button类:表示一个响应 ButtonBase.Click 事件的 Windows 按钮控件. 继承层次结构: 命名空间:    System.Windows.Controls ClickMode ...

  9. Automate Screen or Button Taps via Tasker : Simulating keypress events

    When using Tasker, sometimes we want to do some automation on screen e.g. screen or button taps. At ...

随机推荐

  1. Hibernate(10)_双向n对1(双向1对n)

    1.双向 1-n 与 双向 n-1 是完全相同的两种情形,这里使用双向多对一来演示 双向 1-n 需要在 1 的一端可以访问 n 的一端, 反之依然. 出版社和图书的关系:Publishers--Bo ...

  2. 开源流媒体服务器SRS学习笔记(1) - 安装、推流、拉流

    SRS(Simple RTMP Server)  是国人写的一款非常优秀的开源流媒体服务器软件,可用于直播/录播/视频客服等多种场景,其定位是运营级的互联网直播服务器集群. 一.安装 官网提供了3种安 ...

  3. 与临时对象的斗争(上)ZZ

    C++ 是一门以效率见长的语言(虽然近来越来越多的人“不齿”谈及效率,我深以为不然,在某一次的程序编写中不对效率锱铢必较并不意味意味着我们就不应该追求更多的更好的做法).总之吧,相比起其它语言,程序员 ...

  4. SSE图像算法优化系列九:灵活运用SIMD指令16倍提升Sobel边缘检测的速度(4000*3000的24位图像时间由480ms降低到30ms)。

    这半年多时间,基本都在折腾一些基本的优化,有很多都是十几年前的技术了,从随大流的角度来考虑,研究这些东西在很多人看来是浪费时间了,即不能赚钱,也对工作能力提升无啥帮助.可我觉得人类所谓的幸福,可以分为 ...

  5. VMware中虚拟机与主机不能ping通解决办法

    先去看看服务全部启动了没? VMware相关服务启动关闭脚本     启动了还报错,接着往下看......     一.如果是桥接模式,那么 可能性1:虚拟机防火墙禁ping,请关闭虚拟机防火墙重试: ...

  6. 每天一个linux命令(5):rmdir

    1.命令简介 rmdir (Remove Directory删除目录): 用来删除空目录,删除某目录时也必须具有对父目录的写权限. 2.用法 用法:rmdir [选项]... 目录... 3.选项 - ...

  7. bootstrap table 的简单Demo

    暂时够用,不够用再补充 T_T script: <link rel="stylesheet" href="lib/bootstrap.min.css"&g ...

  8. 面试汇总——知道什么是同源策略吗?那怎么解决跨域问题?知道 JSONP 原理吗?

    本文是面试汇总分支——知道什么是同源策略吗?那怎么解决跨域问题?知道 JSONP 原理吗?. 同源策略 同源策略(Same origin policy)是一种约定,它是浏览器最核心也最基本的安全功能, ...

  9. Why does Delphi XE7 IDE hangs and fails on out of memory exception?

    引自:   https://stackoverflow.com/questions/27701294/why-does-delphi-xe7-ide-hangs-and-fails-on-out-of ...

  10. MySQL processlist中需要关注的状态

    一般而言,我们在processlist结果中如果经常能看到某些SQL的话,至少可以说明这些SQL的频率很高,通常需要对这些SQL进行进一步优化. 今天我们要说的是,在processlist中,看到哪些 ...