博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
青岛网络赛J-Press the button【暴力】
阅读量:5076 次
发布时间:2019-06-12

本文共 5125 字,大约阅读时间需要 17 分钟。

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

28 2 5 1 2 1810 2 5 1 2 10

Sample Output

64

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进行特判 

乘以相应的倍数即可

 

1 #include 
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 10 using namespace std;11 12 typedef long long LL;13 14 int T;15 LL a, b, c, d, v, t;16 vector
press;17 18 LL gcd(LL a, LL b)19 {20 if(b == 0){21 return a;22 }23 else{24 return gcd(b, a % b);25 }26 }27 28 LL LCM(LL a, LL b)29 {30 return a * b / gcd(a, b);31 }32 33 int main()34 {35 cin>>T;36 while(T--){37 press.clear();38 scanf("%lld%lld%lld%lld%lld%lld", &a, &b, &c, &d, &v, &t);39 LL lcm = LCM(a, c);40 41 LL ans = 0, res = t % lcm, tmp = 0;42 for(int i = 0; i * a < lcm; i++){43 if(i * a <= res){44 ans += b;45 }46 tmp += b;47 press.push_back(a * i);48 }49 for(int i = 0; i * c < lcm; i++){50 if(i * c <= res){51 ans += d;52 }53 tmp += d;54 press.push_back(c * i);55 }56 sort(press.begin(), press.end());57 58 for(int i = 1; i < press.size(); i++){59 if(press[i] - press[i - 1] > v){60 tmp--;61 if(press[i] <= res){62 ans--;63 }64 }65 }66 ans += tmp * (t / lcm);67 if(lcm - press[press.size() - 1] > v){68 ans -= (t / lcm);69 }70 ans--;71 72 printf("%lld\n", ans);73 }74 return 0;75 }

 

转载于:https://www.cnblogs.com/wyboooo/p/9682971.html

你可能感兴趣的文章
Illustrated C#学习笔记(一)
查看>>
理解oracle中连接和会话
查看>>
两种最常用的Sticky footer布局方式
查看>>
Scrapy实战篇(三)之爬取豆瓣电影短评
查看>>
HDU 5510 Bazinga KMP
查看>>
[13年迁移]Firefox下margin-top问题
查看>>
Zookeeper常用命令 (转)
查看>>
Java程序IP v6与IP v4的设置
查看>>
RUP(Rational Unified Process),统一软件开发过程
查看>>
数据库链路创建方法
查看>>
Enterprise Library - Data Access Application Block 6.0.1304
查看>>
重构代码 —— 函数即变量(Replace temp with Query)
查看>>
Bootstrap栅格学习
查看>>
程序员的数学
查看>>
聚合与组合
查看>>
jQuery如何获得select选中的值?input单选radio选中的值
查看>>
设计模式 之 享元模式
查看>>
如何理解汉诺塔
查看>>
洛谷 P2089 烤鸡【DFS递归/10重枚举】
查看>>
15 FFT及其框图实现
查看>>