• 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 }
  • 相关阅读:
    计算机术语
    【转】 物理内存和线性空间
    windows Visual Studio 上安装 CUDA【转载】
    windows Notepad++ 上配置 vs 编译器 , 编译并运行
    单列模式 [转载]
    Java Swing布局管理器GridBagLayout的使用示例 [转]
    五年java工作应具备的技能
    三年java软件工程师应有的技技能
    京东面试题 Java相关
    京东笔试题总结
  • 原文地址:https://www.cnblogs.com/tingtin/p/9667078.html
Copyright © 2020-2023  润新知