luogu P3565 [POI2014]HOT-Hotels】的更多相关文章

传送门 无脑暴力+O2=AC 题目要统计距离两两相等的三个点的组数,这三个点之间显然有一个点,并且这三个点到这个点的距离都相同.所以枚举中间这个点作为根,然后bfs整棵树,对于每一层,把以根的某个儿子的子树中在这一层点的数量统计出来,那么这样三元组的数量就是在这些点里面选3个点,并且分别来自不同子树的方案,\(f_{i,0/1/2/3}\)即可 详见代码 // luogu-judger-enable-o2 #include<bits/stdc++.h> #define LL long long…
Luogu P3577 [POI2014]TUR-Tourism 题目链接 题目大意:给出一张\(n\)个点,\(m\)条边的无向图,保证任意两点之间没有点数超过\(10\)的简单路径.选择第\(i\)个点要支付\(C_i\)的代价,要求用最小的代价使得每个点被选择或者与一个被选择的点相邻. \(n\leq 20000,m\leq 25000,C_i\leq 1000\). 可以发现,如果原问题是在树上的话就很简单.所以我们先建出\(dfs\)树.因为这是无向图,所以所有的非树边都是返祖边.由题…
二次联通门 : luogu P3567 [POI2014]KUR-Couriers MMP 指针 RE + MLE + WA..... 不得已...向黑恶的数组实力低头 /* 指针 */ #include <algorithm> #include <cstdio> #define Max 2000009 void read (int &now) { now = ; register char word = getchar (); ') word = getchar ();…
题目:[POI2014]KUR-Couriers 题解: 要求出现次数大于(R-L+1)/2的数,这样的数最多只有一个.我们对序列做主席树,每个节点记录出现的次数和(sum).(这里忽略版本差值问题)对于一个节点,如果左儿子的sum小于等于(R-L+1)/2,则答案不可能在左儿子中:右儿子同理.然后对有可能的儿子递归寻找答案,如果左右儿子都不可能,则不存在答案. 代码: BZOJ 3524: #include<cstdio> #include<cstring> #include&l…
题目描述 There are nn towns in Byteotia, connected with only n-1n−1 roads. Each road directly links two towns. All the roads have the same length and are two way. It is known that every town can be reached from every other town via a route consisting of…
P3572 [POI2014]PTA-Little Bird 题目描述 In the Byteotian Line Forest there are nn trees in a row. On top of the first one, there is a little bird who would like to fly over to the top of the last tree. Being in fact very little, the bird might lack the s…
传送门 一群蚂蚁能被吃,也就是走到指定边的两端点之一要走到另一端点时有\(k\)只,我们可以从这两端点逆推,记两个值为走到某个点时最后会被吃掉\(k\)只蚂蚁的蚂蚁数量范围,式子下面有,很好理解(雾).最后在每个叶子节点二分查找有多少个数在区间内即可 // luogu-judger-enable-o2 #include<bits/stdc++.h> #define LL long long #define il inline #define re register #define inf 20…
题目大意: 给出T组询问,每组询问给出四个数a,b,c,d,每次询问满足a<=x<=b,c<=y<=d的gcd(x,y)的最大值 首先可以想到如果存在gcd(x,y)=k,那么就一定要满足b/k>(a-1)/k&&d/k>(c-1)/k. 而n/k的k取法只有√n种,直接枚举即可. //by zykykyk #include<cstdio> #include<ctime> #include<iostream> #inc…
从1开始,跳到比当前矮的不消耗体力,否则消耗一点体力,每次询问有一个步伐限制,求每次最少耗费多少体力 #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; const int N=1e6+10; #define int long long int a[N],dp[N],q[N],l,r=1; int n,m,k; inlin…
题目描述 从1开始,跳到比当前矮的不消耗体力,否则消耗一点体力,每次询问有一个步伐限制,求每次最少耗费多少体力 单调队列优化动态规划 #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; const int N=1e6+10; #define int long long int a[N],dp[N],q[N],l,r=1;…