【Codeforces Round 364 (Div 2)A】【水题】Cards
来源:互联网 发布:windows pe权威指南 编辑:程序博客网 时间:2024/05/16 01:39
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.
61 5 7 4 4 3
1 36 24 5
410 10 10 10
1 23 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.
#include<stdio.h>#include<iostream>#include<string.h>#include<string>#include<ctype.h>#include<math.h>#include<set>#include<map>#include<vector>#include<queue>#include<bitset>#include<algorithm>#include<time.h>using namespace std;void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }#define MS(x,y) memset(x,y,sizeof(x))#define MC(x,y) memcpy(x,y,sizeof(x))#define MP(x,y) make_pair(x,y)#define ls o<<1#define rs o<<1|1typedef long long LL;typedef unsigned long long UL;typedef unsigned int UI;template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b>a)a = b; }template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b<a)a = b; }const int N = 105, M = 0, Z = 1e9 + 7, ms63 = 0x3f3f3f3f;int n;pair<int, int>a[N];int main(){while (~scanf("%d", &n)){for (int i = 1; i <= n; ++i)scanf("%d", &a[i].first), a[i].second = i;sort(a + 1, a + n + 1);for (int i = 1; i <= n / 2; ++i)printf("%d %d\n", a[i].second, a[n + 1 - i].second);}return 0;}
- Codeforces Round #364 (Div. 2) A. Cards
- Codeforces Round #364 (Div. 2) A. Cards
- 【Codeforces Round 364 (Div 2)A】【水题】Cards
- Cards(Codeforces 701A)(Codeforces Round #364Div.2 A)
- Codeforces Round #364 (Div. 2) A - Cards(水)
- codeforces Round #364(Div.2)701A Cards 贪心算法
- Codeforces Round #235 (Div. 2) A. Vanya and Cards
- Codeforces Round #356 (Div. 2) A - Bear and Five Cards
- Codeforces Round #233 (Div. 1) A. Cards
- Codeforces Round #364(Div. 2) A. Cards【模拟】 && B. Cells Not Under Attack【SET/规律】
- ★【16.6.9】Codeforces Round #356 (Div. 2) A. Bear and Five Cards
- Codeforces Round #356 (Div. 2)-A. Bear and Five Cards(模拟)
- Codeforces Round #385 (Div. 2) E. Hongcow Buys a Deck of Cards DP+好题
- Codeforces Round #364 (Div. 2)【A,C】
- Codeforces Round #364 (Div. 2)(A ~ D)
- Codeforces Round #364 (Div. 2) A
- Codeforces Round #304 (Div. 2) C Soldier and Cards
- Codeforces-Round-#356-(Div.-2)-Bear-and-Five-Cards
- Growing Mushrooms
- ThreadLocal
- replace和update的区别是什么
- java日期-时间戳-字符串转换
- SQL 按某一字段特定顺序排序
- 【Codeforces Round 364 (Div 2)A】【水题】Cards
- Android弹幕编程设计实现的解决方案(一)
- Java 泛型
- 改变系统导航栏自带的返回按钮点击事件
- 5-3 树的同构
- 用jQuery获取表格中的值
- 设置Eclipse中文API提示信息
- class-dump的安装和使用
- android SpannableString使用详解