Cards(Codeforces 701A)(Codeforces Round #364Div.2 A)
2016-07-23 03:22
1581 查看
701A
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.
这题还算简单,自己成功A掉。
AC代码如下:
附上大牛的代码:(思路是排序)
#include<bits/stdc++.h>
using namespace std;
struct p{
int i,v;
};
int com(p a,p b){
return a.v<b.v;
}
int main(){
int n;
cin>>n;
p a
;
for(int i=0;i<n;i++)
{ cin>>a[i].v;
a[i].i=i+1;
}
sort(a,a+n,com);
for(int i=0;i<n/2;i++){
cout<<a[i].i<<' '<<a[n-1-i].i<<'\n';
}
}
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.
这题还算简单,自己成功A掉。
AC代码如下:
#include<iostream> #include<cstdio> #include<cstring> using namespace std; int a[105]; int visited[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]; } memset(visited,0,sizeof(visited)); int res=sum*2/n; for(int i=1;i<=n;i++){ for(int j=1;j<=n&&j!=i;j++){ if(a[i]+a[j]==res&&!visited[i]&&!visited[j]){ printf("%d %d\n",i,j); visited[i]=1; visited[j]=1; } } } return 0; }
附上大牛的代码:(思路是排序)
#include<bits/stdc++.h>
using namespace std;
struct p{
int i,v;
};
int com(p a,p b){
return a.v<b.v;
}
int main(){
int n;
cin>>n;
p a
;
for(int i=0;i<n;i++)
{ cin>>a[i].v;
a[i].i=i+1;
}
sort(a,a+n,com);
for(int i=0;i<n/2;i++){
cout<<a[i].i<<' '<<a[n-1-i].i<<'\n';
}
}
相关文章推荐
- Codeforces Round #197 (Div. 2)
- Codeforces Round #198 (Div. 1)
- Codeforces 405E Codeforces Round #238 (Div. 2)E
- Codeforces 407C Codeforces Round #239 (Div. 1)C
- CodeForces 449A - Jzzhu and Chocolate
- CodeForces 449 B. Jzzhu and Cities
- codeforces 618C. Constellation
- Codeforces Round #349 (Div. 2) - C
- Codeforces Round #361 (Div. 2)
- 7.13Codeforces Round #360 (Div. 2)
- Codeforces Round #363 (Div. 2)
- Codeforces Round #265 (Div. 2)
- Codeforces #310 div2 C. Case of Matryoshkas
- 状态压缩DP codeforces 244 Problem C. The Brand New Function 和 codeforces 165 E. Compatible Numbers
- codeforces 16 Problem E fish
- Codeforces Round332 部分题解
- CodeForces 603A_Alternative Thinking (DP)
- CodeForces 602B_Approximating a Constant Range_DP
- Codeforces round #247 for Div. 2
- Codeforces Round #246 (Div. 2)