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≤10​6​​, 1≤v,t≤10​12​​). 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的最小公倍数,所以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-,l=a,r=c;
ll pos=;
while(l<g || r<g)
{
if(l<=r && l<g){
if(l-pos>v) ans1+=(b-);
else ans1+=b;
pos=l;
l+=a;
}
else if(l>r && r<g){
if(r-pos>v) ans1+=(d-);
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-;
pos=,l=a,r=c;
while(l<=t || r<=t)
{
if(l<=r && l<=t){
if(l-pos>v) ans2+=(b-);
else ans2+=b;
pos=l;
l+=a;
}
else if(l>r && r<=t){
if(r-pos>v) ans2+=(d-);
else ans2+=d;
pos=r;
r+=c;
}
}
printf("%lld\n",ans1+ans2);
}
return ;
}

The 2018 ACM-ICPC Asia Qingdao Regional Contest, Online J Press the Button的更多相关文章

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

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

  2. The 2018 ACM-ICPC Asia Qingdao Regional Contest(部分题解)

    摘要: 本文是The 2018 ACM-ICPC Asia Qingdao Regional Contest(青岛现场赛)的部分解题报告,给出了出题率较高的几道题的题解,希望熟悉区域赛的题型,进而对其 ...

  3. The 2018 ACM-ICPC Asia Qingdao Regional Contest

    The 2018 ACM-ICPC Asia Qingdao Regional Contest 青岛总体来说只会3题 C #include<bits/stdc++.h> using nam ...

  4. ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Kraków

    ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Kraków Problem A: Rubik’s Rect ...

  5. 2019-2020 ICPC, Asia Jakarta Regional Contest (Online Mirror, ICPC Rules, Teams Preferred)

    2019-2020 ICPC, Asia Jakarta Regional Contest (Online Mirror, ICPC Rules, Teams Preferred) easy: ACE ...

  6. The 2018 ACM-ICPC Asia Qingdao Regional Contest, Online -C:Halting Problem(模拟)

    C Halting Problem In computability theory, the halting problem is the problem of determining, from a ...

  7. 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 ...

  8. 2018-2019, ICPC, Asia Yokohama Regional Contest 2018 K

    传送门:https://codeforces.com/gym/102082/attachments 题解: 代码: /** * ┏┓ ┏┓ * ┏┛┗━━━━━━━┛┗━━━┓ * ┃ ┃ * ┃ ━ ...

  9. ZOJ - 4048 Red Black Tree (LCA+贪心) The 2018 ACM-ICPC Asia Qingdao Regional Contest, Online

    题意:一棵树上有m个红色结点,树的边有权值.q次查询,每次给出k个点,每次查询有且只有一次机会将n个点中任意一个点染红,令k个点中距离红色祖先距离最大的那个点的距离最小化.q次查询相互独立. 分析:数 ...

随机推荐

  1. Nginx+Php-fpm运行原理

    一.代理与反向代理 现实生活中的例子 1.正向代理:访问google.com 如上图,因为google被墙,我们需要vpnFQ才能访问google.com. vpn对于“我们”来说,是可以感知到的(我 ...

  2. -2 caffe数据结构

    一.Blob 使用: 访问数据元素: 计算diff: 保存数据与读取数据: 二.Layer 三.Net

  3. 【模板】 非旋转treap

    模板:luogu P3369 [模板]普通平衡树 code: #include <cstdio> #include <cstdlib> const int MAX_N=1000 ...

  4. 使用Requests+正则表达式爬取猫眼TOP100电影并保存到文件或MongoDB,并下载图片

    需要着重学习的地方:(1)爬取分页数据时,url链接的构建(2)保存json格式数据到文件,中文显示问题(3)线程池的使用(4)正则表达式的写法(5)根据图片url链接下载图片并保存(6)MongoD ...

  5. ssh远程连接和linux基本操作

    客户端工具:Xshell,SecureCRT 启动网卡(eth0): ifup eth0 查看IP地址: ifconfig       [root@oldboy~] : [登入名 @ 主机名 文件或者 ...

  6. Python - def 函数

    1.def 函数 如果我们用代码实现了一个小功能,但想要在程序代码中重复使用,不能在代码中到处粘贴这些代码,因为这样做违反了软件工程中 DRY原则. Python 提供了 函数功能,可以将我们这部分功 ...

  7. apache 与 nginx 详解

    Apache与Nginx的优缺点比较 1.nginx相对于apache的优点: 轻量级,同样起web 服务,比apache 占用更少的内存及资源 抗并发,nginx 处理请求是异步非阻塞的,而apac ...

  8. 在centOS6.5 上安装使用pipework

    需求:镜像生成了2个含有tomcat的容器,用nginx进行负载均衡.但是容器重启后ip会自动改变...所以使用pipework进行分配静态ip pipework安装 OS:centos6.5 第一步 ...

  9. C++类中静态变量和静态方法的注意事项

    在C++中,静态成员是属于整个类的而不是某个对象,静态成员变量仅仅存储一份供全部对象共用.所以在全部对象中都能够共享它.使用静态成员变量实现多个对象之间的数据共享不会破坏隐藏的原则,保证了安全性还能够 ...

  10. 【Hibernate步步为营】--单向关联一对一映射

    上篇文章对多对一的关联映射做了具体的分析,它在实现上能够有两种方式,而且这两种方式实现也非常easy,关键是标签<many-to-one>的使用,它分别指明了多端和一端的映射关系.这样的映 ...