hdu 4786 Fibonacci Tree 乱搞 智商题目 最小生成树
首先计算图的联通情况,如果图本身不联通一定不会出现生成树,输出"NO",之后清空,加白边,看最多能加多少条,清空,加黑边,看能加多少条,即可得白边的最大值与最小值,之后判断Fibonacci数是否在这两个之间,如果是输出yes,否则no。
然而,,然而,,我看的题解有问题!!!!!调了俩小时愣是没找出错误来,,然后把题解交了发现过不了,,,,真是够了。,。,。,
第二天上午终于A了,,满分程序:
#include <cstdio>
#include <cstring>
#include <algorithm> struct data {
int x1;
int y1;
int z1;
};
const int maxn = + ;
int father[maxn];
int f[maxn];
data p[maxn];
int T;
int n, m; bool cmp(data aa, data bb) {
return (aa.z1 < bb.z1);
} int getfather(int x) {
if (father[x] == x) return x;
return (father[x] = getfather(father[x]));
} bool solve (void) {
int cur = n;
for (int i = ; i <= m; i++) {
int tx = getfather(p[i].x1);
int ty = getfather(p[i].y1);
if (tx != ty) {
father[tx] = ty;
cur--;
}
}
if (cur > ) return ;
return ;
} int main () {
f[] = ;
f[] = ;
for (int i = ; i <= ; i++) {
f[i] = f[i-] + f[i-];
}
scanf("%d", &T);
for (int kase = ; kase <= T; kase++) {
printf("Case #%d: ", kase);
scanf("%d %d", &n, &m);
for (int i = ; i <= n; i++) father[i] = i;
for (int i = ; i <= m; i++) scanf("%d %d %d", &p[i].x1, &p[i].y1, &p[i].z1);
std :: sort(p + , p + m + , cmp);
if (solve()) printf("No\n");
else {
for (int i = ; i <= n; i++) father[i] = i;
int smin = ;
for (int i = ; i <= m; i++) {
int tx = getfather(p[i].x1);
int ty = getfather(p[i].y1);
if (tx != ty) {
father[tx] = ty;
if (p[i].z1 == ) smin++;
}
}
int smax = ;
for (int i = ; i <= n; i++) father[i] = i;
for (int i = m; i >= ; i--) {
int tx = getfather(p[i].x1);
int ty = getfather(p[i].y1);
if (tx != ty) {
father[tx] = ty;
if (p[i].z1 == ) smax++;
}
}
bool flag = ;
for (int i = ; i <= ; i++)
if (smin <= f[i] && smax >= f[i]) {
flag = ;
break;
}
if (flag) printf("Yes\n");
else printf("No\n");
}
}
return ;
}
hdu 4786 Fibonacci Tree 乱搞 智商题目 最小生成树的更多相关文章
- 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 (2013ACMICPC 成都站 F)
http://acm.hdu.edu.cn/showproblem.php?pid=4786 Fibonacci Tree Time Limit: 4000/2000 MS (Java/Others) ...
- HDU 4786 Fibonacci Tree 最小生成树
Fibonacci Tree 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=4786 Description Coach Pang is intere ...
- HDU 4786 Fibonacci Tree
Fibonacci Tree Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) P ...
- 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(最小生成树)
Fibonacci Tree Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- hdoj 4786 Fibonacci Tree【并查集+最小生成树(kruskal算法)】
Fibonacci Tree Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- 【HDU 4786 Fibonacci Tree】最小生成树
一个由n个顶点m条边(可能有重边)构成的无向图(可能不连通),每条边的权值不是0就是1. 给出n.m和每条边的权值,问是否存在生成树,其边权值和为fibonacci数集合{1,2,3,5,8...}中 ...
- HDU 5167 Fibonacci 筛法+乱搞
题目链接: hdu: http://acm.hdu.edu.cn/showproblem.php?pid=5167 题意: 给你一个x,判断x能不能由斐波那契数列中的数相乘得到(一个数可以重复使用) ...
随机推荐
- 编写高性能的javascript代码(持续更新)
参考资料: Vanilla JS——世界上最轻量的JavaScript框架(没有之一) http://segmentfault.com/a/1190000000355277 探索高效jQuery的奥秘 ...
- sql 语句中的 (+) 是什么意思?
在select语句中(+)指的是外连接,是连接查询的一种方法.例:select t1.*,t2.* from dept t1,emp t2 where t1.deptno=t2.deptno(+);其 ...
- poi生成word2007及以上文件
一.简介 对于poi来说,poi可以完成对word.excel.ppt的处理.word目前有两种文件格式,一种是doc后缀.另一种是docx后缀的.2007之前的版本都是doc后缀的,这种格式poi使 ...
- FastDFS架构
1.什么是 FastDFS FastDFS是用c语言编写的一款开源的分布式文件系统.FastDFS为互联网量身定制,充分考虑了冗余备份.负载均衡.线性扩容等机制,并注重高可用.高性能等指标,使用Fas ...
- HDU 4240 Route Redundancy
Route Redundancy Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Origin ...
- 洛谷 2921 记忆化搜索 tarjan 基环外向树
洛谷 2921 记忆化搜索 tarjan 传送门 (https://www.luogu.org/problem/show?pid=2921) 做这题的经历有点玄学,,起因是某个random题的同学突然 ...
- ZOJ 3829 模拟贪心
2014牡丹江现场赛水题 给出波兰式,推断其是否合法.假设不合法有两种操作: 1:任何位置加一个数字或者操作符 2:随意两个位置的元素对调 贪心模拟就可以 先推断数字数是否大于操作符数,若不大于 an ...
- Baby_Step,Gaint_Step(分析具体解释+模板)
下面是总结自他人博客资料.以及本人自己的学习经验. [Baby_Step,Gaint_Step定义] 高次同余方程. BL == N (mod P) 求解最小的L.因为数据范围非常大,暴力不行 这里用 ...
- 剑指offer_面试题_从上往下打印二叉树
题目:从上往下打印出二叉树的每一个结点.同一层的结点依照从左到右的顺序打印.比如输入图4.5中的二叉树.则依次打印出8.6.10.5.7.9.11. 8 / \ 6 10 / \ ...
- Math类概述及其成员方法
Math 类包括用于运行基本数学运算的方法,如初等指数.对数.平方根和三角函数,这个类寻常开发中用的不多,可是在某些需求上会用到,比方求二个用户年龄的相差多少岁,这会用到Math类中的方法!如今把Ma ...