Codeforces Round #364 (Div. 2) A - Cards(水)
来源:互联网 发布:百度自然排名优化费用 编辑:程序博客网 时间:2024/04/28 10:08
思路:水水
#include<bits/stdc++.h>using namespace std;int a[105];int vis[105];int main(){ int n;scanf("%d",&n);int sum = 0;for(int i = 1;i<=n;i++){scanf("%d",&a[i]);sum+=a[i];}sum/=(n/2); for(int i = 1;i<=n;i++){if(vis[i])continue;vis[i]=1;int get = sum-a[i];for(int j = i+1;j<=n;j++)if(!vis[j] && a[j]==get){vis[j]=1;printf("%d %d\n",i,j);break;}}}
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.
- 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/规律】
- Codeforces Round #376 (Div. 2)F. Video Cards(乱搞)
- ★【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 #364 (Div. 2)(A,B,C,D)
- 合并两个的排序链表
- linux中几个有用的快捷键
- junit单元测试
- Radar Installation
- webpack及react的搭配使用(一)
- Codeforces Round #364 (Div. 2) A - Cards(水)
- 修炼一名程序员的职业水准(林庆忠__署名原创)
- 【总结】机房合作碎知识总结二
- *ACM集训day13
- 数组复制 System.arraycopy用法例
- 克鲁斯卡尔
- 求逆元的几种办法
- unity从服务器下载资源并且保存到本地
- Codeforces Round #364 (Div. 2) B Cells Not Under Attack(数学)