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\n",ans); 70 } 71 return 0; 72 }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现