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 ...
随机推荐
- cocos run -p android报错 BUILD FAILED ..\ant\build.xml:892
使用编译指令生成apk文件时,出现这个错误,是因为重复引用了..\YourGame\cocos2d\cocos\platform\android\java\bin\classes.jar文件. 为什么 ...
- How to display SSRS report based on customer/Vendor specific language [AX2012]
Common requirement is to show the reports in customer’s language. [example : Quotations, sales confi ...
- p ython笔记第三天
#!/usr/bin/env python# -*- coding:utf-8 -*- # v = "李杰"# for item in v:# print(item)####### ...
- 转:javascript 中select的取值
javascript获取select的值全解 获取显示的汉字 document.getElementById("bigclass").options[window.document ...
- 对云风 cstring 第二次解析
前言 从明天起 关心粮食和蔬菜 我有一所房子 面朝大海 春暖花开 本文前提条件 1.了解 posix 线程 2.了解 原子操作 3.具备简单C基础,或者 你也敲一遍. 如果上面不太清楚,你可以翻看我以 ...
- Hive深入浅出
1. Hive是什么 1) Hive是什么? 这里引用 Hive wiki 上的介绍: Hive is a data warehouse infrastructure built on top of ...
- 随机数范围扩展(如rand7()到rand10())(转)
题目:已知有个rand7()的函数,返回1到7随机自然数,让利用这个rand7()构造rand10() 随机1~10.分析:要保证rand10()在整数1-10的均匀分布,可以构造一个1-10*n的均 ...
- windows phone版的一个儿教app
昨天下午看见一个园友写的一篇关于儿教的api,看了也就两三个接口,所以数据处理应该不会太复杂,主要是界面的效果,要求可能比较高.于是我就重新自己写了一个app,实现很简单,花的时间比较多的地方应该是在 ...
- JavaScript 中怎样判断文本框只能输出英文字母、汉字和数字,不能输入特殊字符!
JS-只能输入中文和英文2008-11-08 10:17在js中用正则表达式对象(RegExp)判断中文 ^[\u0391-\uFFE5]+$英文 ^[A-Za-z]+$中文和英文/^[\u0391- ...
- js判断小数点几位
js如何判断小数点后有几位 <script> var n=3.143423423;alert(n.toString().split(".")[1].length); & ...