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 }
  • 相关阅读:
    IdentityServer4 接口说明
    MQTT中的Retained(保留消息) 与 LWT(最后遗嘱)
    Docker常用命令
    开源服务容错处理库Polly使用文档
    MQTT 主题的高级特性
    MQTT的$SYS主题定义
    RabbitMQ消息队列之Windows下安装和部署
    RabbitMQ多台物理机集群搭建
    Ocelot.json完整配置文件
    nginx.conf文件配置明细详解
  • 原文地址:https://www.cnblogs.com/PrayG/p/5749682.html
Copyright © 2011-2022 走看看