codeforces #364a Cards
1 second
256 megabytes
standard input
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.
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
#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 ;
}
最新文章
- SQL排序问题
- codeforces #369div2 B. Chris and Magic Square
- RN的像素及布局
- CR LF的由来
- 基于MVC4+EasyUI的Web开发框架经验总结(15)--在MVC项目中使用RDLC报表
- mvc4 用NPOI导出Excel
- dede 单表模型动态浏览设置 arclistsg arc.sglistview.class.php
- EXPLAIN句法 优化表结构
- python安装——Windows平台
- FZU-Problem 2294 Uint47 calculator
- 1.2.7 Excel表格打印技巧
- LVM管理之减少LV的大小
- axios的初步使用
- Go语言之高级篇beego框架安装与使用
- Ubuntu下从外网上北邮人BT
- MySQL课堂练习 20162315
- leetcode 数据库题解
- Android链接蓝牙电子称
- PotPlayer 进度条显示缩略图
- android签名生成和发布
热门文章
- NPOI读取Excel2003,2007
- IIS8集成模式下打开静态资源被aspx处理程序处理,StaticFileModule失效问题分析
- 使用Spring Cloud Sleuth和Zipkin进行分布式链路跟踪
- 【翻译】自定义 UIViewController Transitions
- 关于BOM UTF8
- mysql 初始化报错 /usr/local/mysql/bin/mysqld:error while loading shared libraries :libaio.so.1
- fl2440hello world模块驱动编写
- solr6.6 配置拼音分词
- 转:Android推送技术研究
- qml自学笔记------自己写相似于劲舞团的按键小游戏(中)