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 }
  • 相关阅读:
    Java 获取字符串指定下标位置的值 charAt()
    Java 获取字符串长度 length()
    Java 字符串拼接 StringBuilder() StringBuffer
    ngBind {{}} ngBindTemplate
    什么是:before和:after?
    滚屏加载
    JavaScript 高程三读书笔记;
    angularjs 构建主页 内置过滤器、日期的格式化
    Angular实现递归指令
    JQuery获取浏览器窗口的可视区域高度和宽度,滚动条高度
  • 原文地址:https://www.cnblogs.com/PrayG/p/5749682.html
Copyright © 2011-2022 走看看