• cogs 448. 神牛果 神奇&&好理解的思路


    ☆   输入文件:1.in   输出文件:1.out   简单对比
    时间限制:1 s   内存限制:128 MB

    【题目描述】
    在某次膜拜大会上,一些神牛被要求集体膜拜。这些神牛被奖励每人吃一些神牛果。但是,每个神牛的肚量不一样。为了不显得某些人吃得太多,决定两人一组,使得吃得最多的那组吃得尽量少。(神牛数为偶数)
    【输入格式】
    第一行一个整数 n。(n<=10000)
    第二行有 n 个正整数,为给定的一列数字,表示每个神牛能吃多少神牛果。(数字均小于 1000000000)
    文件名为“1.in”。
    【输出格式】
    一个正整数,吃的最多的一组神牛吃的个数的最小值。
    文件名为“1.out”。
    【输入样例】
    4
    1 5 2 8
    【输出样例】
    9

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<algorithm>
     4 
     5 using namespace std;
     6 const int N=10001;
     7 
     8 long long a[N];
     9 
    10 inline void read(long long & x) 
    11 {
    12     char c=getchar();
    13     x=0;
    14     while(c<'0'||c>'9')c=getchar();
    15     while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();
    16 }
    17 
    18 inline void rread(int & x) 
    19 {
    20     char c=getchar();
    21     x=0;
    22     while(c<'0'||c>'9')c=getchar();
    23     while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();
    24 }
    25 
    26 int main()
    27 {
    28     freopen("1.in","r",stdin);
    29     freopen("1.out","w",stdout);
    30     int n;
    31     rread(n);
    32     long long ans=-1;
    33     for(int i=1;i<=n;i++)
    34     {
    35         read(a[i]);
    36     }
    37     sort(a+1,a+n+1);
    38     for(int i=1;i<=n;i++)
    39     {
    40         ans=max(ans,a[i]+a[n-i+1]);
    41     }
    42     printf("%lld",ans);
    43 }
  • 相关阅读:
    软件工程概论-用户登录界面
    2016.11.25异常处理
    2016.11.18多态
    2016.11.11继承与接口
    11.6数组
    10.28字符串加密等
    python 读写文件
    python可变的类型、不可变的类型
    python 字典练习 记录学生是否交作业的小程序
    python字典
  • 原文地址:https://www.cnblogs.com/lyqlyq/p/6863231.html
Copyright © 2020-2023  润新知