• Codeforces Round #364 (Div. 2) A


    Description

    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.

    这个,从大到小排序,然后取头尾就行

    #include<bits/stdc++.h>
    using namespace std;
    int n,m;
    struct P
    {
        int i,num;
    }He[105];
    bool cmd(P x,P y)
    {
        return x.num<y.num;
    }
    int main()
    {
       int n;
       cin>>n;
       for(int i=1;i<=n;i++)
       {
           cin>>He[i].num;
           He[i].i=i;
       }
       sort(He+1,He+n+1,cmd);
       for(int i=1;i<=n/2;i++)
       {
           cout<<He[i].i<<" "<<He[n-i+1].i<<endl;
       }
       return 0;
    }
    

      

  • 相关阅读:
    DevExpress GridControl用法----SearchLookUpEdit,单选框,图片,颜色,进度条,分页查询
    EasyUi之Datagrid行拖放冲突处理
    [LeetCode No.1] 两数之和
    [LeetCode No.2] 两数相加
    注册定义文件扩展名图标和关联相应的应用程序
    加载进度-【圆圈+百分比】
    .net core + eureka + spring boot 服务注册与调用
    一个Java类的加载
    Nifi:nifi内置处理器Processor的开发
    Nifi:nifi的基本使用
  • 原文地址:https://www.cnblogs.com/yinghualuowu/p/5698628.html
Copyright © 2020-2023  润新知