CF369D Valera and Fools 题解】的更多相关文章

题目链接:http://codeforces.com/contest/369/problem/D 注意题意:所有fools都向编号最小的fool开枪:但每个fool都不会笨到想自己开枪,所以编号最小的fool向编号次小的fool开枪: 所以只需记录编号最小的两位成员即可代表一种状态:当然当只剩一个fool时,次小编号是不存在的出界元素. 编号最小的两个fools只有四种状态:a活b活,a死b死,a活b死,a死b活:注意状态转移条件. 记忆化搜索即可(算法上依然是搜索的流程,但是搜索到的一些解用动…
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 369C - Valera and Elections: 这是一个树上问题,用深搜,最开始贪心想得是只加叶子节点,找到一个叶子节点且从根1 ——> 叶子节点有problem edges,就把这个点加入,但后来一直WA,才发现时贪错了,找到的这个叶子节点不一定需要,所以要多记录点信息,参考别人的思想,就是标记每个点是不是需要修,如果一个更深的点需要修,则中间的就不需要了. 代码: #include<cstdio>…
以后争取补题不看别人代码,只看思路,今天就是只看思路补完的题,有点小激动. A. Valera and Plates 水题,贪心地先放完第一种食物,在考虑第二种. 居然被卡了一会,心态要蹦 :(: #include<bits/stdc++.h> using namespace std; int n,m,k; int main() { cin>>n>>m>>k; ,cnt2=; ;i<=n;i++) { int g; scanf("%d&quo…
H - A + B Strikes Back A + B is often used as an example of the easiest problem possible to show some contest platform. However, some scientists have observed that sometimes this problem is not so easy to get accepted. Want to try? Input The input co…
A. Numbers Joke time limit per test:2 seconds memory limit per test:64 megabytes input:standard input output:standard output   Input The input contains a single integer a (1 ≤ a ≤ 30). Output Output a single integer. Example Input 3 Output 27 题目链接:ht…
趁着上课无聊,来补一补-- A. Numbers Joke 直接oeis就好了:http://oeis.org/search?q=numbers+joke&language=english&go=Search #include<bits/stdc++.h> using namespace std; long long p[]={ 4, 22, 27, 58, 85, 94, 121, 166, 202, 265, 274, 319, 346, 355, 378, 382, 39…
树上差分半裸题 常规思路是进行三次DFS,然后常规运算即可 这里提供两次dfs的思路(wyz tql orz) 我们以样例2为例 我们考虑任意一条路径,令其起点为u终点为v,每走一次当前路径则v的访问次数必定+1,于是我们可以使每一个点表示连接其上的一条边的访问次数,所以我们令节点v的访问次数+1; 与此同时,过程中的路径也同样会被访问,且这里是双向边,于是与此同时的我们也令节点u的访问次数+1;当然访问当前子树下根节点中包含的两个点并不会访问,而我们在增加u和v的访问时同时也错误地增加了其公共…
April Fools Day Contest 2014 A.C.H三道题目 =================================================================== A. The Great Game 这题怎没看懂..看了官方题解真是恍然大悟啊,原来是石头剪刀布啊!!! 8< 代表剪刀啊 () 代表石头啊 [] 代表布啊 真是逆天啊,这么一说还真觉得有点像....尤其是那个剪刀. 给那个出题人的想象力跪了. /* * ===============…
D. Fools and Foolproof Roads   You must have heard all about the Foolland on your Geography lessons. Specifically, you must know that federal structure of this country has been the same for many centuries. The country consists of n cities, some pairs…