E. Sergey and Subway】的更多相关文章

题意:给出一颗树,现在,给哪些距离为2的点对,加上一条边,问所有点对的距离和 题解:如果没有加入新的边,距离和就会等于每条边的贡献,由于是树,我们用点来代表点上面的边,对于每条边,它的贡献将是(子树大小)*(n-子树大小) 而这题加上了新边,我们依然这样算贡献,跨越旧边的次数,依然是(子树大小)*(n-子树大小),只不过都是两个两个的走,那么虽然跨越了这条边,但是它可能走的是新边,也就是他的贡献要除以2,对于那些真正跨越了旧边的点对,它其实不需要除2的,所以我们要把它加上,这些点对的数量是(奇数…
题目链接 题意:给你一棵树,然后连接两个有公共邻居的点,问你连完后,任意两点的距离之和. 一开始看这种题,还不怎么会做,借鉴了这位大佬的博客,get到了新技能,当我们求树上任意俩点的距离之时,可以转化问题,不看点,而看边,每条边的使用次数是固定的,每条边使用的次数为:这条边左边的顶点数*右边的顶点数,而由于我们可以将相隔一个点的两个点连起来,所以,如果是偶数的距离,我们可以2个2个跳,就是距离的一半,奇数呢就是(距离+1)/2,而奇数的距离只能在偶数和奇数层产生,所以用dp[now][2]dp[…
题意 给出 \(n\) 个点的树,求 \(\sum_{i=1}^n{\sum_{j=i}^n{\lceil \frac{dis(i,j)}{2} \rceil}}\) . \(n\leq 2 \times 10^5\) . 分析 点分治SBT.考虑更快速的做法. 如果直接统计总的贡献唯一的问题在于奇数路径统计时上取整的问题. 实际答案加上奇数长路径条数就可以解决问题. 一条路径可以写成: \({dis}_u+{dis}_v-2*{dis}_{lca}\), \(2*{dis}_{lca}\) 是…
分两种情况讨论 一种为奇数长为$L$的路径,在经过变化后,我们需要走$\frac{L}{2} + 1$步 一种为偶数长为$L$的路径,在变化后,我们需要走$\frac{L}{2}$步 那么,我们只需要讨论出所有奇数长的路径的个数,再加上原本的路径和,除以2就是答案了 对于奇数长的路径的个数,一定是从奇点走到偶点 对于路径和,考虑每条边的经过次数即可 #include <map> #include <queue> #include <vector> #include &l…
题意 题目链接 Sol 很套路的题 直接考虑每个边的贡献,最后再把奇数点的贡献算上 #include<bits/stdc++.h> #define Pair pair<int, int> #define MP(x, y) make_pair(x, y) #define fi first #define se second #define int long long #define LL long long #define rg register #define pt(x) prin…
比赛时候写复杂了…… 我写的是 计算每个节点树内所有点到某个点的距离和. #include <bits/stdc++.h> using namespace std; typedef long long ll; ; vector<int> g[maxn]; int son[maxn]; ll d[maxn]; ///树内所有点到某个点的距离和 int odd[maxn]; int even[maxn]; void dfs1(int u, int fa) { d[u] = ; son[…
给出一颗$N$个节点的树,现在我们**在原图中**每个不直接连边但是中间只间隔一个点的两个点之间连一条边. 比如**在原图中**$u$与$v$连边,$v$与$w$连边,但是$u$与$w$不连边,这时候我们就需要连一条$u$与$v$的边. 现在我们需要求出新图中每一个点对$(i,j)\ (1 \leq i \leq j \leq N)$的经过的边数和. 因为实在太菜了不会树形dp的只好用点分了…… (点分是个好东西所有树的题目都可以暴力艹过去) 首先,设原点对之间距离为$dis$,如果$dis$是…
学习博客:戳这里 本人代码: 1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int maxn = 2e5 + 10; 5 const ll mod = 998244353; 6 vector<int> mp[maxn]; 7 ll ans = 0, cnt[3]; 8 int n; 9 ll dfs(int u, int pre,int now) { 10 ++cn…
Codeforces Round #513 游记 A - Phone Numbers 题目大意: 电话号码是8开头的\(1\)位数字.告诉你\(n(n\le100)\)个数字,每个数字至多使用一次.问最多能凑出多少个电话号码. 思路: 统计8出现的次数,如果有多余的8不能作为开头,那么就将其放到后面去 源代码: #include<cstdio> #include<cctype> #include<algorithm> inline int getint() { regi…
A. Phone Numbers 签. #include <bits/stdc++.h> using namespace std; #define N 110 char s[N]; ], n; int main() { while (scanf("%d", &n) != EOF) { scanf(); memset(cnt, , sizeof cnt); ; i <= n; ++i) ++cnt[s[i] - ']; ; ; i <= cnt[]; ++…
前记 眼看他起高楼:眼看他宴宾客:眼看他楼坍了. 比赛历程 开考前一分钟还在慌里慌张地订正上午考试题目. “诶这个数位dp哪里见了鬼了???”瞥了眼时间,无奈而迅速地关去所有其他窗口,临时打了一个缺省源. A. Phone Numbers 那么就是模拟. #include<bits/stdc++.h> int n,x; ]; int read() { char ch = getchar(); ; ; for (; !isdigit(ch); ch=getchar()) ; for (; isd…
我是比赛地址 A:Phone Numbers $Description$:给你一串数字,问你能组成多少开头为8的11位电话号码. $Sol$:统计8的数量,与$n$%11作比较. #include<cstdio> #include<algorithm> #include<cstring> using namespace std; int n,len,cnt,ans; ]; int main() { scanf("%d",&n); scanf(…
A Phone Numbers 题意:定义"电话号码"为开头为'8',长度为11的字符串.给定一些字符,每个字符只能用一次,求可以拼出多少个电话号码(可以重复). 直接min(str.length()/11, number_of_8_in(str)) B Maximum Sum of Digits 题意:设\(S(a)\)为\(a\)的各数位之和,求最大的\(S(a)+S(b)\),满足\(a+b=n\). 让\(a\)全是\(9\)并且尽可能大就行了(鬼知道为什么). C Maxim…
本次 5 道题均来自Codeforce 关于树形DP的算法讲解:Here 791D. Bear and Tree Jumps 如果小熊每次能跳跃的距离为1,那么问题变为求树上任意两点之间距离之和. 对于每一条边sum1和sum2分别表示边的左右点数,ans=各边的sum1*sum2之和即为答案. 而本题最大跳跃距离为k,答案变为(ans+sum)/k.sum为每一条边需要多走x步才能整除k的x之和. 树上任意两点间距离len=depth[x1]+depth[y1]-2*depth[f],f表示点…
作业源程序代码:https://github.com/R-81/subway 作业程序使用说明:通过输入命令参数求解路线(仅支持-b,-c),根据参数得出路线后,程序不会结束,此时可输入地铁路线名(例如地铁一号线)输出此路线上所有车站名. 1)各模块开发需要消耗的时间   Personal Software Process Stages Time Planning 计划 · Estimate · 估计这个任务需要多少时间 15h Development 开发 · Analysis · 需求分析 …
Subway Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 860    Accepted Submission(s): 126Special Judge Problem Description jiefangxuanyan and yiyi cat are universally acknowledged model couple…
这个图标集是306个优化的像素完美,精雕细琢的图标.为这些设备进行了优化:iOS.Windows Phone.Windows 8 and BlackBerry 10,提供 PNG, SVG, XALM, PSD, CSH, SKETCH, PDF, AI 和 EPS 格式. 在线演示      源码下载 您可能感兴趣的相关文章 网站开发中很有用的 jQuery 效果[附源码] 分享35个让人惊讶的 CSS3 动画效果演示 十分惊艳的8个 HTML5 & JavaScript 特效 Web 开发中…
1272. Non-Yekaterinburg Subway Time limit: 1.0 secondMemory limit: 64 MB A little town started to construct a subway. The peculiarity of the town is that it is located on small islands, some of them are connected with tunnels or bridges. The mayor is…
Non-Yekaterinburg Subway Time limit: 1.0 secondMemory limit: 64 MB A little town started to construct a subway. The peculiarity of the town is that it is located on small islands, some of them are connected with tunnels or bridges. The mayor is sure…
树的最小表示法 给定两个有根树的dfs序,问这两棵树是否同构 题解:http://blog.sina.com.cn/s/blog_a4c6b95201017tlz.html 题目要求判断两棵树是否是同构的,思路是用树的最小表示法去做.这里用的最小表示法就是将树的所有子树分别用1个字符串表示,要按字典序排序将他们依依连接起来.连接后如果两个字符串是一模一样的,那么他们必然是同构的.这样原问题就变成了子问题,子树又是一颗新的树. Source Code Problem: User: sdfzyhy…
Subway 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/L Description You have just moved from a quiet Waterloo neighbourhood to a big, noisy city. Instead of getting to ride your bike to school every day, you now get to walk and take the s…
Subway Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4928   Accepted: 1602 Description You have just moved from a quiet Waterloo neighbourhood to a big, noisy city. Instead of getting to ride your bike to school every day, you now get…
问题来源 BYVoid魔兽世界模拟赛 [问题描述] 蒙提在暴风城与铁炉堡之间的地铁站中工作了许多年,除了每天抓一些矿道老鼠外,没有其他的变化.然而最近地铁站终于要扩建了,因为侏儒们攻克了建设长距离穿海隧道的技术难题,矮人们制造的***威力也有了很大的增强.于是,联盟决定修建通往诺森德的地铁.拥有常年的地铁站工作经验的蒙提被派往了新的线路上,他的工作是进行地铁重组. 如上图,在左边部分停靠着N节车厢,从右向左标号依次为1.2.…….N.中间有一个停车轨道,这个轨道上最多只能同时停放P节车厢.现在需…
Subway Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6692   Accepted: 2177 Description You have just moved from a quiet Waterloo neighbourhood to a big, noisy city. Instead of getting to ride your bike to school every day, you now get…
Subway Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6689   Accepted: 2176 Description You have just moved from a quiet Waterloo neighbourhood to a big, noisy city. Instead of getting to ride your bike to school every day, you now get…
すぬけ君の地下鉄旅行 / Snuke's Subway Trip Time limit : 3sec / Memory limit : 256MB Score : 600 points Problem Statement Snuke's town has a subway system, consisting of N stations and M railway lines. The stations are numbered 1 through N. Each line is operate…
Description You have just moved from a quiet Waterloo neighbourhood to a big, noisy city. Instead of getting to ride your bike to school every day, you now get to walk and take the subway. Because you don't want to be late for class, you want to know…
In the big cities, the subway systems always look so complex to the visitors. To give you some sense, the following figure shows the map of Beijing subway. Now you are supposed to help people with your computer skills! Given the starting position of…
In the big cities, the subway systems always look so complex to the visitors. To give you some sense, the following figure shows the map of Beijing subway. Now you are supposed to help people with your computer skills! Given the starting position of…
The construction of subway in Bertown is almost finished! The President of Berland will visit this city soon to look at the new subway himself. There are n stations in the subway. It was built according to the Bertown Transport Law: For each station …