[bzoj3943][Usaco2015 Feb]SuperBull_Kruskal
SuperBull bzoj-3943 Usaco-2015 Feb
题目大意:贝西和她的朋友们在参加一年一度的“犇”(足)球锦标赛。FJ的任务是让这场锦标赛尽可能地好看。一共有N支球队参加这场比赛,每支球队都有一个特有的取值在1-230-1之间的整数编号(即:所有球队编号各不相同)。“犇”锦标赛是一个淘汰赛制的比赛——每场比赛过后,FJ选择一支球队淘汰,淘汰了的球队将不能再参加比赛。锦标赛在只有一支球队留下的时候就结束了。FJ发现了一个神奇的规律:在任意一场比赛中,这场比赛的得分是参加比赛两队的编号的异或(Xor)值。例如:编号为12的队伍和编号为20的队伍之间的比赛的得分是24分,因为 12(01100) Xor 20(10100) = 24(11000)。FJ相信比赛的得分越高,比赛就越好看,因此,他希望安排一个比赛顺序,使得所有比赛的得分和最高。请帮助FJ决定比赛的顺序
注释:$1\le N \le 2,000$。
想法:显然,最后的情况一定是一棵树。反证法:假设最后情况不是一棵树。那么一定存在这样的一条边,开始的时候是一个森林,这条边在一棵树内,使得形成环。因为每一次比赛就会淘汰一个人,k-1场比赛淘汰k-1个人,所以这棵树上只有一个点,又因为每个人不能有自环,矛盾。
所以,最后的情况一定是一棵树。
这样的话我们用两个点的点权异或值在表示这两点之间的边权,然后跑kruskal即可。
最后,附上丑陋的代码... ...
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 2010
using namespace std;
typedef long long ll;
struct Node
{
int a,b,val;
}f[N*N];
int fa[N],a[N];
inline bool cmp(const Node &a,const Node &b)
{
return a.val>b.val;
}
int find(int x)
{
return fa[x]==x?x:(fa[x]=find(fa[x]));
}
inline bool merge(int x,int y)
{
x=find(x); y=find(y);
if(x==y) return true;
fa[x]=y; return false;
}
int main()
{
int n; cin >> n ;
for(int i=1;i<=n;i++) fa[i]=i;
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
int cnt=0;
for(int i=1;i<=n;i++)
{
for(int j=i+1;j<=n;j++)
{
f[++cnt].a=i; f[cnt].b=j;
f[cnt].val=a[i]^a[j];
}
}
sort(f+1,f+cnt+1,cmp);
// for(int i=1;i<=cnt;i++)
// {
// printf("Fuck %d %d %d\n",f[i].a,f[i].b,f[i].val);
// }
int count=0;
ll ans=0;
for(int i=1;i<=cnt;i++)
{
if(!merge(f[i].a,f[i].b))
{
count++;
ans+=f[i].val;
// printf("Bitch %d\n",i);
}
if(count==n-1) break;
}
printf("%lld\n",ans);
return 0;
}
小结:有意思...
[bzoj3943][Usaco2015 Feb]SuperBull_Kruskal的更多相关文章
- Bzoj3943 [Usaco2015 Feb]SuperBull
3943: [Usaco2015 Feb]SuperBull Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 300 Solved: 185 Desc ...
- 【BZOJ3943】[Usaco2015 Feb]SuperBull 最小生成树
[BZOJ3943][Usaco2015 Feb]SuperBull Description Bessie and her friends are playing hoofball in the an ...
- 【BZOJ3943】[Usaco2015 Feb]SuperBull 最大生成树
[BZOJ3943][Usaco2015 Feb]SuperBull Description Bessie and her friends are playing hoofball in the an ...
- 【BZOJ3940】【BZOJ3942】[Usaco2015 Feb]Censoring AC自动机/KMP/hash+栈
[BZOJ3942][Usaco2015 Feb]Censoring Description Farmer John has purchased a subscription to Good Hoov ...
- 3942: [Usaco2015 Feb]Censoring [KMP]
3942: [Usaco2015 Feb]Censoring Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 375 Solved: 206[Subm ...
- bzoj3940: [Usaco2015 Feb]Censoring
AC自动机.为什么洛谷水题赛会出现这种题然而并不会那么题意就不说啦 .终于会写AC自动机判断是否是子串啦...用到kmp的就可以用AC自动机水过去啦 #include<cstdio> #i ...
- BZOJ_3940_[Usaco2015 Feb]Censoring_AC自动机
BZOJ_3940_[Usaco2015 Feb]Censoring_AC自动机 Description FJ把杂志上所有的文章摘抄了下来并把它变成了一个长度不超过10^5的字符串S.他有一个包含n个 ...
- BZOJ_3942_[Usaco2015 Feb]Censoring_KMP
BZOJ_3942_[Usaco2015 Feb]Censoring_KMP Description 有一个S串和一个T串,长度均小于1,000,000,设当前串为U串,然后从前往后枚举S串一个字符一 ...
- 3942: [Usaco2015 Feb]Censoring
3942: [Usaco2015 Feb]Censoring Time Limit: 10 Sec Memory Limit: 128 MB Submit: 964 Solved: 480 [Subm ...
随机推荐
- This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery
This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'的意思是,这版本的 MySQL 不支持使 ...
- HDU3533 Escape
题目: The students of the HEU are maneuvering for their military training. The red army and the blue a ...
- Redis(二)-Win系统下安装
下载地址:https://github.com/MSOpenTech/redis/releases. Redis 支持 32 位和 64 位.这个需要根据你系统平台的实际情况选择,这里我们下载 Red ...
- POJ 1101 译文
The Game 题意: Description One morning, you wake up and think: "I am such a good programmer. Why ...
- GS运维常用工具及文档
规范部分 GS产品线性能问题处理流程:http://gsk.inspur.com/File/t-4244 XXX项目性能问题信息收集单-模板:http://gsk.inspur.com/File/ ...
- 大白话理解箭头函数this
var obj1={ num:4, fn:function(){ num:5; var f=() => { num:6; console.log(this.num); //4 外层非箭头函数包裹 ...
- VMWare linux安装mysql 5.7.13
1.基础环境说明 虚拟机:VMWare 操作系统:linux 数据库版本:mysql 5.7.13 社区版(别问为什么不装企业版,因为企业版要钱) 背景:虚拟机可以连上外网 下载目录: /tools/ ...
- Assembly之example
Here is a simple example by assembly language. It is based on openMSP430. Very important is to under ...
- Embedded之Stack之三
Stack Overflow While stacks are generally large, they don't occupy all of memory. It is possible to ...
- Maya API编程快速入门
一.Maya API编程简介 Autodesk® Maya® is an open product. This means that anyone outside of Autodesk can ch ...