zoukankan      html  css  js  c++  java
  • Codeforces 701A. Cards(水)

    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.

     分析:水题,见代码。

     1 /*************************************************************************
     2     > File Name: cfC.cpp
     3     > Author: 
     4     > Mail: 
     5     > Created Time: 2016年08月08日 星期一 13时42分35秒
     6  ************************************************************************/
     7 
     8 #include<iostream>
     9 #include<bits/stdc++.h>
    10 using namespace std;
    11 int a[105],vis[105];
    12 
    13 int main()
    14 {
    15     int n;
    16     cin >> n;
    17     int sum = 0;
    18     for(int i = 1; i <= n; i++)
    19     {
    20         cin >> a[i];
    21         sum += a[i];
    22     }
    23     memset(vis,0,sizeof(vis));
    24     int nn = n /2;
    25     sum = sum / nn;
    26     for(int  i = 1; i <= n; i++)
    27     {
    28         for(int j = i+1; j<= n; j++)
    29         {
    30             if(a[i] + a[j] == sum && !vis[i] && !vis[j])
    31             {
    32                 printf("%d %d
    ",i,j);
    33                 vis[i] = 1;
    34                 vis[j] =1;
    35             }
    36         }
    37     }
    38     return 0;
    39 }
  • 相关阅读:
    C#编程思路
    将字符串类型字段转为map类型字段,使用str_to_map()函数
    写hive脚本时,如果hive的过滤条件比较多。可以把过滤条件放到一个参数里。然后把参数放到过滤条件处。这样以后只需要改参数就可以了
    linux中. 路径/文件
    inner join ,left join 会导致数据发散
    如何批量按分区插入数据
    hive表添加字段后,查不出数据是咋回事?
    linux中$0的含义
    linux中的$#含义
    linux的语法
  • 原文地址:https://www.cnblogs.com/PrayG/p/5749682.html
Copyright © 2011-2022 走看看