zoj 4056

Posted tingtin

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了zoj 4056相关的知识,希望对你有一定的参考价值。

技术分享图片

技术分享图片

  • 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次按钮,若同是a,c的倍数,先a,后c
若按之前为暗,按一次变亮,若按之前为亮,按一次为计数器+1
每次按一下,都会让计时器重新设置为v+0.5(开始倒计时,时间到0,就会变暗)
问[0,t]的时间内,计数器最后为多少。(0为任意数的倍数)

 

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <algorithm>
 4 #include <cstring>
 5 #include <string>
 6 #include <cmath>
 7 using  namespace std;
 8 #define ll long long
 9 int T;
10 ll a,b,c,d,v,t;
11 ll gcd(ll a,ll b)
12 {
13     return b==0?a:gcd(b,a%b);
14 }
15 ll lcm(ll a,ll b)
16 {
17     return a*b/gcd(a,b);
18 }
19 ll x,y,z,cnt,ans,last;
20 /*
21 明显一个最小公倍数为一个周期
22 0 :单独算
23 再计算除一个周期的结果*周期数
24 再加上不满一个周期的结果
25 */
26 int  main()
27 {
28     scanf("%d",&T);
29     while(T--){
30     scanf("%lld%lld%lld%lld%lld%lld",&a,&b,&c,&d,&v,&t);
31     ans=b+d-1;
32     x=0,y=0,last=0,cnt=0;//ans 不用再赋初值了
33     /*
34     
35     */
36     z=lcm(a,c);//(a,c) 不是(x,y)
37     while(x<z||y<z){
38         if(x+a<=y+c){
39             x+=a;
40             if(x<=last+v) cnt++;
41             cnt+=b-1;
42             last=x;
43         }
44         else{
45             y+=c;
46             if(y<=last+v) cnt++;
47             cnt+=d-1;
48             last=y;
49         }
50         
51     }
52     ans+=cnt*(t/z);//cnt为一个周期的结果
53     t%=z;
54     x=0,y=0,last=0;
55     while(x+a<=t||y+c<=t){//保证在t的范围内
56         if(x+a<=y+c){
57             x+=a;
58             if(x<=last+v) ans++;
59             ans+=b-1;
60             last=x;
61         }
62         else{
63             y+=c;
64             if(y<=last+v) ans++;
65             ans+=d-1;
66             last=y;
67         }
68     }
69     printf("%lld
",ans);
70     }
71     return  0;
72 }

 




以上是关于zoj 4056的主要内容,如果未能解决你的问题,请参考以下文章

HDOJ4056 Draw a Mess

进行资产设备研发时,TP4056充电电流和匹配电阻的关系

TP4056的好处有哪些?

锂电池充电(TP4056A芯片)电路分享

群赛 ZOJ3741(dp) ZOJ3911(线段树)

ZOJ4113 Calandar