codeforces #364a Cards
1 second
256 megabytes
standard input
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.
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.
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.
6
1 5 7 4 4 3
1 3
6 2
4 5
4
10 10 10 10
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的更多相关文章
- Codeforces 626B Cards(模拟+规律)
B. Cards time limit per test:2 seconds memory limit per test:256 megabytes input:standard input outp ...
- Codeforces 364A - Matrix
原题地址:http://codeforces.com/problemset/problem/364/A 题目大意: 给定一个数字a(0 ≤ a ≤ 109)和一个数列s(每个数都是一位,长度不超过40 ...
- Codeforces 999F Cards and Joy(二维DP)
题目链接:http://codeforces.com/problemset/problem/999/F 题目大意:有n个人,n*k张卡牌,每个人会发到k张卡牌,每个人都有一种喜欢的卡牌f[i],当一个 ...
- Codeforces 830B - Cards Sorting 树状数组
B. Cards Sorting time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- Codeforces 701A. Cards(水)
A. Cards time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...
- 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 ...
- CodeForces 626B Cards
瞎搞题...凭直觉+猜测写了一发,居然AC了.. #include<cstdio> #include<cstring> #include<cmath> #inclu ...
- 【Codeforces 364A】Matrix
[链接] 我是链接,点我呀:) [题意] 让你求出b[i][j]=s[i]*s[j]规则构成的矩阵 的所有子矩阵中子矩阵的和为a的子矩阵的个数 [题解] (x,y,z,t) 会发现它的和就是sum(x ...
- Codeforces 1278F: Cards
题目传送门:CF1278F. 题意简述: 有 \(n\) 个独立随机变量 \(x_i\),每个随机变量都有 \(p = 1/m\) 的概率取 \(1\),有 \((1-p)\) 的概率取 \(0\). ...
随机推荐
- Scala零基础教学【21-40】
第24讲:Scala中SAM转换实战详解 SAM:single abstract method 单个抽象方法 我们想传入一个函数来指明另一个函数具体化的工作细节,但是重复的样板代码很多. 我们不关 ...
- inline-block 前世今生(转)
曾几何时,display:inline-block 已经深入「大街小巷」,随处可见 「display:inline-block; *display:inline; *zoom:1; 」这样的代码.如今 ...
- 关于css解决俩边等高的问题(等高布局)
等高布局 前段时间公司需哦一个后台管理系统,左侧是导航栏,右侧是content区域.然厚刚开始用的是js 去控制的,但是当页面的椰蓉过长的时候,有与js单线程,加载比较慢,就会有那么一个过程,查找了很 ...
- 使用apt-mirror建立局域网内的Debian/Ubuntu源镜像
转:http://forum.ubuntu.org.cn/viewtopic.php?t=41791 第一次翻译,翻译得不好还请大家见谅,多多指出错误~!:) 原文可以见如下的贴子:http://fo ...
- es6的模块化;js的模块化
现在感觉Java.Python.Js都是越来越工程花,模块化.懂得每个模块的功能和使用场景,你很快的就能搭起一个功能齐备的应用.至于应用的性能.稳定性等,还在于你对模块的理解深度以及组合的成熟度,就看 ...
- http://zhidao.baidu.com/link?url=fX6C1xFLsqiuTY88cjwJYal2x52rOwlJstmz7KWyMc6l9j3FHw2yhvp83timZ86pwhqQ8rONj2xkgo2wbU2tLK
http://zhidao.baidu.com/link?url=fX6C1xFLsqiuTY88cjwJYal2x52rOwlJstmz7KWyMc6l9j3FHw2yhvp83timZ86pwhq ...
- 为甚么要将某个方法声明为final呢?
他可以防止其他人覆盖该方法.但更重要的一点或许是:这样做可以有效的"关闭"动态绑定,或者说, 告诉编译器不需要对其进行丰台绑定.这样,编译器就可以为final方法调用生成更有效的代 ...
- Download FFmpeg
Builds Static builds provide one self-contained .exe file for each program (ffmpeg, ffprobe, ffplay) ...
- 支付宝支付系统繁忙,请稍后再试(ALI64)错误解决
解决方法:将商户支付參数的seller邮箱换成与partner同样的数字串,依然无法支付请检查所给參数
- JAVA利用HttpClient进行POST请求(HTTPS)
目前,要为另一个项目提供接口,接口是用HTTP URL实现的,最初的想法是另一个项目用jQuery post进行请求. 但是,很可能另一个项目是部署在别的机器上,那么就存在跨域问题,而JQuery的p ...