zoukankan      html  css  js  c++  java
  • Codefroces 939 C Convenient For Everybody

    939 C

    题意:若干年以后地球会变成n个时区, 为了方便计时, 每个时区的时间从1:00开始到n:00点结束, 现在将要举行一场c赛, 每个时区内都有ai个人参加,并且比赛开始时间不早于当地时间s:00, 比赛结束时间不晚于(或等于)f:00才会参加,现在求比赛的开始时间(第一时区的当地时间),使得参加人数最多,如果有多个答案,输出时间最小的那个。

    题解:我们可以看作当地时间在[s:00,f-1:00]时间内的人会参加比赛,然后每次增加一个小时就删除最右边那个区间的人数,加上最左边区间的人数,再进行比较就好了。

    代码:

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 #define ll long long
     4 #define fi first
     5 #define se second
     6 #define lson l,m,rt<<1
     7 #define rson m+1,r,rt<<1|1
     8 #define max3(a,b,c) max(a,max(b,c))
     9 const int INF = 0x3f3f3f3f;
    10 typedef pair<int,int> pll;
    11 const int N = 1e5+5;
    12 ll s, f;
    13 ll a[N];
    14 int n;
    15 ll ans , id = 1;
    16 int main()
    17 {
    18     ios::sync_with_stdio(false);
    19     cin.tie(0);
    20     cout.tie(0);
    21     cin >> n;
    22     for(int i = 1; i <= n; i++)
    23         cin >> a[i];
    24     cin >> s >> f;
    25     f--;
    26     int l = s, r = f;
    27     ll num = 0;
    28     for(int i = s; i <= f; i++)
    29         num += a[i];
    30     ans = num;
    31     for(int i = 2; i <= n; i++)
    32     {
    33         num -= a[r];
    34         r--;
    35         l--;
    36         if(l == 0) l = n;
    37         if(r == 0) r = n;
    38         num += a[l];
    39         if(num > ans)
    40         {
    41             ans = num;
    42             id = i;
    43         }
    44     }
    45     cout << id << endl;
    46     return 0;
    47 }
  • 相关阅读:
    pymysql学习笔记
    logging库基本使用(官方文档搬运)
    ddt学习笔记
    openpyxl 基本使用
    jieba库基本使用
    PyInstaller库基本使用
    time库基本使用
    react-dnd 拖拽排序
    create-react-app 基于ts项目,使用react-router-dom搭建项目
    使用create-react-app创建ts项目
  • 原文地址:https://www.cnblogs.com/MingSD/p/8455503.html
Copyright © 2011-2022 走看看