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
  • 相关阅读:
    使用Layui上传图片,并进行压缩(非原创,证实可用)
    mysql 存储过程及事件
    Redis一些简单的笔记
    RIOT 技术笔记-01 RIOT介绍
    杂七杂八-ubuntu安装eclipse
    杂七杂八-sqlyog连接mysql错误码2058
    杂七杂八-Mysql8.0忘记root密码
    RIOT学习笔记-01 cygwin安装
    Ubutun-安装远程桌面
    中间件-RocketMQ 02 Docker下的安装
  • 原文地址:https://www.cnblogs.com/superxuezhazha/p/5698125.html
Copyright © 2011-2022 走看看