【bzoj3943】[Usaco2015 Feb]SuperBull
题目描述
输入
输出
样例输入
4
3
6
9
10
样例输出
37
题解
由于n只有2000,可以建图然后最大生成树。
有趣的是kruskal都能过
#include <cstdio>
#include <algorithm>
using namespace std;
struct data
{
int x , y , z;
}e[4000001];
int num[2001] , cnt , f[2001];
bool cmp(data a , data b)
{
return a.z > b.z;
}
int find(int x)
{
return x == f[x] ? x : f[x] = find(f[x]);
}
int main()
{
int n , i , j , k = 0;
long long ans = 0;
scanf("%d" , &n);
for(i = 0 ; i < n ; i ++ )
scanf("%d" , &num[i]);
for(i = 0 ; i < n ; i ++ )
{
f[i] = i;
for(j = 0 ; j < n ; j ++ )
{
e[cnt].x = i;
e[cnt].y = j;
e[cnt].z = num[i] ^ num[j];
cnt ++ ;
}
}
sort(e , e + cnt , cmp);
for(i = 0 ; i < cnt && k < n - 1 ; i ++ )
{
int tx = find(e[i].x) , ty = find(e[i].y);
if(tx != ty)
{
k ++ ;
ans += (long long)e[i].z;
f[tx] = ty;
}
}
printf("%lld\n" , ans);
return 0;
}
【bzoj3943】[Usaco2015 Feb]SuperBull的更多相关文章
- 【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 ...
- 【BZOJ3939】[Usaco2015 Feb]Cow Hopscotch 动态规划+线段树
[BZOJ3939][Usaco2015 Feb]Cow Hopscotch Description Just like humans enjoy playing the game of Hopsco ...
- 【BZOJ3940】[USACO2015 Feb] Censoring (AC自动机的小应用)
点此看题面 大致题意: 给你一个文本串和\(N\)个模式串,要你将每一个模式串从文本串中删去.(此题是[BZOJ3942][Usaco2015 Feb]Censoring的升级版) \(AC\)自动机 ...
- 【bzoj3940】[Usaco2015 Feb]Censoring
[题目描述] FJ把杂志上所有的文章摘抄了下来并把它变成了一个长度不超过10^5的字符串S.他有一个包含n个单词的列表,列表里的n个单词 记为t_1...t_N.他希望从S中删除这些单词. FJ每次 ...
- 【bzoj3942】[Usaco2015 Feb]Censoring
[题目大意] 有一个S串和一个T串,长度均小于1,000,000,设当前串为U串,然后从前往后枚举S串一个字符一个字符往U串里添加,若U串后缀为T,则去掉这个后缀继续流程. [样例输入] whatth ...
- 【bzoj3940】[Usaco2015 Feb]Censoring AC自动机
题目描述 Farmer John has purchased a subscription to Good Hooveskeeping magazine for his cows, so they h ...
- 【bzoj3939】[Usaco2015 Feb]Cow Hopscotch 动态开点线段树优化dp
题目描述 Just like humans enjoy playing the game of Hopscotch, Farmer John's cows have invented a varian ...
随机推荐
- ASP.NET 实现上一篇文章 下一篇文章
select top 1 * from job_hrnews where newsid>162 --下一篇 select top 1 * from job_hrnews where newsi ...
- Android开发手记(23) Notification
有时候,我们需要应用程序在状态内显示一些通知信息,这时我们就需要使用Notification来完成这一工作.也许我们会想到以前经常使用的Toast来通知用户.虽然Notification与Toast都 ...
- iOS8中添加的extensions总结(一)——今日扩展
通知栏中的今日扩展 分享扩展 Action扩展 图片编辑扩展 文件管理扩展 第三方键盘扩展 注:此教程来源于http://www.raywenderlich.com的<iOS8 by Tutor ...
- Linux 0.11下信号量的实现和应用
Linux 011下信号量的实现和应用 生产者-消费者问题 实现信号量 信号量的代码实现 关于sem_wait和sem_post sem_wait和sem_post函数的代码实现 信号量的完整代码 实 ...
- 打包静默安装参数(nsis,msi,InstallShield,InnoSetup)[转]
有时我们在安装程序的时候,希望是静默安装的,不显示下一步下一步,这编访问来教大家如何来操作,现在常用的制作安装程序的软件有, Microsoft Windows Installer , Windo ...
- Zend Cache的学习和实例
前一段时间,公司让我组织一下关于Zend Cache的培训. 培训的具体内容有: 前端core缓存 前端Output缓存 前端Function缓存 前端Class缓存 前端File缓存 前端Page缓 ...
- mobox:推进企业文档管理走向信息化之路
随着“大数据”时代的到来,越来越多的人们对数据库管理信息抱有认可态度,这是近年来信息化发展的必然结果.企业作为推进社会经济发展的主力军,也必然要紧跟大数据时代潮流,利用计算机技术全面普及企业的信息化管 ...
- SCALA常规练习C
package com.hengheng.scala abstract class Animal { def walk(speed : Int) def breathe() = { println(& ...
- static用法一
#include "stdafx.h" #include "string.h" struct student { int num; ]; char sex; } ...
- Children of the Candy Corn (bfs+dfs)
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8120 Accepted: 3547 Description The c ...