题目链接:
http://acm.hust.edu.cn/vjudge/contest/126546#problem/D
Description
This year at Monsters University it is decided to arrange Scare Games. At the Games all campus gathers
at the stadium stands, and the Scare program students divide into two teams to compete in their abilities
of scaring children. This year the two teams will be “Oozma Kappa” and “Roar Omega Roar”.
Each team has ? monsters, and the Games consist of ? challenges. During each challenge Dean
Hardscrabble, the chair of the Scare program, invites one monster from each team to demonstrate his
mastery. Each of the monsters is invited only once and scores from 0 to 6 points, depending on how much
a child is scared. The results of each challenge are announced at the same time for both monsters right
after the end of this challenge. The winning team will be identified by the sum of the points scored by all
its members.
Sports competition is an unpredictable process. But the Dean wants to keep all the course of the Games
under control, so that the identity of the winning team will have been unclear for the audience as long as
possible. For example, if six challenges until the end “Oozma Kappa” is forty points ahead, the audience at
the stadium stands will just lose interest to the game. The Dean knows the skill level of all her students,
and she wants to decide beforehand the order in which both teams’ members will be participating in
the challenges. In what order should monsters from “Oozma Kappa” and from “Roar Omega Roar” show
up to keep the audience in suspense as long as possible?
Input
The first line contains an integer ? (2 ≤ ? ≤ 1 000). The second line contains ? integers within the range
from 0 to 6, which are the points monsters from “Oozma Kappa” will score. The third line contains
the points, monsters from “Roar Omega Roar” will score, written in the same manner.
Output
Output ? lines, each containing integers ?? and ??
, which are the numbers of monsters from “Oozma
Kappa” and “Roar Omega Roar” respectively, who should be called by the Dean to take part in the ?-th
challenge. In each team monsters are numbered with integers from 1 to ? in the order they appear in
the input data. If the problem has several solutions, output any of them.
Examples
5
0 1 4 3 6
6 5 1 3 0
5 1
1 5
4 4
2 3
3 2
题意:
两队参加比赛,各有n个成员,得分在0-6之间.
每次各选出一位成员PK,每个成员只能出战一次. 最后得分多者获胜.
最后的结果虽已确定,现在要尽量使得观众猜不出最后是谁赢:
即如果还有i场比赛,那么现在的分差最好要小于6*i. (否者此时胜局已定).
求两队队员的各自的出场顺序.
题解:
贪心的思路.
由于最后的胜局是可以确定的.
那么随着比赛的进行,胜局肯定是逐渐奠定的.
那么现在要做的是要使得胜局奠定越晚越好.
所以贪心的想法是一开始尽量让败者多得分.
所以胜者先出小的,败者先出大的为最优策略.
(可以反证.)
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#define LL long long
#define eps 1e-8
#define maxn 1100
#define mod 100000007
#define inf 0x3f3f3f3f
#define IN freopen("in.txt","r",stdin);
using namespace std;
int n;
struct node{
int score;
int id;
bool operator < (const node& b) const {
return score < b.score;
}
};
node a[maxn];
node b[maxn];
int main(int argc, char const *argv[])
{
//IN;
while(scanf("%d", &n) != EOF)
{
int s1 = 0, s2 = 0;
for(int i=1; i<=n; i++) {
scanf("%d", &a[i].score);
a[i].id = i;
s1 += a[i].score;
}
for(int i=1; i<=n; i++) {
scanf("%d", &b[i].score);
b[i].id = i;
s2 += b[i].score;
}
sort(a+1, a+1+n);
sort(b+1, b+1+n);
if(s1 < s2) reverse(a+1, a+1+n);
else reverse(b+1, b+1+n);
for(int i=1; i<=n; i++)
printf("%d %d\n", a[i].id, b[i].id);
}
return 0;
}