Codeforces Round #364 (Div. 2) A - Cards(水)
2016-07-24 20:14
260 查看
思路:水水
#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;
}
}
}
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
output
input
output
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.
#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;
}
}
}
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.
相关文章推荐
- LA-5059(组合游戏)
- linux中几个有用的快捷键
- LA 4287 Proving Equivalences(强连通分量缩点)
- webpack及react的搭配使用(一)
- Radar Installation
- 合并两个的排序链表
- Service的绑定中,Binder跨进程与非跨进程的区别
- **ACM集训day12——bfs队列
- hdu4786Fibonacci Tree
- 6位随机密码生成器
- 自己动手实现HTTP协议
- 集合类(一) List的用法测试例
- PAT A1042 Shuffling Machine (20)
- spring-mybatis
- 网站安全认证系统的设计变迁
- JavaSE基础--构造函数
- codeforces--701B Cells Not Under Attack
- Spring事务管理(6)-执行目标方法
- MFC中的DC,CDC和HDC
- 《Windows环境下32位汇编语言程序设计(第2版)》-chapter5-基本框架