<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      有毒的粽子

      CF1141E Superhero Battle

      A superhero fights with a monster. The battle consists of rounds, each of which lasts exactly n minutes. After a round ends, the next round starts immediately. This is repeated over and over again.

      Each round has the same scenario. It is described by a sequence of n numbers: d1,d2,,dn(?10^6di10^6). The i-th element means that monster's hp (hit points) changes by the value didi during the i-th minute of each round. Formally, if before the i-th minute of a round the monster's hp is h, then after the i-th minute it changes to h:=h+di

      The monster's initial hp is H. It means that before the battle the monster has H hit points. Print the first minute after which the monster dies. The monster dies if its hp is less than or equal to 0. Print -1 if the battle continues infinitely.

      Input

      The first line contains two integers H and n (1H10^121≤n≤2?10^5). The second line contains the sequence of integers d1,d2,…,dn (?10^6di10^6), where di is the value to change monster's hp in the i-th minute of a round.

      Output

      Print -1 if the superhero can't kill the monster and the battle will last infinitely. Otherwise, print the positive integer k such that k is the first minute after which the monster is dead.

      Examples
      input
      1000 6
      -100 -200 -300 125 77 -4
      
      output
      9
      
      input
      1000000000000 5
      -1 0 0 0 0
      
      output
      4999999999996
      
      input
      10 4
      -3 -6 5 4
      
      output
      -1
      題意解釋:輸入,給定了怪物的hp和n輪戰斗對怪物造成的傷害。輸出,怪物的hp降到0及以下即被擊敗輸出第幾分鐘怪物被擊敗或-1.
      解題思路:先判斷第一個周期造成的最高傷害是多少和第一個周期是否對怪物造成了傷害,來確定怪物是否能被擊敗。然后我們通過計算求出到打敗怪物的前一個周期的時間,再判斷最后一個周期何時擊敗怪物。
      其實可以說是個數學題,這里我用了二分來求解,但是long long精度不夠,中間判斷的時候將long long轉為double來提高精度。
      #include <bits/stdc++.h>
      using namespace std;
      typedef long long ll;
      ll a[2000005];
      int main()
      {
          ll hp,n;
          scanf("%lld%lld%lld",&hp,&n,&a[1]);
          ll t=a[1];
          ll aa=0;
          ll mmin=min(t,aa);
          ll flag=1;
          for(int i=2;i<=n;++i)
          {
              scanf("%lld",&a[i]);
              t+=a[i];
              if(mmin>t)
              {
                  mmin=t;
                  flag=i;
              }
          }
          ll tmp=hp;
          tmp+=mmin;
          if(tmp<=0)
          {
              for(int i=1;i<=n;++i)
              {
                  hp+=a[i];
                  if(hp<=0)
                  {
                      cout<<i;
                      return 0;
                  }
              }
          }
          else
          {
              if(t>=0)
              {
                  cout<<-1;
                  return 0;
              }
              ll l=0,r=1000000000000;
              while(l<=r)
              {
                  double mid=(l+r)/2;
                  if(hp+(mid*t)+mmin<=0)
                  {
                      r=mid-1;
                  }
                  else
                  {
                      l=mid+1;
                  }
              }
              hp+=l*t;    
              for(int i=1;i<=n;++i)
              {
                  hp+=a[i];
                  if(hp<=0)
                  {
                      cout<<i+l*n;
                      return 0;
                  }
              }
          }
      }
      View Code

       

      posted on 2019-09-15 22:17  有毒的粽子  閱讀(178)  評論(0)    收藏  舉報

      主站蜘蛛池模板: 亚洲av无码乱码在线观看野外| 草裙社区精品视频播放| 又爆又大又粗又硬又黄的a片| 四虎成人精品永久网站| av午夜福利一片看久久| 一级毛片网| 午夜精品久久久久久久爽| 无码日韩做暖暖大全免费不卡| 托克逊县| www国产精品内射熟女| 国产99久久无码精品| 一亚洲一区二区中文字幕| 日本一区二区三区在线看| 亚洲中文字幕av无码区| 欧美日韩国产图片区一区| 青柠影院免费观看高清电视剧丁香 | 国内精品一区二区不卡| 国产精品午夜福利导航导| 亚洲AV永久中文无码精品综合| 亚洲人成人日韩中文字幕| 青青草原国产AV福利网站| 色就色中文字幕在线视频| 精品国产一区二区三区香蕉| 伊人成人在线视频免费| 在线国产毛片| 天天躁日日躁狠狠躁性色avq| 2020年最新国产精品正在播放| 无遮无挡爽爽免费视频| 国产成人精品亚洲高清在线| 精品国产乱码久久久久夜深人妻| 在线免费观看毛片av| 国产精品久久久久aaaa| 亚洲第四色在线中文字幕| 又黄又无遮挡AAAAA毛片| 老司机性色福利精品视频| 日本中文字幕有码在线视频| 国产高清视频一区二区三区 | 国产精品成| 国产三级a三级三级| 久热这里只有精品12| 日本丰满少妇高潮呻吟|