A. Cards
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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.

Output

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.

Examples
input
6
1 5 7 4 4 3
output
1 3
6 2
4 5
input
4
10 10 10 10
output
1 2
3 4
Note

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的更多相关文章

  1. Codeforces Round #364 (Div. 2) Cards

    Cards 题意: 给你n个牌,n是偶数,要你把这些牌分给n/2个人,并且让每个人的牌加起来相等. 题解: 这题我做的时候,最先想到的是模拟,之后码了一会,发现有些麻烦,就想别的方法.之后发现只要把它 ...

  2. Codeforces Round #364 (Div. 2)

    这场是午夜场,发现学长们都睡了,改主意不打了,第二天起来打的virtual contest. A题 http://codeforces.com/problemset/problem/701/A 巨水无 ...

  3. Codeforces Round #364 (Div.2) D:As Fast As Possible(模拟+推公式)

    题目链接:http://codeforces.com/contest/701/problem/D 题意: 给出n个学生和能载k个学生的车,速度分别为v1,v2,需要走一段旅程长为l,每个学生只能搭一次 ...

  4. Codeforces Round #364 (Div.2) C:They Are Everywhere(双指针/尺取法)

    题目链接: http://codeforces.com/contest/701/problem/C 题意: 给出一个长度为n的字符串,要我们找出最小的子字符串包含所有的不同字符. 分析: 1.尺取法, ...

  5. 树形dp Codeforces Round #364 (Div. 1)B

    http://codeforces.com/problemset/problem/700/B 题目大意:给你一棵树,给你k个树上的点对.找到k/2个点对,使它在树上的距离最远.问,最大距离是多少? 思 ...

  6. Codeforces Round #490 (Div. 3) F - Cards and Joy

    F - Cards and Joy 思路:比较容易想到dp,直接dp感觉有点难,我们发现对于每一种数字要处理的情况都相同就是有 i 张牌 要给 j 个人分, 那么我们定义dp[ i ][ j ]表示 ...

  7. Codeforces Round #490 (Div. 3) :F. Cards and Joy(组合背包)

    题目连接:http://codeforces.com/contest/999/problem/F 解题心得: 题意说的很复杂,就是n个人玩游戏,每个人可以得到k张卡片,每个卡片上有一个数字,每个人有一 ...

  8. 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 ...

  9. Codeforces Round #364 (Div. 2) A 水

    A. Cards time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...

随机推荐

  1. 【PHP】配置环境变量

    使用Zend Framework的zf.bat创建项目时,出现如下提示:"php.exe"不是内部或外部命令,也不是可运行的程序或批处理文件. 解决方法: 配置php的环境变量: ...

  2. 类似桌面背景壁纸随手指滑动--第三方开源--BackgroundViewPager

    Android BackgroundViewPager在github上的项目主页是:https://github.com/MoshDev/BackgroundViewPager 下载下来即可运行

  3. IBM开发者 JSON 教程

    在异步应用程序中发送和接收信息时,可以选择以纯文本和 XML 作为数据格式.掌握 Ajax 的这一期讨论另一种有用的数据格式 JavaScript Object Notation(JSON),以及如何 ...

  4. about the pageload and page init event

    Page_Init The Page_Init event is the first to occur when an ASP.NET page is executed. This is where ...

  5. 图表控件MsChart使用demo

    chart 控件主要有 Titles 标题集合  Chart Area图形显示区域 Series图表集合 Legends图列的集合 (1)  常用事件: 1. Series1.Points.DataB ...

  6. jQuery学习笔记(1)

    设置和获取HTML,文本和值 val()方法: 1.单选框 <html xmlns="http://www.w3.org/1999/xhtml"> <head r ...

  7. 第九章 管理类型(In .net4.5) 之 继承机制

    1. 概述 本章包括 设计和实现接口.创建和使用基类 以及 使用.net类库提供的标准接口. 2. 主要内容 2.1 设计和实现接口 一个接口包含公共的方法.属性.事件.索引器.类和结构都可以实现接口 ...

  8. python杂记-3(购买商品)

    #!/usr/bin/env python# -*- coding: utf-8 -*-#如下是一个购物程序:#先输入工资,显示商品列表,购买,quit退出,最后格式化输出所买的商品.count = ...

  9. Map和HashMap

    通过查询JDK帮助文档,我们可以得知Map的说明.方法等 import java.util.Map; import java.util.HashMap; class Test{ public stat ...

  10. Node.js:util.inherits 面向对象特性【原型】

    /** * Created by Administrator on 2014/9/4. */ var util = require('util'); function Base() { this.na ...