点击打开链接 D.D-City Description Luxer is a really bad guy. He destroys everything he met. One day Luxer went to D-city. D-city has N D-points and M D-lines. Each D-line  connects exactly two D-points. Luxer will destroy all the D-lines. The mayor of D-ci…
题意:给定n个点和m条边,问你拆掉前i条边后,整个图的连同城市的数量. i从1到m. 思路:计算连通的城市,很容易想到并查集,但是题目里是拆边,所以我们可以反向去做. 存下拆边的信息,从后往前建边. #include <iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; struct node { int a,b; }Q[100005];…
A. Tutor Description Lilin was a student of Tonghua Normal University. She is studying at University of  Chicago now. Besides studying, she worked as a tutor teaching Chinese to Americans. So,  she can earn some money per month. At the end of the yea…
dp[ba][ta][bb][tb]表示a堆牌从下面拿了ba张,从上面拿了ta张.b堆牌从下面拿了bb张,从上面拿了tb张.当前玩家能得到的最大的分数. 扩展方式有4种,ba+1,ta+1,bb+1,tb+1,用当前剩下牌的总分减掉它,取最大值,就是当前玩家的最高分. 记忆化搜索 #include<iostream> #include<cstdio> #include<cmath> #include<algorithm> #include<cstrin…
计算12个数的和的平均数.四舍五入,不能有后导0. 我的做法是,将答案算出后,乘以1000,然后看个位是否大于等于5,判断是否要进位…… #include<iostream> #include<cstdio> #include<string.h> #include<cmath> #include<algorithm> using namespace std; #define eps 1e-2 int main() { int cas; scanf…
题意:初始时有个首都1,有n个操作 +V表示有一个新的城市连接到了V号城市 -V表示V号城市断开了连接,同时V的子城市也会断开连接 每次输出在每次操作后到首都1距离最远的城市编号,多个距离相同输出编号最小的城市 输入数据保证正确,每次添加与删除的城市一定是与首都相连的 题解:每次都只需要知道最远且编号最小的城市,所以直接使用优先队列存储 如果是+V就使用并查集(不能路径压缩)添加上然后加入优先队列,接着直接弹出首元素就是结果 如果是-V则把V指向0,接着弹出优先队列的第一个元素 如果他与1相连就…
题意:一个村子有n个房子,他们用n-1条路连接起来,每两个房子之间的距离为w.有m次询问,每次询问房子a,b之间的距离是多少. 分析:近期公共祖先问题,建一棵树,求出每一点i到树根的距离d[i],每次询问a.b之间的距离=d[a]+d[b]-2*d[LCA(a,b)];LCA(a,b)是a,b的近期公共祖先. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<iostream> #include…
m方枚举,并查集O(1)维护,傻逼题,,被自己吓死搞成神题了... #include <bits/stdc++.h> using namespace std; struct tri { int x,y,z; bool operator<(const tri & temp)const { return z<temp.z; } }; ],Size[],f[]; vector<tri> vec; int get_anc(const int x) { return x=…
题目链接:https://nanti.jisuanke.com/t/39271 题意:给定n个物品,m组限制,每个物品有个伤害值,现在让两个人取完所有物品,要使得两个人取得物品伤害值之和最接近,输出伤害值不小于另一个的人的伤害值,每组限制包括两次数x y,表示物品x和物品y不能由同一个人取得. 思路:思路是通过bfs或并查集将有关系的物品合并为一个物品,合并的物品有两个值,每个人必须分别取每个物品的一个值,然后就是背包问题了. 具体实现就是用root[i]表示i的祖先,a[i]表示i与其祖先的关…
http://acm.hdu.edu.cn/showproblem.php?pid=4710 Balls Rearrangement Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 735    Accepted Submission(s): 305 Problem Description Bob has N balls and A b…