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 ...
随机推荐
- Ubuntu通过APT配置开发环境
apt-get install vim apt-get install ssh apt-get install apache2 apt-get install redis-server apt-get ...
- mysql中character_set_connection的作用
character_set_client = x character_set_results = xcharacter_set_connection = x; 我们常用在mysql操作类中使用这三面, ...
- 【Zend Studio】10.6.0版本设置默认编码为UTF-8
1.打开Windows->Prefefences 2.找到Workspace->Text file encoding,修改为UTF-8,OK保存.
- sendBroadcast 无法接收
项目中遇到已经sendbroadcast,但是在对应的BroadcastReceiver中却无法调用onReceiver 真是个纠结的问题.找了许久. 终于发现Intent中传递了一个参数(自定义类继 ...
- DELPHI 单元文件结构
unit Unit1; interface {接口部分开始} uses {引用单元列表,这是可选的,如果包含必须紧跟interface关键字} {接口部分声明常量/类型/变量/过程和函数,这些声明对引 ...
- Python学习教程(learning Python)--2.3.1 Python传参函数设计
本节主要讨论设计传递多个参数子函数的设计方法. 在2.3节里我们讨论了如何自己设计一个带参数的子函数的设计方法,现在我们研究一下如何传递两个及以上参数的设计方法. 函数为何要带参数呢?其实原因很简单, ...
- VBA赋值给指定单元格
这是一个Range对象基本操作实例,对指定单元格赋值,然后使用弹窗获取值. 代码如下: Sub test1() Worksheets( MsgBox "工作表Sheet1内单元格A5中的值为 ...
- ORA-01017 invalid username/password;logon denied" (密码丢失解决方案)
1.先确认是否输错 用户名和密码 2.如果的确是丢失密码的话: 查看sqlnet.ora 如果是 SQLNET.AUTHENTICATION_SERVICES= (NONE) , 需更改为SQLNET ...
- python中的各种排序
#encoding=utf-8 import random from copy import copy def directInsertSort(seq): """ 直接 ...
- 【坑】执行Consumer的时候发生java.net.UnknownHostException错误
[时间]: 2016/4/8 17:30 [问题]: kafka执行Consumer实例的时候,发生了一下错误. kafka配置文件server.properties如下: zookeeper配置文件 ...