Terrorist’s destroy HDU - 4679】的更多相关文章

Terrorist’s destroy HDU - 4679 There is a city which is built like a tree.A terrorist wants to destroy the city's roads. But now he is alone, he can only destroy one road, then the city will be divided into two cities. Impression of the city is a num…
Terrorist’s destroy Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 24    Accepted Submission(s): 6 Problem Description There is a city which is built like a tree.A terrorist wants to destroy th…
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4679 题意:给定一颗树,每条边有一个权值w,问切掉哪条边之后,分成的两颗树的较大的直径*切掉边的权值最小?如果存在多条边使得结果相同,输出边id最小的 思路: dept一次找出最深的节点,之后以最深的节点出发(rt1)dept找到树的直径(即找到rt2):将路径保存在f[]中: 之后分别从rt1/rt2进行深搜,找到以一个节点为根的树的直径,这样在每次dfs之后,可以求出每条边的一边的最值,这样两次取m…
如果不在最长路的边,那么肯定是w*最长路. 如果在最长路,那么把最长路分成两段,左边树的最长路就是左段+左边点的次短路(不包含最长路上的点的最长路) ,右边同理. 还有就是更新,经过左端点的最长路,不一定是整颗左边树的最长路,乱搞一下就可以了.我是搞成一条链,写的很麻烦..从一点搞到了快四点.. #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include…
题意:给你一棵树,每条边都有值W,然后问你去掉一条边,令val = w*max(两颗新树的直径),求val最小值~ 做法,先求树的直径,然后算出直径上每个点的最长枝条长度.这样对于每一条边,假如是枝条边,那么val = w*直径,如果不是那么val = max(w*(两颗新树的直径)).新树直径说到这里已经很好算了. DFS爆栈了一下午 #include <stdio.h> #include <string.h> #include <iostream> #include…
题意: There is a city which is built like a tree.A terrorist wants to destroy the city's roads. But now he is alone, he can only destroy one road, then the city will be divided into two cities. Impression of the city is a number defined as the distance…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4679 题意:给一颗树,每个边有一个权值,要你去掉一条边权值w剩下的两颗子树中分别的最长链a,b,使得w*Min(a,b)最小.. 说白了就是要枚举每条边,然后在O(1)的时间内求出两颗子树的最长链.因此我们可以考虑用树形DP,首先一遍DFS,对于每个节点维护两个信息,hign[u]:u为根节点的子树的深度,f[u]:u为根节点的子树的最长链.然后还要维护一个hige[i][0]和hige[i][1]…
思路:我们其实只需要枚举每条边,求得最小值就行了. 先dfs算出每个节点作为根时,其子树的最长路径,以及进过该节点的最长,次长,第三长路径. 然后在次dfs枚举求出切断某条边,求出这条边的两个端点为子树根,其子树的最长路径.b就是其中较大的. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<iostream> #include<cstring> #include<algori…
题意:给一棵树,边的权值都是1,摧毁每条边是有代价的,选择摧毁一条边,把一棵树分成两部分,求出两部分中距离最大的两点的距离,求出距离*代价最小的边,多条的话输出序号最小的. 刚开始理解错题意了,wrong了几次,一直在纠结摧毁一条边后上边的树的最远距离怎么求,儿子树的最远距离就是所有子树的最长边+次长边就可以了.当我们求到一个节点u时,肯定有一个祖先节点,该祖先节点在摧毁与u链接的边后剩余的子树中最长的边和次长边之和是最大的,如果摧毁u与子节点的边时,就要考虑那个祖先节点的位置了,可能就是u这个…
String Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 695    Accepted Submission(s): 254 Problem Description Given 3 strings A, B, C, find the longest string D which satisfy the following rule…
/* 题目大意:给n个点n-1条边的树,求删除哪条边时两个树中最大的直径与边权的乘积最小. 树的直径(Diameter)是指树上的最长简单路. 直径的求法:两遍BFS (or DFS) 若删除的边不是直径上的那么花费为max_len*wi 若删除的边是直径上的那么花费为max(dp[u][2],dp[v][2])*wi */ #pragma comment(linker, "/STACK:16777216") #include <iostream> #include <…
HDU 4678 Mine 对于每个空白区域,求SG值. 最后异或起来等于0,先手必败. #pragma comment(linker,"/STACK:102400000,102400000") #include<cstdio> #include<cstring> #define MAXN 1010 #define oo 1234567890 int arr[MAXN][MAXN]; bool vis[MAXN][MAXN]; int n, m; int dg,…
Day 1 上午 讲的挺基础的--不过还是有些地方不太明白 例1 给定一个数n,求将n划分成若干个正整数的方案数. 例2 数字三角形 例7 最长不下降子序列 以上太过于基础,不做深入讨论 例3 给定一个数n,求将n划分成若干个正整数的方案数. 题解: 定义状态 \(dp[i][j]\)表示用不超过\(j\)的数来组成\(i\) 状态转移 \(i < j \;\;\; dp[i][j]=dp[i][i]\) \(i = j \;\;\; dp[i][j]=dp[i][j-1]+1\) \(i >…
Terrorist’s destroy Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 1643    Accepted Submission(s): 558 Problem Description There is a city which is built like a tree.A terrorist wants to destro…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4940 Destroy Transportation system Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 21    Accepted Submission(s): 17 Problem Description Tom is a…
Destroy the Well of Life Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1692 Description In the game of DotA (Defense of the Ancient), there are two opposite legions called The Sentinel and The Scourage. Now Th…
Destroy Transportation system Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)http://acm.hdu.edu.cn/showproblem.php?pid=4940 Problem Description Tom is a commander, his task is destroying his enemy’s transportatio…
HDU 6187 Destroy Walls (思维,最大生成树) Destroy Walls *Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others) Total Submission(s): 1784 Accepted Submission(s): 692 * Problem Description Long times ago, there are beautiful histor…
Description Tom is a commander, his task is destroying his enemy’s transportation system. Let’s represent his enemy’s transportation system as a simple directed graph G with n nodes and m edges. Each node is a city and each directed edge is a directe…
看不懂题解以及别人说的集合最多只有一个点..... 然后试了下题解的方法http://blog.sina.com.cn/s/blog_6bddecdc0102uzka.html 首先是无源汇有上下界最大流:就是最大流基础上,无源汇,每条边的流量有上下界. 这题是给一个图,V<=200,E<=5000,每条边有destroy[i][j]和build[i][j].选一个非空点集S,令T为S的补集.若max{∑D[s][t]-D[t][s]-B[t][s]}<=0输出happy否则输出unha…
职务地址:pid=4940">HDU 4940 当时这个题一看就看出来了是网络流的最小割.然后就一直在想建图. .然后突然发现,应该要让T集合的数目最少,不然仅仅要有两个,那这两个的每个都能够跑到S集合,使得T集合变小.那就仅仅能是1个了.然后. .枚举就好了. .可是尽管认为这么做肯定没错.. 可是不敢敲..由于当时都3个小时了才仅仅有10个队过了.. . 后来又想了几遍后认为这样没错,就写完交上了.果然AC. .. 代码例如以下: #include <iostream> #…
Problem Description Tom is a commander, his task is destroying his enemy’s transportation system. Let’s represent his enemy’s transportation system as a simple directed graph G with n nodes and m edges. Each node is a city and each directed edge is a…
Destroy Walls Long times ago, there are beautiful historic walls in the city. These walls divide the city into many parts of area. Since it was not convenient, the new king wants to destroy some of these walls, so he can arrive anywhere from his cast…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6187 题意:有一个V个结点M条边的带边权无向平面图,有一个人在一个区域,要拆一些墙使得他可以到达任意一个区域,问最小花费. 解法: #include <bits/stdc++.h> using namespace std; const int maxn = 100010; const int maxm = 200010; struct edge{ int u,v,w; edge(){} bool…
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=6089 题解 这波强行维护搞得我很懵逼... 扫描线,只考虑每个点能走到左上方(不包括正上方,但包括正左方)的哪些点,然后旋转四次坐标系处理 所有询问和操作点按照先\(x\)后\(y\)坐标的顺序排序,然后枚举每一行,按\(y\)从小到大的顺序枚举这一行每个点 对于一个询问点找出前面最后一个操作点,那么要求的就是一个矩形减去一个区间内所有后缀最大值的和 然后这个东西可以用线段树直接维护,记录个区间最大…
思路:无源汇有上下界可行流判定, 原来每条边转化成  下界为D  上界为 D+B   ,判断是否存在可行流即可. 为什么呢?  如果存在可行流  那么说明对于任意的 S 集合流出的肯定等于 流入的, 流出的计算的 X 肯定小于等于这个流量(X是下界之和), 计算出来的Y (上界之和)肯定大于等于 这个流量  肯定满足X<=Y. #include<cstdio> #include<cstring> #include<algorithm> #include<cm…
前几天正看着网络流,也正研究着一个有上下界的网络流的问题,查看了很多博客,觉得下面这篇概括的还是相当精确的: http://blog.csdn.net/leolin_/article/details/7208246 里面包含了其中一些解释.看了这道题的题解之后就会发现确实好像就是一个无源的有上下界的可行流. #pragma warning(disable:4996) #include <iostream> #include <cstring> #include <string…
题意:有n个点和m条有向边构成的网络.每条边有两个花费: d:毁坏这条边的花费 b:重建一条双向边的花费 寻找这样两个点集,使得点集s到点集t满足 毁坏全部S到T的路径的费用和 > 毁坏全部T到S的路径的费用和 + 重建这些T到S的双向路径的费用和. 思路1: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center&quo…
题意 有一个 \(n\times m\) 的二维网格,其中有 \(k\) 个禁止点. 有 \(q\) 组询问,每组询问为给一个点,求有多少个矩形以这个点为一角且不包含禁止点. \(n,m,k,q\le 10^5\) sol zjt 是怎么认为这是道李超树题的--难道只是因为看到了官方题解吗? 这题不难,但是太恶心了我琢磨了三小时,关键是没选手写题解,官方题解还写李超树误导人 不过官方题解除了最后一段最后一句外,其余内容还是可以借鉴的: 问题相当于平面中有若干障碍点,询问以某一个点为四个角之一的不…
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5091 Problem Description Recently, the γ galaxies broke out Star Wars. Each planet is warring for resources. In the Star Wars, Planet X is under attack by other planets. Now, a large wave of enemy spaces…