【Codeforces】-701A-Cards(思维)
2016-08-05 21:50
381 查看
点击打开题目
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 thei-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<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
#define CLR(a,b) memset(a,b,sizeof(a))
struct node
{
int num,ant;
}a[110];
bool cmp(node x,node y)
{
return x.ant<y.ant;
}
int main()
{
int n;
while(~scanf("%d",&n))
{
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i].ant);
a[i].num=i;
}
sort(a+1,a+n+1,cmp);
for(int i=1;i<=(n/2);i++)
printf("%d %d\n",a[i].num,a[n+1-i].num);
}
return 0;
}
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 thei-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.
题解:既然他保证存在是符合的,那么排一下序,前后各挑一个输出序号就好了。
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
#define CLR(a,b) memset(a,b,sizeof(a))
struct node
{
int num,ant;
}a[110];
bool cmp(node x,node y)
{
return x.ant<y.ant;
}
int main()
{
int n;
while(~scanf("%d",&n))
{
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i].ant);
a[i].num=i;
}
sort(a+1,a+n+1,cmp);
for(int i=1;i<=(n/2);i++)
printf("%d %d\n",a[i].num,a[n+1-i].num);
}
return 0;
}
相关文章推荐
- 【CodeForces】701A - Cards(暴力 || 思维)
- Cards(Codeforces 701A)(Codeforces Round #364Div.2 A)
- Codeforces 387E George and Cards【思维+RMQ+二分+树状数组】被卡常= =
- CodeForces - 916B(思维+位运算)
- Codeforces 842C(思维)
- Codeforces 915 C Permute Digits (思维)解题报告
- CodeForces 66A - Petya and Java(思维)
- codeforces 754A(思维题)
- Codeforces 381C Sereja and Brackets【二分+思维】好题~
- CodeForces - 672D Robin Hood (思维二分)
- Codeforces 349 B Color the Fence (思维+贪心)
- CodeForces - 822C Hacker, pack your bags!(区间端点处理技巧+思维)
- 【CodeForces】348A - Mafia(二分 & 思维)
- Codeforces 160C Find Pair【思维+排序】
- Codeforces 631B Print Check 【思维】
- CodeForces 258A Vanya and Cards
- CodeForces 360A - Levko and Array Recovery (思维)
- Codeforces 490D Chocolate【思维+暴搜】
- codeforces-755【C思维、并查集】
- Codeforces 544D Destroying Roads【思维枚举+最短路】好题~好题!