BZOJ 3943: [Usaco2015 Feb]SuperBull 最小生成树
Description
Input
Output
任意两个队伍只会比一次比赛,可以将比赛的赛程想成是一个树.
跑一遍最大生成树即可.
#include<bits/stdc++.h>
#define setIO(s) freopen(s".in","r",stdin)
#define maxn 4100000
#define ll long long
using namespace std;
int u[maxn],v[maxn],p[3000],A[maxn];
ll arr[3000],val[maxn];
int n,edges;
int find(int x)
{
return p[x]==x?x:p[x]=find(p[x]);
}
bool merge(int a,int b)
{
int x=find(a),y=find(b);
if(x==y) return false;
p[x]=y;
return true;
}
bool cmp(const int i,const int j)
{
return val[i]>val[j];
}
int main()
{
// setIO("input");
scanf("%d",&n);
for(int i=0;i<3000;++i) p[i]=i;
for(int i=1;i<=n;++i) scanf("%lld",&arr[i]);
for(int i=1;i<=n;++i)
for(int j=1;j<=n;++j)
{
if(i==j) continue;
A[++edges]=edges, u[edges]=i,v[edges]=j, val[edges]=arr[i]^arr[j];
}
sort(A+1,A+1+edges,cmp);
ll sum=0;
int cc=0;
for(int i=1;i<=edges;++i)
{
int e=A[i];
int a=u[e],b=v[e];
if(merge(a,b)) sum+=val[e],++cc;
if(cc==n-1) break;
}
printf("%lld\n",sum);
return 0;
}
BZOJ 3943: [Usaco2015 Feb]SuperBull 最小生成树的更多相关文章
- BZOJ 3943 [Usaco2015 Feb]SuperBull:最大生成树
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3943 题意: 有n只队伍,每个队伍有一个编号a[i]. 每场比赛有两支队伍参加,然后选一支 ...
- 【BZOJ3943】[Usaco2015 Feb]SuperBull 最小生成树
[BZOJ3943][Usaco2015 Feb]SuperBull Description Bessie and her friends are playing hoofball in the an ...
- 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 ...
- BZOJ 3940: [Usaco2015 Feb]Censoring
3940: [Usaco2015 Feb]Censoring Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 367 Solved: 173[Subm ...
- bzoj 3940: [Usaco2015 Feb]Censoring -- AC自动机
3940: [Usaco2015 Feb]Censoring Time Limit: 10 Sec Memory Limit: 128 MB Description Farmer John has ...
- Bzoj 3942: [Usaco2015 Feb]Censoring(kmp)
3942: [Usaco2015 Feb]Censoring Description Farmer John has purchased a subscription to Good Hooveske ...
- [BZOJ 3942] [Usaco2015 Feb] Censoring 【KMP】
题目链接:BZOJ - 3942 题目分析 我们发现,删掉一段 T 之后,被删除的部分前面的一段可能和后面的一段连接起来出现新的 T . 所以我们删掉一段 T 之后应该接着被删除的位置之前的继续向后匹 ...
- 【bzoj3943】[Usaco2015 Feb]SuperBull
题目描述 Bessie and her friends are playing hoofball in the annual Superbull championship, and Farmer Jo ...
随机推荐
- Java多线程之如何确定线程数
关于多线程的线程数的确定,最近研读过几篇paper,在此做一下笔记,方便使用时翻看. 1.<Java 虚拟机并发编程>中介绍 就是说:线程数 = CPU的核心数 * (1 - 阻塞系数) ...
- mysql实例的连接数max_user_connections 和max_connections 配置的那些事
今天在查线上问题时,通过phpMyAdmin来进行DML操作,发现比平时慢多了,就各种进原因. 项目的场景是一个mysql实例中创建了多个数据库,猜想可能是相互影响所致. 然后,查询线上Mysql数据 ...
- 开源GIS软件 3
OpenWLANMap 与 OpenStreetMap 项目类似,OpenWLANMap 将变成一个开源的替代产品,提供 WLANs 的数据库.定位信息等. 开源排水管网GIS系统 udpnGIS 邢 ...
- 【JavaScript】正則表達式
正則表達式,也不是第一次与它见面了.在我们学习ASP.NET视频的时候,验证控件的那个实例中.就有提到过它. 那个时候.都是在控件的属性中自己设置的,用的原理就是正則表達式,当时得感觉就是方便,强大, ...
- pytest 失败用例重试
https://www.cnblogs.com/jinzhuduoduo/articles/7017405.html http://www.lxway.com/445949491.htm https: ...
- ASP环境下轻松实现报表的打印 (转)
作者:zcg2000 一.前言 ASP在电子商务上应用广泛,报表的处理又有一些麻烦.本文介绍了在ASP中利用 本人写的Report Server Page脚本解释器实现报表的显示.打印. 二.准备工作 ...
- log4net preserveLogFileNameExtension 和 watch
preserveLogFileNameExtension <log4net> <appender name="fileappender" type="l ...
- 格伦布编码——rice编码无非是golomb编码M为2^x的特例
格伦布编码 格伦布编码是一种无失真资料压缩方法,由数学家所罗门·格伦布在1960年代提出. Rice编码 Robert F. Rice提出Rice 编码,是以哥伦布编码为基础做改良而更简易的前置码.R ...
- Codeforces--626B--Cards(模拟)
Cards Time Limit: 2000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit Sta ...
- vue.js的第一个程序
Vue.js是一个轻巧.高性能.可组件化的MVVM库,同时拥有非常容易上手的API. 1.安装 下载 git clone https://github.com/vuejs/vue.git 页面中直接引 ...