zoukankan      html  css  js  c++  java
  • T133305 57级返校测试重测-T1-数字配对

    大致题意:

    • 给定偶数个的数字,操作使得两两配对后的最大值最小。

    基本思路:

    • 先排序,然后设i=1,j=n(序列以下标1开始),
    • 每次配对为a[i]+a[j],然后++i,--j。
    • 最后找到最大的配对结果。

    Code:

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #include <queue>
    #include <stack>
    #include <map>
    #include <set>
    #include <list>
    using namespace std;
    #define R read()
    #define GC getchar()
    #define ll long long
    #define ull unsigned long long
    #define INF 0x7fffffff
    #define LLINF 0x7fffffffffffffff
    ll read(){
        ll s=0,f=1;
        char c=GC;
        while(c<'0'||c>'9'){if(c=='-')f=-f;c=GC;}
        while(c>='0'&&c<='9'){s=s*10+c-'0';c=GC;}
        return s*f;
    }
    int n;
    int m[10010];
    int main(){
        n=R;
        for(int i=1;i<=n;++i){
            m[i]=R;
        }
        sort(m+1,m+n+1);//先排序
        for(int i=1;i<=n/2;++i){//配对相加
            m[i]+=m[n-i+1];
        }
        sort(m+1,m+n/2+1);//排序配对结果
        printf("%d
    ",m[n/2]);//输出最大
        return 0;
    }
    
  • 相关阅读:
    对jquery的 attr()和prop()理解
    你真的了解javascript吗
    js代码的一些小技巧
    导出导入数据库
    Mysql授权root用户远程登录
    Centos 忘记root密码怎么办?
    linux挂载概念简述:
    centos7防火墙设置
    centos 防火墙
    centos共享目录
  • 原文地址:https://www.cnblogs.com/FUXyao/p/12875265.html
Copyright © 2011-2022 走看看