LCA求树上两点最短距离,如果a,b之间距离小于等于k并且奇偶性与k相同显然YES:或者可以从a先走到x再走到y再走到b,并且a,x之间距离加b,y之间距离+1小于等于k并且奇偶性与k相同也输出YES:或者从a走到y再走到x再走到b,并且总距离+1小于等于k并且奇偶性与k相同同样输出YES:否则输出NO. #define HAVE_STRUCT_TIMESPEC #include <bits/stdc++.h> using namespace std; ]; int cnt; struct e…
题:https://codeforces.com/contest/1304/problem/E 题意:给定一颗树,边权为1,m次询问,每次询问给定x,y,a,b,k,问能否在原树上添加x到y的边,a到b的路径长度等于k,注意这里的点和边都是可以重复走的: 分析:注意到点边可以重复走,我们就可以推出一个条件就是a.b之间的长度len要满足>=k: 其次当路长大于k时,我们就要判断len和k是否同奇偶,因为要到达长度len要被分为:len=k+2*i(i>=0),否则无法构造出这么一条路径 然后添…
Codeforces Round #620 (Div. 2) A. Two Rabbits 题意 两只兔子相向而跳,一只一次跳距离a,另一只一次跳距离b,每次同时跳,问是否可能到同一位置 题解 每次跳相对距离减少Δ=(a+b)\Delta=(a+b)Δ=(a+b),如果总距离是Δ\DeltaΔ的倍数,就证明可以到同一位置 代码 #include<iostream> #include<cstdio> using namespace std; int main() { long N,x…
LCA的倍增 模板: ], depth[maxn]; int dist[maxn],head[maxn]; void add(int u,int v,int dist0){ a[tot].next=head[u]; a[tot].dist=dist0; a[tot].v=v; head[u]=tot++; } void dfs(int u,int fa,int d) { fath[u][]=fa; depth[u]=d; ;i<;i++) fath[u][i]=fath[fath[u][i-]]…
http://acm.hdu.edu.cn/showproblem.php?pid=2586 课上给的ppt里的模板是错的,wa了一下午orz.最近总是被坑啊... 题解:树上两点距离转化为到根的距离之和减去重复部分,相当于前缀和 dis[x] + dis[y] - 2ll * dis[LCA(x, y)] #define _CRT_SECURE_NO_WARNINGS #include<cmath> #include<iostream> #include<stdio.h&g…
https://codeforces.com/contest/1114/problem/C 题意 给你一个数n(<=1e8),要你求出n!在b进制下的后缀零个数(b<=1e12) 题解 a在b进制下的后缀零个数? \(a=p_1^{x_1}*p_2^{x_2}*p_3^{x_3}...*p_n^{x_n}\), \(b=q_1^{y_1}*q_2^{y_2}*q_3^{y_3}...*q_n^{y_n}\) p,q为素因子,后缀零个数为min(floor(\(x_i/y_i\))) 求p在n!…
A. Two Rabbits 思路: 很明显,如果(y-x)%(a+b)==0的话ans=(y-x)/(a+b),否则就为-1 #include<iostream> #include<algorithm> using namespace std; +; int main(){ int k; scanf("%d",&k); while(k--){ long long x,y,a,b,ans; cin>>x>>y>>a&g…
A. Two Rabbits (手速题) #include<bits/stdc++.h> using namespace std; typedef long long ll; int main(){ int t; cin>>t; while(t--){ ll x,y,a,b; cin>>x>>y>>a>>b; ll sum = a+b; ){ cout<<(y-x)/sum<<endl; } else{ cou…
Being tired of participating in too many Codeforces rounds, Gildong decided to take some rest in a park. He sat down on a bench, and soon he found two rabbits hopping around. One of the rabbits was taller than the other. He noticed that the two rabbi…
题:https://codeforces.com/contest/1304/problem/D 题意:给定长度为n-1的只含’>'和‘<’的字符串,让你构造出俩个排列,俩个排列相邻的数字之间要满足这个字符串,找出的俩个要是最小化最长上升子序列,和最大化最长上升子序列: 分析:dilworld定理,最长下降子序列个数等于最长上升子序列的长度 先说构造最小的,LIS的长度就等于最长的连续'<'的长度加1,贪心地把最大的数放在最前面: 构造最大的就把最小的数尽可能放在前面…