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.


Author: JIN, Mengge
Source: The 2018 ACM-ICPC Asia Qingdao Regional Contest, Online

题意:

两个人按灯 第一个人在a的倍数时按b次 第二个人在c的倍数时按d次

如果灯在按时是暗的 则灯会被点亮 并开始倒计时 经过v+0.5秒后灯灭

如果灯在按时是亮的 则每按一次计数器加一 并且倒计时器刷新

问在t时 计数器的值

思路:

比赛的时候想的是 按的总次数是确定的好算的 现在只需要知道有多少个按灯时间之间间隔大于v

这些灯是暗的 需要浪费一次来点亮灯

czc当时提出了用lcm求一个周期的 但是怕时间不够 如果a和c是互质的 lcm可能还是会非常大 优化效果无法估计

trader比赛的时候推了半天的数论还是不行

最后比赛结束看了题解发现竟然真的就是lcm周期暴力来求

下次想这种真的搞不出的情况下 暴力就暴力试一发

先求一个周期里的按灯次数 存入vector 同时求取模后的余数的按灯次数

对vector排序 求得一个周期内用来亮灯的次数

再对周期的最后一个数和lcm进行特判

乘以相应的倍数即可

 #include <iostream>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <cmath>
#include <cstring>
#include <set>
#include <map> using namespace std; typedef long long LL; int T;
LL a, b, c, d, v, t;
vector<LL>press; LL gcd(LL a, LL b)
{
if(b == ){
return a;
}
else{
return gcd(b, a % b);
}
} LL LCM(LL a, LL b)
{
return a * b / gcd(a, b);
} int main()
{
cin>>T;
while(T--){
press.clear();
scanf("%lld%lld%lld%lld%lld%lld", &a, &b, &c, &d, &v, &t);
LL lcm = LCM(a, c); LL ans = , res = t % lcm, tmp = ;
for(int i = ; i * a < lcm; i++){
if(i * a <= res){
ans += b;
}
tmp += b;
press.push_back(a * i);
}
for(int i = ; i * c < lcm; i++){
if(i * c <= res){
ans += d;
}
tmp += d;
press.push_back(c * i);
}
sort(press.begin(), press.end()); for(int i = ; i < press.size(); i++){
if(press[i] - press[i - ] > v){
tmp--;
if(press[i] <= res){
ans--;
}
}
}
ans += tmp * (t / lcm);
if(lcm - press[press.size() - ] > v){
ans -= (t / lcm);
}
ans--; printf("%lld\n", ans);
}
return ;
}

青岛网络赛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. ACM-ICPC 2018 青岛赛区网络预赛 J. Press the Button(数学)

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

  3. HDU 5880 Family View (2016 青岛网络赛 C题,AC自动机)

    题目链接  2016 青岛网络赛  Problem C 题意  给出一些敏感词,和一篇文章.现在要屏蔽这篇文章中所有出现过的敏感词,屏蔽掉的用$'*'$表示. 建立$AC$自动机,查询的时候沿着$fa ...

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

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

  5. luogu 1327 数列排序 & 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 J题 循环节

    luogu 1327 数列排序 题意 给定一个数列\(\{an\}\),这个数列满足\(ai≠aj(i≠j)\),现在要求你把这个数列从小到大排序,每次允许你交换其中任意一对数,请问最少需要几次交换? ...

  6. 2015北京网络赛 J Scores bitset+分块

    2015北京网络赛 J Scores 题意:50000组5维数据,50000个询问,问有多少组每一维都不大于询问的数据 思路:赛时没有思路,后来看解题报告也因为智商太低看了半天看不懂.bitset之前 ...

  7. hihocoder1236(北京网络赛J):scores 分块+bitset

    北京网络赛的题- -.当时没思路,听大神们说是分块+bitset,想了一下发现确实可做,就试了一下,T了好多次终于过了 题意: 初始有n个人,每个人有五种能力值,现在有q个查询,每次查询给五个数代表查 ...

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

  9. J Press the Button

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

随机推荐

  1. (转)x264代码详细阅读之x264.c,common.c,encoder.c

    转自:http://alphamailpost.blog.163.com/blog/static/201118081201281103931932/ x264代码详细阅读第一之x264.chttp:/ ...

  2. Android检测Cursor泄漏的原理以及使用方法(转)

    简介: 本文介绍如何在 Android 检测 Cursor 泄漏的原理以及使用方法,还指出几种常见的出错示例.有一些泄漏在代码中难以察觉,但程序长时间运行后必然会出现异常.同时该方法同样适合于其他需要 ...

  3. php将汉字转换为拼音和得到词语首字母(三)

    <?php function getfirstchar($s0){ $fchar = ord($s0{0}); if($fchar >= ord("A") and $f ...

  4. 创建SQL语句_面试

    创建一个表:create table if not exists Teachaers(tea_id integer  primary key autoincrement,tea_name text,t ...

  5. 详解MathType引用公式编号功能

    在论文创作期间,如果需要在文本中删除大量的公式,手动编号删除的工作量是比较大的,使用MathType引用公式编号功能就可以节约大量的时间,提供很大的方便.本教程将详解MathType引用公式编号功能. ...

  6. linux下mysql 启动命令

    1,使用service 启动.关闭MySQL服务 service mysql start service mysql stop service mysql restart 运行上面命令,其实是serv ...

  7. mysql中/*!40000 DROP DATABASE IF EXISTS `top_server`*/;这中注释有什么作用?

    需求描述: 今天在进行mysqldump实验,使用--add-drop-databases参数,于是在生成的SQL文件中,就出现了. /*!40000 DROP DATABASE IF EXISTS ...

  8. linux中,如何设置每隔2个小时就执行一次某个脚本?

    需求描述: 今天同事问了一个linux上crontab定时任务的问题,说,如何调整一个定时任务每2个小时 执行一次,在此记录下. 操作过程: 1.通过以下的方式设置,每2个小时执行一次脚本 */ * ...

  9. 关于代理ip

    反爬很重要的手段之一就是根据ip来了,包括新浪微博搜索页 微信搜索页 360全系网站360搜索 360百科 360 问答 360新闻,这些都是明确的提示了是根据ip反扒的,所以需要买ip.买得是快代理 ...

  10. Android 中如何从一个App启动另外一个App(如启动支付界面、启动地图界面、应用商场下载App等场景)

    假定两个App,分别是A和B,当A运行某个功能需要启动B,一种是启动B应用,一种直接进入B的某个Activity.搜了很多资料,没有一个完整的.下面就A--Android5.1.1.B--Androi ...