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 }
  • 相关阅读:
    LeetCode 67 Add Binary(二进制相加)(*)
    从头认识Spring-3.1 简单的AOP日志实现-某方法之前的前后记录日志
    Registration system
    BZOJ 1055 HAOI2008 玩具取名 动态规划
    9.Laravel5学习笔记:在laravel中注冊自己的服务到容器中
    B-Tree 索引和 Hash 索引的对照
    负载均衡之基于DNS负载
    Eclipse中git插件导入远程库和上传项目源代码到远程库
    Android开发艺术-第二章 IPC 机制
    一天教你入门struts2
  • 原文地址:https://www.cnblogs.com/PrayG/p/5749682.html
Copyright © 2011-2022 走看看