cf的a题没什么好说到,100的量级,每个人给2张牌,使每个人手中的牌点数相等。保证有一种分配方案。
对每个人,先计算出手中的牌的点数,然后循环两遍拿牌就可以。
 
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
#include<iostream>
#include<stdint.h>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<math.h> using namespace std;
int main()
{
int n;
scanf("%d",&n);
int a[];
int sum=;
for(int i=; i<n; i++)
{
scanf("%d",&a[i]);
sum+=a[i];
}
int vis[];
for(int i=; i<=; i++) vis[i]=;
int tt=sum/(n/);
for(int i=; i<n/; i++)
{
int tmp=tt;
for(int j=; j<n; j++)
{
if(tmp>=a[j]&&!vis[j])
{
printf("%d ",j+);
tmp-=a[j];
vis[j]=;
break;
}
}
for(int j=; j<n; j++)
{
if(tmp==a[j]&&!vis[j])
{
printf("%d\n",j+);
vis[j]=;
break;
}
} }
return ;
}

最新文章

  1. SQL排序问题
  2. codeforces #369div2 B. Chris and Magic Square
  3. RN的像素及布局
  4. CR LF的由来
  5. 基于MVC4+EasyUI的Web开发框架经验总结(15)--在MVC项目中使用RDLC报表
  6. mvc4 用NPOI导出Excel
  7. dede 单表模型动态浏览设置 arclistsg arc.sglistview.class.php
  8. EXPLAIN句法 优化表结构
  9. python安装——Windows平台
  10. FZU-Problem 2294 Uint47 calculator
  11. 1.2.7 Excel表格打印技巧
  12. LVM管理之减少LV的大小
  13. axios的初步使用
  14. Go语言之高级篇beego框架安装与使用
  15. Ubuntu下从外网上北邮人BT
  16. MySQL课堂练习 20162315
  17. leetcode 数据库题解
  18. Android链接蓝牙电子称
  19. PotPlayer 进度条显示缩略图
  20. android签名生成和发布

热门文章

  1. NPOI读取Excel2003,2007
  2. IIS8集成模式下打开静态资源被aspx处理程序处理,StaticFileModule失效问题分析
  3. 使用Spring Cloud Sleuth和Zipkin进行分布式链路跟踪
  4. 【翻译】自定义 UIViewController Transitions
  5. 关于BOM UTF8
  6. mysql 初始化报错 /usr/local/mysql/bin/mysqld:error while loading shared libraries :libaio.so.1
  7. fl2440hello world模块驱动编写
  8. solr6.6 配置拼音分词
  9. 转:Android推送技术研究
  10. qml自学笔记------自己写相似于劲舞团的按键小游戏(中)