HDU 4786 Fibonacci Tree (2013成都1006题) 最小生成树+斐波那契
题意:问生成树里能不能有符合菲波那切数的白边数量
思路:白边 黑边各优先排序求最小生成树,并统计白边在两种情况下数目,最后判断这个区间就可以。注意最初不连通就不行。
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include<cmath>
#define LL long long
using namespace std;
int t,n,m;
int tot;
int F[];
struct node {
int u,v,c;
} edge[];
int f[];
void init() {
f[]=;
f[]=;
tot=;
while(f[tot]<=) {
f[tot+]=f[tot]+f[tot-];
tot++;
}
} int findd(int x) {
if(F[x]==-) return x;
else return F[x]=findd(F[x]);
}
bool cmp1(node a,node b) {
return a.c<b.c;
}
bool cmp2(node a,node b) {
return a.c>b.c;
}
int main() {
scanf("%d",&t);
int cas=;
init();
while(t--) {
scanf("%d%d",&n,&m);
cas++;
for(int i=; i<m; i++) {
scanf("%d%d%d",&edge[i].u,&edge[i].v,&edge[i].c);
}
sort(edge,edge+m,cmp1);
memset(F,-,sizeof(F));
int cnt=;
for(int i=; i<m; i++) {
int x=findd(edge[i].u);
int y=findd(edge[i].v);
if(x!=y) {
F[x]=y;
if(edge[i].c==)
cnt++;
}
}
int low=cnt;
cnt=;
memset(F,-,sizeof(F));
sort(edge,edge+m,cmp2);
for(int i=; i<m; i++) {
int x=findd(edge[i].u);
int y=findd(edge[i].v);
if(x!=y) {
F[x]=y;
if(edge[i].c==)
cnt++;
}
}
int high=cnt;
int flag=;
for(int i=; i<=n; i++) {
if(findd()!=findd(i)) {
flag=;
break;
}
}
if(flag) {
printf("Case #%d: No\n",cas);
continue;
}
flag = false;
for(int i = ; i <= tot; i++)
if(f[i] >= low && f[i] <= high)
flag = true;
if(flag)
printf("Case #%d: Yes\n",cas);
else printf("Case #%d: No\n",cas); }
return ;
}
HDU 4786 Fibonacci Tree (2013成都1006题) 最小生成树+斐波那契的更多相关文章
- hdu 4786 Fibonacci Tree (2013ACMICPC 成都站 F)
http://acm.hdu.edu.cn/showproblem.php?pid=4786 Fibonacci Tree Time Limit: 4000/2000 MS (Java/Others) ...
- HDU 3117 Fibonacci Numbers(围绕四个租赁斐波那契,通过计++乘坐高速动力矩阵)
HDU 3117 Fibonacci Numbers(斐波那契前后四位,打表+取对+矩阵高速幂) ACM 题目地址:HDU 3117 Fibonacci Numbers 题意: 求第n个斐波那契数的 ...
- hdu 2044:一只小蜜蜂...(水题,斐波那契数列)
一只小蜜蜂... Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepte ...
- hdu 4786 Fibonacci Tree 乱搞 智商题目 最小生成树
首先计算图的联通情况,如果图本身不联通一定不会出现生成树,输出"NO",之后清空,加白边,看最多能加多少条,清空,加黑边,看能加多少条,即可得白边的最大值与最小值,之后判断Fibo ...
- HDU 4786 Fibonacci Tree (2013成都1006题)
Fibonacci Tree Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- HDU 4786 Fibonacci Tree(生成树,YY乱搞)
http://acm.hdu.edu.cn/showproblem.php? pid=4786 Fibonacci Tree Time Limit: 4000/2000 MS (Java/Others ...
- hdu 4786 Fibonacci Tree(最小生成树)
Fibonacci Tree Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- HDU 4786 Fibonacci Tree 生成树
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4786 题意:有N个节点(1 <= N <= 10^5),M条边(0 <= M <= ...
- Project Euler 104:Pandigital Fibonacci ends 两端为全数字的斐波那契数
Pandigital Fibonacci ends The Fibonacci sequence is defined by the recurrence relation: F[n] = F[n-1 ...
- 《剑指offer》第十题(斐波那契数列)
// 面试题:斐波那契数列 // 题目:写一个函数,输入n,求斐波那契(Fibonacci)数列的第n项. #include <iostream> using namespace std; ...
随机推荐
- 九度OJ 1202 排序 -- 堆排序
题目地址:http://ac.jobdu.com/problem.php?pid=1202 题目描述: 对输入的n个数进行排序并输出. 输入: 输入的第一行包括一个整数n(1<=n<=10 ...
- IOS 学习日志 2015-3-17
Objective--C 一 关键字 @class 导入已有的类 id 对象类型 表示任何一个ObjC对象类型 Block 对象类型 OC中称为代码块 类似于C中的函数式指针 typedef 定义数据 ...
- 管理员把我的admin权限去掉了,那么如何获得jdk zip安装呢?这篇可以帮你。
JDK is not available as a portable zip unfortunately. However, you can: Create working JDK directory ...
- 服务器卡死,重启报错: INFO: task blocked for more than 120 seconds
问题:服务器负载很高,但是CPU利用率不高.服务器经常夯住,网站打不开,SSH连接非常不稳定,输入命令夯住. 重启服务器报错: INFO: task blocked for more than 120 ...
- 【实习记】2014-09-04浏览代码查middle资料+总结我折腾过的源码浏览器
浏览着代码,看源码可以先看make文件,make文件有制造的流程信息. 一般可以从运行的程序对应的cpp看起.然而如果有框架,那就不容易了,会关系错纵复杂. 总结一下我折腾过的源码阅读器. s ...
- shell中的双引号,单引号,反引号
在shell中引号分为三种:单引号,双引号和反引号. 单引号 ‘ 由单引号括起来的字符都作为普通字符出现.特殊字符用单引号括起来以后,也会失去原有意义,而只作为普通字符解释.单引号用于保持引号内所有字 ...
- centos 交换分区
内容来自:http://www.huzs.net/?p=1683 一般在桌面型的用不到,因为现在内存都比较大,服务器就不一样了,但是建议无论是在桌面还是服务器上,都设置 swap 以下操作都是在 ro ...
- Sumbline编译Less
Less教程 Sublime Text 2的Less2Css插件介绍与安装 网址 http://fdream.net/blog/article/783.aspx 如果出现node.exe不是内部命令的 ...
- KeepAlive详解
KeepAlive既熟悉又陌生,踩过坑的同学都知道痛.一线运维工程师踩坑之后对于KeepAlive的总结,你不应该错过! 最近工作中遇到一个问题,想把它记录下来,场景是这样的: 从上图可以看出,用户通 ...
- 关于回波损耗 和 驻波比的摘要 Return Loss and VSWR
关于回波损耗 和 驻波比的摘要 以下摘自:http://www.soontai.com/cal_rtvswr.html RL = 20log((VSWR+1) / (VSWR-1)) VSWR = ( ...