zoukankan      html  css  js  c++  java
  • [ZJOI2006]皇帝的烦恼

    嘟嘟嘟


    首先瞎想可以知道,一定选相邻两个数之和最大的。这样后面的将军选和前面的前面的一样的勋章就行了。
    不过如果(n)是奇数的话就会gg。然后考虑每一个勋章最多有(frac{n}{2})个人用,所以(lceil frac{sum a[i]}{frac{n}{2}} ceil)个勋章一定够。
    然后两者取max。
    (只考虑第一种情况能对一半点 #滑稽)

    #include<cstdio>
    #include<iostream>
    #include<cmath>
    #include<algorithm>
    #include<cstring>
    #include<cstdlib>
    #include<cctype>
    #include<vector>
    #include<stack>
    #include<queue>
    using namespace std;
    #define enter puts("") 
    #define space putchar(' ')
    #define Mem(a, x) memset(a, x, sizeof(a))
    #define In inline
    typedef long long ll;
    typedef double db;
    const int INF = 0x3f3f3f3f;
    const db eps = 1e-8;
    const int maxn = 2e4 + 5;
    inline ll read()
    {
      ll ans = 0;
      char ch = getchar(), last = ' ';
      while(!isdigit(ch)) last = ch, ch = getchar();
      while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
      if(last == '-') ans = -ans;
      return ans;
    }
    inline void write(ll x)
    {
      if(x < 0) x = -x, putchar('-');
      if(x >= 10) write(x / 10);
      putchar(x % 10 + '0');
    }
    
    int n, sum = 0, a[maxn];
    
    int main()
    {
      n = read();
      for(int i = 1; i <= n; ++i) a[i] = read(), sum += a[i];
      a[n + 1] = a[1];
      int ans = 0;
      for(int i = 1; i <= n; ++i) if(a[i] + a[i + 1] > ans) ans = a[i] + a[i + 1];
      write(max(ans, (sum + (n >> 1) - 1) / (n >> 1))), enter;
      return 0;
    }
    
  • 相关阅读:
    使用JS实现网页动态换肤
    数据库更新Sql脚本总结
    Javascript无刷新获取当前时间
    ASP.NET将网页设为桌面图标实现
    解决在IE浏览器中resize事件执行多次
    linux编译安装gcc5.3.0
    JAVA抽象类和接口
    JAVA内部类
    推测竞赛中测试集的正负比例
    Codeforces Round #742 (Div. 2) 题解
  • 原文地址:https://www.cnblogs.com/mrclr/p/10370376.html
Copyright © 2011-2022 走看看