Codeforces Round #364 (Div. 2)->A. 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
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.
题意:n是偶数,组成n/2组人,每人一张牌,使得每组的牌总和差值尽可能小
思路:排序,然后第一个跟最后一个组合,第二个跟倒数第二个组合,以此类推,输出牌原来的位置
#include<bits/stdc++.h>
using namespace std;
struct Node{
int id;
int num;
}a[];
bool cmp(Node a,Node b){
return a.num<b.num;
}
int main(){
int n;
cin>>n;
for(int i=;i<n;i++){
cin>>a[i].num;
a[i].id=i+;
}
sort(a,a+n,cmp);
int i,j;
for(i=,j=n-;i<n/,j>=n/;i++,j--)
{
printf("%d %d\n",a[i].id,a[j].id);
}
return ;
}
Codeforces Round #364 (Div. 2)->A. Cards的更多相关文章
- Codeforces Round #364 (Div. 2) Cards
		
Cards 题意: 给你n个牌,n是偶数,要你把这些牌分给n/2个人,并且让每个人的牌加起来相等. 题解: 这题我做的时候,最先想到的是模拟,之后码了一会,发现有些麻烦,就想别的方法.之后发现只要把它 ...
 - Codeforces Round #364 (Div. 2)
		
这场是午夜场,发现学长们都睡了,改主意不打了,第二天起来打的virtual contest. A题 http://codeforces.com/problemset/problem/701/A 巨水无 ...
 - Codeforces Round  #364 (Div.2) D:As Fast As Possible(模拟+推公式)
		
题目链接:http://codeforces.com/contest/701/problem/D 题意: 给出n个学生和能载k个学生的车,速度分别为v1,v2,需要走一段旅程长为l,每个学生只能搭一次 ...
 - Codeforces Round #364 (Div.2) C:They Are Everywhere(双指针/尺取法)
		
题目链接: http://codeforces.com/contest/701/problem/C 题意: 给出一个长度为n的字符串,要我们找出最小的子字符串包含所有的不同字符. 分析: 1.尺取法, ...
 - 树形dp  Codeforces Round #364 (Div. 1)B
		
http://codeforces.com/problemset/problem/700/B 题目大意:给你一棵树,给你k个树上的点对.找到k/2个点对,使它在树上的距离最远.问,最大距离是多少? 思 ...
 - Codeforces Round #490 (Div. 3) F - Cards and Joy
		
F - Cards and Joy 思路:比较容易想到dp,直接dp感觉有点难,我们发现对于每一种数字要处理的情况都相同就是有 i 张牌 要给 j 个人分, 那么我们定义dp[ i ][ j ]表示 ...
 - Codeforces Round #490 (Div. 3) :F. Cards and Joy(组合背包)
		
题目连接:http://codeforces.com/contest/999/problem/F 解题心得: 题意说的很复杂,就是n个人玩游戏,每个人可以得到k张卡片,每个卡片上有一个数字,每个人有一 ...
 - Codeforces Round #364 (Div. 2) A
		
Description There are n cards (n is even) in the deck. Each card has a positive integer written on i ...
 - Codeforces Round #364 (Div. 2) A 水
		
A. Cards time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...
 
随机推荐
- PHP Startup: Unable to load dynamic library
			
昨天帮一朋友配置服务器结果发现apache日志中有PHP Warning: PHP Startup: Unable to load dynamic library 提示了,然后调试数据库连接发现提示C ...
 - 6)Java中String类
			
1)String对象的初始化 由于String对象特别常用,所以在对String对象进行初始化时,Java提供了一种简化的特殊语法,格式如下: String s = “abc”; ...
 - 编译android程序时DEX过程出现错误
			
今天编译高级设置时出现了错误,这好坑爹啊~ 于是我开始检查代码,发现代码没有错误啊,然后观察MAKE的步骤才发现是DEX时出现了问题!! 下面是错误的LOG: Information:Using ja ...
 - 多点触摸画板(MultiTouchCanvas)
			
这是个简单的支持多点触摸的画板控件, 绘制功能基于WPF InkCanvas,也是我drawTool系列文章的开篇. 阅读该文章后可能产生一些问题: 1. 如果对生成的笔迹对象进行控制 如果要对生成的 ...
 - DB2执行脚本
			
经常会遇到数据库脚本放在.sql文件中,那么怎么去执行这个脚本,而不需要将脚本中的东西粘贴出来再数据库链接工具中执行呢? 下面是DB2数据库脚本执行的办法 环境介绍: 脚本文件名:Script.sql ...
 - Android-----第三方 ImageLoader 的简单配置和使用
			
ImageLoader 的简单使用配置,最好是将配置信息放到application里面,这样我们就不需要每次使用都需要配置了 1.首先我们得有一个包 2.简单的配置信息 //显示图片的配置 Displ ...
 - 获取 UIWebView中用户所点击的图片URL
			
在使用 UIWebView 的时候 (通常是阅读类的 App),会有点击图片放大的需求,那么可以通过设置 UIWebViewDelegate 来过滤请求,取出图片的 URL 这个方法的前提是 img ...
 - 整理了一下 jQuery 的原型关系图,理解起来更加方便一些。
			
图例:黄色的为对象,蓝色的为函数.
 - [转]Ubuntu中root用户和user用户的相互切换
			
[转]Ubuntu中root用户和user用户的相互切换 http://www.cnblogs.com/weiweiqiao99/archive/2010/11/10/1873761.html Ubu ...
 - 配置 Cocoapods的简单配置及胡思乱想
			
外部访问属性 & 重要属性变化 外部访问方法 监听方法 内部属性 swift编写 懒加载控件.布局.监听 使用第三方框架之前先需要配置 cocoapods环境 (唐巧博客) gib 查看自己的 ...