zoukankan      html  css  js  c++  java
  • codeforces #364a Cards

    cf的a题没什么好说到,100的量级,每个人给2张牌,使每个人手中的牌点数相等。保证有一种分配方案。
    对每个人,先计算出手中的牌的点数,然后循环两遍拿牌就可以。
     
    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

    #include<iostream>
    #include<stdint.h>
    #include<algorithm>
    #include<map>
    #include<set>
    #include<vector>
    #include<queue>
    #include<stack>
    #include<math.h>
    
    using namespace std;
    int main()
    {
        int n;
        scanf("%d",&n);
        int a[105];
        int sum=0;
        for(int i=0; i<n; i++)
        {
            scanf("%d",&a[i]);
            sum+=a[i];
        }
        int vis[105];
        for(int i=0; i<=105; i++) vis[i]=0;
        int tt=sum/(n/2);
        for(int i=0; i<n/2; i++)
        {
            int tmp=tt;
            for(int j=0; j<n; j++)
            {
                if(tmp>=a[j]&&!vis[j])
                {
                    printf("%d ",j+1);
                    tmp-=a[j];
                    vis[j]=1;
                    break;
                }
            }
            for(int j=0; j<n; j++)
            {
                if(tmp==a[j]&&!vis[j])
                {
                    printf("%d
    ",j+1);
                    vis[j]=1;
                    break;
                }
            }
    
        }
        return 0;
    }
    View Code
  • 相关阅读:
    Tomcat Manager用户配置详解
    自动更新Chromium
    如何方便快速在指定文件夹打开命令行
    让Chrome 接管邮件连接,收发邮件更方便了
    Chrome扩展程序的二次开发:把它改得更适合自己使用
    更改Photoshop 语言为英语(无需语言包)
    Chrome 控制台新玩法-console显示图片以及为文字加样式
    JavaScript—之对象参数的引用传递
    jQuery 绑定事件到动态创建的元素上
    JavaScript –类型之我晕
  • 原文地址:https://www.cnblogs.com/superxuezhazha/p/5698125.html
Copyright © 2011-2022 走看看