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[];
int sum=;
for(int i=; i<n; i++)
{
scanf("%d",&a[i]);
sum+=a[i];
}
int vis[];
for(int i=; i<=; i++) vis[i]=;
int tt=sum/(n/);
for(int i=; i<n/; i++)
{
int tmp=tt;
for(int j=; j<n; j++)
{
if(tmp>=a[j]&&!vis[j])
{
printf("%d ",j+);
tmp-=a[j];
vis[j]=;
break;
}
}
for(int j=; j<n; j++)
{
if(tmp==a[j]&&!vis[j])
{
printf("%d\n",j+);
vis[j]=;
break;
}
} }
return ;
}

codeforces #364a Cards的更多相关文章

  1. Codeforces 626B Cards(模拟+规律)

    B. Cards time limit per test:2 seconds memory limit per test:256 megabytes input:standard input outp ...

  2. Codeforces 364A - Matrix

    原题地址:http://codeforces.com/problemset/problem/364/A 题目大意: 给定一个数字a(0 ≤ a ≤ 109)和一个数列s(每个数都是一位,长度不超过40 ...

  3. Codeforces 999F Cards and Joy(二维DP)

    题目链接:http://codeforces.com/problemset/problem/999/F 题目大意:有n个人,n*k张卡牌,每个人会发到k张卡牌,每个人都有一种喜欢的卡牌f[i],当一个 ...

  4. Codeforces 830B - Cards Sorting 树状数组

    B. Cards Sorting time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  5. Codeforces 701A. Cards(水)

    A. Cards time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...

  6. CodeForces 701A Cards

    直接看示例输入输出+提示 1. 统计所有数的和 sum,然后求 sum/(n/2) 的到一半数的平均值 6 1 5 7 4 4 3 ->1+5+7+4+4+3=24  分成3组 每组值为8 in ...

  7. CodeForces 626B Cards

    瞎搞题...凭直觉+猜测写了一发,居然AC了.. #include<cstdio> #include<cstring> #include<cmath> #inclu ...

  8. 【Codeforces 364A】Matrix

    [链接] 我是链接,点我呀:) [题意] 让你求出b[i][j]=s[i]*s[j]规则构成的矩阵 的所有子矩阵中子矩阵的和为a的子矩阵的个数 [题解] (x,y,z,t) 会发现它的和就是sum(x ...

  9. Codeforces 1278F: Cards

    题目传送门:CF1278F. 题意简述: 有 \(n\) 个独立随机变量 \(x_i\),每个随机变量都有 \(p = 1/m\) 的概率取 \(1\),有 \((1-p)\) 的概率取 \(0\). ...

随机推荐

  1. redis踩坑记

    本来打算给一批主库做从库,用来读取数据,还不想碰主库数据. 主库redis2.8.12,从库一开始没注意,docker了一个3.1的,结果slaveof之后命令不兼容,下了一个2.8的(2.8.23好 ...

  2. 【Linux】ubuntu或linux网卡配置/etc/network/interfaces

    转自:http://gfrog.net/2008/01/config-file-in-debian-interfaces-1/   青蛙准备写一个系列文章,介绍一些Debian/Ubuntu里面常用的 ...

  3. html5页面中 触发 拨打电话、发短信 的方式

    <a href="tel:18688888888">拨号</a> <a href="sms:18688888888">发短信 ...

  4. CAD中如何裁剪需要的区域

    M1: 先转换为块的方式进行裁剪 大范围框选复制出来>>B命令生成块>>XC命令>>选择刚才生成的块>>空格>>新边界>>框选新 ...

  5. t-sql 笔记(1)

    Toad-for-SQL-Server-Freeware 1.查询哪些数据库对象使用了某个表 SELECT b.[name], a.[definition] FROM sys.all_sql_modu ...

  6. PHP图片的类型将其自动编码成base64

    <!--根据图片的类型将其自动编码成base64--><html><head><?php$file="test.jpg";$type=ge ...

  7. 怎么在windows7系统我的电脑中添加快捷方式

    在我的电脑中添加一些快捷方式,这样不用每次在开始菜单中去找了 2 选择开始菜单运行 3 输入:Regedit命令 4 进入路径地址:HKEY_LOCAL_MACHINE\SOFTWARE\Micros ...

  8. 基于CentOS与VmwareStation10搭建Oracle11G RAC 64集群环境:3.安装Oracle RAC-3.3.安装前检查

    3.3. 安装前检查 1.检查节点连通性 或:./runcluvfy.sh stage -pre crsinst -n linuxrac1,linuxrac2 -fixup -verbose [gri ...

  9. 为甚么要将某个方法声明为final呢?

    他可以防止其他人覆盖该方法.但更重要的一点或许是:这样做可以有效的"关闭"动态绑定,或者说, 告诉编译器不需要对其进行丰台绑定.这样,编译器就可以为final方法调用生成更有效的代 ...

  10. Python 自用代码(某方标准类网页源代码清洗)

    用于mongodb中“标准”数据的清洗,数据为网页源代码,须从中提取: 标准名称,标准外文名称,标准编号,发布单位,发布日期,状态,实施日期,开本页数,采用关系,中图分类号,中国标准分类号,国际标准分 ...