地址:http://codeforces.com/contest/796/problem/D 题目: D. Police Stations time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Inzane finally found Zane with a lot of money to spare, so they togeth…
传送门 题意 n个点有n-1条边相连,其中有k个特殊点,要求: 删去尽可能多的边使得剩余的点距特殊点的距离不超过d 输出删去的边数和index 分析 比赛的时候想不清楚,看了别人的题解 一道将1个联通块转化为k个树的题目,考虑上界,应该是k-1条边,这k-1条边是原图中连接树与树的边,那么我们操作如下: 1.将特殊点i染色为i,放入队列 2.做一次bfs,对每个点相邻的点染色并判断 3.遍历边,如果边的两点不同色,则输出边的index trick 代码 #include <cstdio> #i…
题目链接:Codeforces Round #275 (Div. 2) C - Diverse Permutation 题意:一串排列1~n.求一个序列当中相邻两项差的绝对值的个数(指绝对值不同的个数)为k个.求序列. 思路:1~k+1.构造序列前段,之后直接输出剩下的数.前面的构造能够依据,两项差的绝对值为1~k构造. AC代码: #include <stdio.h> #include <string.h> int ans[200010]; bool vis[100010]; i…
C. Bank Hacking 题目大意:给出一棵n个节点的树,每个节点有一个权值,删掉一个点的代价为当前这个点的权值,并且会使其相邻点和距离为2且中间隔着未被删除的点的点权值加1,现在选一个点开始删,之后每次能删掉被删过的点的相邻点,问删掉整棵树,删各节点花费的最大值最小是多少.(n<=300,000) 思路:确定第一个删的点之后,与这个点相邻的点的删除花费是原权值加1,其他点是原权值加2,把所有点权加2后枚举一个点减2再把相邻的减1,线段树统计答案后改回去,总复杂度O(nlogn),O(n)…
A - Buying A House 题意:给你n个房间,妹子住在第m个房间,你有k块钱,你想买一个离妹子最近的房间.其中相邻的房间之间距离为10,a[i]=0表示已经被别人买了. 题解:扫一遍更新答案即可. #include<bits/stdc++.h> using namespace std; const int maxn = 105; int mp[maxn]; int n,m,k; int main(){ scanf("%d%d%d",&n,&m,&…
Description Inzane finally found Zane with a lot of money to spare, so they together decided to establish a country of their own. Ruling a country is not an easy job. Thieves and terrorists are always ready to ruin the country's peace. To fight back,…
题目链接: http://codeforces.com/problemset/problem/208/C C. Police Station time limit per test:2 secondsmemory limit per test:256 megabytes 问题描述 The Berland road network consists of n cities and of m bidirectional roads. The cities are numbered from 1 to…
题目链接:http://codeforces.com/contest/208/problem/C 思路:题目要求的是经过1~N的最短路上的某个点的路径数 /  最短路的条数的最大值.一开始我是用spfa得到从1开始的最短路和从N开始的最短路,然后分别从N开始记忆化搜索,得到从1到达最短路径上的u的路径条数,记作dp1[u], 然后再从1开始搜,得到最短路径上从N到达某个点u的路径条数,记作dp2[u],于是经过某个点u的最短路径数目为dp1[u] * dp2[u],然后只需枚举u求最大值即可.…
A. Buying A House time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains unknown to us. The gi…
题目链接:http://codeforces.com/problemset/problem/796/C 题目大意:有n家银行,第一次可以攻击任意一家银行(能量低于自身),跟被攻击银行相邻或者间接相邻(距离<=2)的银行能量+1,除了第一次外,攻击一家银行需要满足以下条件: ①:跟被攻击过后的银行相邻: ②:能量低于攻击者 ③:银行没有被攻击过 题解:可以从题意得知,比如攻击银行i,如果说银行i能量为t,跟银行距离>=2的银行中能量最大的为mx,自身至少所需能量=max(t+1,mx+2),因为…