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 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.
这个,从大到小排序,然后取头尾就行
#include<bits/stdc++.h>
using namespace std;
int n,m;
struct P
{
int i,num;
}He[105];
bool cmd(P x,P y)
{
return x.num<y.num;
}
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>He[i].num;
He[i].i=i;
}
sort(He+1,He+n+1,cmd);
for(int i=1;i<=n/2;i++)
{
cout<<He[i].i<<" "<<He[n-i+1].i<<endl;
}
return 0;
}
Codeforces Round #364 (Div. 2) A的更多相关文章
- 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 #364 (Div. 2) B. Cells Not Under Attack
B. Cells Not Under Attack time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- Codeforces Round #364 (Div. 2) Cells Not Under Attack
Cells Not Under Attack 题意: 给出n*n的地图,有给你m个坐标,是棋子,一个棋子可以把一行一列都攻击到,在根据下面的图,就可以看出让你求阴影(即没有被攻击)的方块个数 题解: ...
- Codeforces Round #364 (Div. 2) Cards
Cards 题意: 给你n个牌,n是偶数,要你把这些牌分给n/2个人,并且让每个人的牌加起来相等. 题解: 这题我做的时候,最先想到的是模拟,之后码了一会,发现有些麻烦,就想别的方法.之后发现只要把它 ...
- Codeforces Round #364 (Div. 2)->A. Cards
A. Cards time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...
- Codeforces Round #364 (Div. 2) E. Connecting Universities
E. Connecting Universities time limit per test 3 seconds memory limit per test 256 megabytes input s ...
- Codeforces Round #364 (Div. 2) C.They Are Everywhere
C. They Are Everywhere time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
随机推荐
- 2017-2018-1 20179203 《Linux内核原理与分析》第三周作业
攥写人:李鹏举 学号:20179203 ( 原创作品转载请注明出处) ( 学习课程:<Linux内核分析>MOOC课程http://mooc.study.163.com/course/US ...
- bzoj 2510: 弱题 概率期望dp+循环矩阵
题目: Description 有M个球,一开始每个球均有一个初始标号,标号范围为1-N且为整数,标号为i的球有ai个,并保证Σai = M. 每次操作等概率取出一个球(即取出每个球的概率均为1/M) ...
- 逐步改用 IronPython 开发你的 ASP.NET 应用程序
IronPython for ASP.NET 的 CTP 已经发布有一段时间了,我们在看了官方提供的范例之后,相信对一个 ASP.NET 应用程序中完全使用 IronPython 开发还是有一些担心的 ...
- BZOJ3307:雨天的尾巴
浅谈线段树合并:https://www.cnblogs.com/AKMer/p/10251001.html 题目传送门:https://lydsy.com/JudgeOnline/problem.ph ...
- poj 3469 Dual Core CPU——最小割
题目:http://poj.org/problem?id=3469 最小割裸题. 那个限制就是在 i.j 之间连双向边. 根据本题能引出网络流中二元关系的种种. 别忘了写 if ( x==n+1 ) ...
- poj 1519 Digital Roots (计算根数字)
一.Description The digital root of a positive integer is found by summing the digits of the integer. ...
- PHP二维数组,根据多个字段来排序
如果是最最常见的二维数组排序, 大多数情况下也只用到二维: 用php内置函数 array_multisort( ) 是最简单的: <?php 假设, $arr 是一个二维数组, $arg1是取 ...
- Zend Server 安装与配置图文教程
Zend Server是一款专业的PHP Web开发应用服务器,一些初次接触并使用此程序的朋友可能不太了解安装方法,本文为您提供了Zend Server 安装与配置图文教程,欢迎大家阅读,并提出自己的 ...
- JVM原理解析
JVM主要的功能: 内存分配 程序调度 内存释放(栈等自动释放.堆垃圾回收) 异常处理 https://www.cnblogs.com/dingyingsi/p/3760447.html https: ...
- [原创]SQL表值函数:获取从当月计算起往前自定义月份数
今天我现在发现看一篇博文不能够太长,只要能够描述清楚自己想表达的东西,能够让大家知道你要讲什么就行了.因为我今天看了一些长篇博文,真的觉得知识点太多了, 会让人囫囵吞枣. 这篇博文跟我昨天发表的类 ...