zoukankan      html  css  js  c++  java
  • Codeforces Round #364 (Div. 2) A 水

    A. Cards
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    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.

    题意:n个数 (n为偶数) 两个配对组合  使得每组的和相同 (数据一定满足条件) 输出n/2对组合的两个数的位置

    题解:结构体排序 头尾配对输出各个的位置

     1 //code  by drizzle
     2 #include<bits/stdc++.h>
     3 #include<iostream>
     4 #include<cstring>
     5 #include<cstdio>
     6 #define ll __int64
     7 #define PI acos(-1.0)
     8 #define mod 1000000007
     9 using namespace std;
    10 int n;
    11 struct node
    12 {
    13     int x;
    14     int pos;
    15 }N[105];
    16 bool cmp(struct node aa,struct node bb)
    17 {
    18     return aa.x<bb.x;
    19 }
    20 int main()
    21 {
    22     scanf("%d",&n);
    23     for(int i=1;i<=n;i++)
    24         {
    25             scanf("%d",&N[i].x);
    26             N[i].pos=i;
    27         }
    28     sort(N+1,N+n+1,cmp);
    29     for(int i=1;i<=n/2;i++)
    30         printf("%d %d
    ",N[i].pos,N[n+1-i].pos);
    31     return 0;
    32 }
  • 相关阅读:
    【Axure】快捷键大全
    【docker】mysql
    PHP filesystem attack vectors
    如何防御“神器”Mimikatz窃取系统密码?
    一段能导致火狐、谷歌Safari浏览器崩溃,甚至让iPhone重启的代码
    windows mysql 自动备份的几种方法
    Mysql的实时同步
    ThinkPHP留后门技巧
    创造tips的秘籍——PHP回调后门
    windows自带的压缩,解压缩命令
  • 原文地址:https://www.cnblogs.com/hsd-/p/5698085.html
Copyright © 2011-2022 走看看