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 }
  • 相关阅读:
    Echarts使用笔记
    vue导出pdf
    mvn上传pom/jar至Nexus私服
    Linux下安装Redis
    国内首发,这款 Serverless 云原生一体化部署工具正式开源!
    使用云托管快速部署CMS内容管理系统
    云开发走进高校,腾讯云联合新工科联盟探索新生工程教育模式
    从0到3000万,TA们用云开发这样做
    基于 ThinkJS 的云开发体验
    使用小程序·云开发静态托管实现免鉴权h5跳转小程序
  • 原文地址:https://www.cnblogs.com/PrayG/p/5749682.html
Copyright © 2011-2022 走看看