Codeforces Round #320 (Div. 2) 579B Finding Team Member
2015-09-24 18:35
197 查看
There is a programing contest named SnakeUp, 2n people want to compete for it. In order to attend this contest, people need to form teams of exactly two people. You are given the strength of each possible combination
of two people. All the values of the strengths are
distinct.
Every contestant hopes that he can find a teammate so that their team’s strength is as high as possible. That is, a contestant will form a team with highest strength possible by choosing a teammate from ones who are willing to be a teammate with him/her.
More formally, two people A and
B may form a team if each of them is the best possible teammate (among the contestants that remain unpaired) for the other one.
Can you determine who will be each person’s teammate?
介个题目一开始就是说 有2n个人选队友,给出了下三角矩阵来表示每两个人之间的分数。
然后题目又说每个人都要选当前可选择的人里面和自己合作分数最高的
浴室胡,就是看如何去找最大分数的一对了。
如果每一次都遍历矩阵去找最大的,那莫对稍微大一点的n都是妥妥的超时的。但是这个题目一就是不用多次便利的,其实一次都不用。
窝把记录的下三角矩阵 记成有i到j的一条无向有权值的边,这个题目就成了找当前可以选择的最大边了#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
struct Team{
int u,v,c;
};
bool operator < (const Team &a, const Team &b ) {
return a.c > b.c;
}
Team p[1000000];
int vis[1000];
int n;
int main()
{
scanf("%d",&n);
for(int i = 1; i <= 2*n; i++) vis[i] = 0;
int cnt = 1;
for(int i = 2; i <= 2*n; i++)
{
for(int j = 1; j < i; j++)
{
p[cnt].u = i;
p[cnt].v = j;
scanf("%d",&p[cnt++].c);
}
}
sort(p+1,p+cnt+1);
for(int i = 1; i <= cnt; i++){
if(!vis[p[i].u]&&!vis[p[i].v])
{
vis[p[i].u] = p[i].v;
vis[p[i].v] = p[i].u;
}
}
for(int i = 1; i < 2*n; i++)
{
printf("%d ",vis[i]);
}
printf("%d\n",vis[2*n]);
return 0;
}
of two people. All the values of the strengths are
distinct.
Every contestant hopes that he can find a teammate so that their team’s strength is as high as possible. That is, a contestant will form a team with highest strength possible by choosing a teammate from ones who are willing to be a teammate with him/her.
More formally, two people A and
B may form a team if each of them is the best possible teammate (among the contestants that remain unpaired) for the other one.
Can you determine who will be each person’s teammate?
介个题目一开始就是说 有2n个人选队友,给出了下三角矩阵来表示每两个人之间的分数。
然后题目又说每个人都要选当前可选择的人里面和自己合作分数最高的
浴室胡,就是看如何去找最大分数的一对了。
如果每一次都遍历矩阵去找最大的,那莫对稍微大一点的n都是妥妥的超时的。但是这个题目一就是不用多次便利的,其实一次都不用。
窝把记录的下三角矩阵 记成有i到j的一条无向有权值的边,这个题目就成了找当前可以选择的最大边了#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
struct Team{
int u,v,c;
};
bool operator < (const Team &a, const Team &b ) {
return a.c > b.c;
}
Team p[1000000];
int vis[1000];
int n;
int main()
{
scanf("%d",&n);
for(int i = 1; i <= 2*n; i++) vis[i] = 0;
int cnt = 1;
for(int i = 2; i <= 2*n; i++)
{
for(int j = 1; j < i; j++)
{
p[cnt].u = i;
p[cnt].v = j;
scanf("%d",&p[cnt++].c);
}
}
sort(p+1,p+cnt+1);
for(int i = 1; i <= cnt; i++){
if(!vis[p[i].u]&&!vis[p[i].v])
{
vis[p[i].u] = p[i].v;
vis[p[i].v] = p[i].u;
}
}
for(int i = 1; i < 2*n; i++)
{
printf("%d ",vis[i]);
}
printf("%d\n",vis[2*n]);
return 0;
}
相关文章推荐
- Git Tips
- C++转换
- 二叉树三种序列的两种转化
- android中getSystemService详解
- 我也开始写博客了
- Light Pre-Pass 渲染器----为多光源设计一个渲染器
- 内存缓存LruCache实现原理
- 滚动加载数据
- spring mvc
- Android开发艺术探索读书笔记(一)
- OpenCV3.0基本类型初探(一)
- 个人博客作业Week2
- ORGANISING THE TEST CASES
- Unity游戏编程定制编辑器(一)
- [Q]图框识别问题
- location.hash来保持页面状态
- 使用Python获取绝对路径下的文件
- 杨辉三角
- RM文件的格式
- hdu 5452 Minimum Cut (LCA)