cf C. Valera and Elections】的更多相关文章

C. Valera and Elections   The city Valera lives in is going to hold elections to the city Parliament. The city has n districts and n - 1 bidirectional roads. We know that from any district there is a path along the roads to any other district. Let's…
http://codeforces.com/contest/369/problem/C 先见边,然后dfs,在回溯的过程中,如果在这个点之后有多条有问题的边,就不选这个点,如果没有而且连接这个点的边还是有问题的边,这个点就是所求的点. #include <cstdio> #include <cstring> #include <algorithm> #define maxn 200000 using namespace std; int head[maxn],e,cnt…
369C - Valera and Elections 思路:dfs,对于搜索到的每个节点,看他后面有没有需要修的路,如果没有,那么这个节点就是答案. 代码: #include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back ; vector<int>g[N]; vector<int>edge[N]; vector<int>ans; int dfs(i…
Valera and Elections 题意:现在有n个候选人, 有n-1条路, 如果选择了这个候选人, 这个候选人就会将从自己这个城市到1号城市上所有坏的路都修复一下,现在求最小的候选人数目, 如果答案有多种情况输出任何一种都可以. 输入:x y k 表示x与y之间有一条双向通道, k==1 表示这路是好的, k == 2表示这条路是坏的. 题解: 从1开始dfs搜索, 往外走, 如果遇到坏的城市就标记一下, 然后继续往外走, 如果更远的地方有一个坏的路就用更远地方的城市候选人代替这个标记的…
CF 441E Description 一共执行\(k\)次,每次有\(p\%\)把\(x * 2\),有\((100 - p)\%\)把\(x + 1\).问二进制下\(x\)末尾期望\(0\)的个数. Solution 设\(f[i][j]\)为执行第\(i\)次后\(x + j\)末尾期望\(0\)的个数 加一:$f[i + 1][j - 1] = f[i + 1][j - 1] + (100 - p)% * f[i][j]; $ 乘二:\(f[i + 1][j * 2] = f[i +…
http://codeforces.com/contest/369/problem/E 题意:输入n,m; n 代表有多少个线段,m代表有多少个询问点集.每一个询问输出这些点的集合所占的线段的个数. 思路:求出没有被点的覆盖的线段的个数,n-这个个数就是所求的. #include <cstdio> #include <cstring> #include <algorithm> #define maxn 2000000 using namespace std; ; int…
http://codeforces.com/contest/369/problem/D 标号最小的两个人会有四种状态:a活b活,a死b活,a活b死,a死b死:按照这四种状态dfs就可以求出最后的数量. #include <cstdio> #include <cstring> #include <algorithm> #define maxn 5000 using namespace std; int n,k; int ans; int p[maxn]; bool vis…
http://codeforces.com/contest/369/problem/B 先对k个处理,先处理sk%k个为sk/k+1,如果sk/k==0,k个数都为sk/k:对与剩下的数也按照同样的方法处理,处理完之后就是所要求的序列. #include <cstdio> #include <cstring> #include <algorithm> #define maxn 10000 using namespace std; int n,k,l,r,s1,s2; i…
题意:1-n的一个排列, p2, ..., pn,f(p)的定义是此排列要交换最少的数对能够回到原排列1,2,3,4...n.给一个排列p.要将其变换成f值为m的排列,问至少要交换几个数对,并输出字典序最小的那组答案. 解法:处理出全部的置换群,求出环数k,此时f值为n-k.然后推断n-k和m的大小,分为两种操作 1.加环,这个是在随意元素个数大于1的环内交换随意两个数都能够做到加环 2.减环,交换随意两个环的随意两个元素.就能够做到将两个环连接起来 题目要求是输出字典序最小,那么就暴力搞. 代…
http://codeforces.com/problemset/problem/369/C 树的遍历,dfs搜一下,从根节点搜到每个分叉末尾,记录一下路况,如果有需要修复的,就把分叉末尾的节点加入答案 10w个点要用邻接表存图 #include <iostream> using namespace std ; typedef struct L{ int s,t ; int v ; int nxt ; }L ; L e[] ; ] ; int cnt ; void ins(int s,int…