zoukankan      html  css  js  c++  java
  • cf701A Cards

    There are n cards (n is even) in the deck. Each card has a positive integer written on it. n / 2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one player.

    Find the way to distribute cards such that the sum of values written of the cards will be equal for each player. It is guaranteed that it is always possible.

    Input

    The first line of the input contains integer n (2 ≤ n ≤ 100) — the number of cards in the deck. It is guaranteed that n is even.

    The second line contains the sequence of n positive integers a1, a2, ..., an (1 ≤ ai ≤ 100), where ai is equal to the number written on the i-th card.

    Output

    Print n / 2 pairs of integers, the i-th pair denote the cards that should be given to the i-th player. Each card should be given to exactly one player. Cards are numbered in the order they appear in the input.

    It is guaranteed that solution exists. If there are several correct answers, you are allowed to print any of them.

    Examples
    input
    6
    1 5 7 4 4 3
    output
    1 3
    6 2
    4 5
    input
    4
    10 10 10 10
    output
    1 2
    3 4
    Note

    In the first sample, cards are distributed in such a way that each player has the sum of numbers written on his cards equal to 8.

    In the second sample, all values ai are equal. Thus, any distribution is acceptable.

    水题简直了

    排个序然后从头尾各取一个

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<cstring>
     4 #include<cstdlib>
     5 #include<algorithm>
     6 #include<cmath>
     7 #include<queue>
     8 #include<deque>
     9 #include<set>
    10 #include<map>
    11 #include<ctime>
    12 #define LL long long
    13 #define inf 0x7ffffff
    14 #define pa pair<int,int>
    15 #define pi 3.1415926535897932384626433832795028841971
    16 using namespace std;
    17 inline LL read()
    18 {
    19     LL x=0,f=1;char ch=getchar();
    20     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    21     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    22     return x*f;
    23 }
    24 inline void write(LL a)
    25 {
    26     if (a<0){printf("-");a=-a;}
    27     if (a>=10)write(a/10);
    28     putchar(a%10+'0');
    29 }
    30 inline void writeln(LL a){write(a);printf("
    ");}
    31 struct e{int x,y;}a[110];
    32 bool operator <(e a,e b)
    33 {return a.x<b.x;}
    34 int n,tot;
    35 int main()
    36 {
    37     n=read();
    38     for (int i=1;i<=n;i++)a[i].x=read(),tot+=a[i].x,a[i].y=i;
    39     tot/=n;
    40     sort(a+1,a+n+1);
    41     for (int i=1;i<=n/2;i++)
    42     {
    43         printf("%d %d
    ",a[i].y,a[n-i+1].y);
    44     }
    45 }
    cf701A
    ——by zhber,转载请注明来源
  • 相关阅读:
    [array] leetcode
    [array] leetcode
    [array] leetcode
    无法将“Scaffold-DbContext”项识别为 cmdlet、函数、脚本文件或可运行程序的名称...
    远程桌面报错解决:No Remote Desktop License Servers Available
    linux设置开机自启动
    阿里云ECS服务器环境搭建 ubuntu 16.04 图形界面的安装
    VS C#程序打包覆盖安装不能更新的解决方法
    MySql EF6 DBFirst 向导无法生成 edmx 解决方法(同:您的项目引用了最新实体框架;但是,找不到数据链接所需的与版本兼容的实体框架数据库提供程序)
    "docker build" requires exactly 1 argument(s).
  • 原文地址:https://www.cnblogs.com/zhber/p/5698437.html
Copyright © 2011-2022 走看看