题目链接:D Persistent Bookcase 题意:有一个n*m的书架,开始是空的,现在有k种操作: 1 x y 这个位置如果没书,放书. 2 x y 这个位置如果有书,拿走. 3 x 反转这一行,即有书的位置拿走,没书的位置放上书. 4 x 返回到第x步操作之后的书架. 现在给出q个操作,询问每次操作之后书架上书的数量. 思路: 开始没有思路.后来被告知dfs. [词不达意.参考:http://blog.csdn.net/zyjhtutu/article/details/5227949…
题目链接: D. Persistent Bookcase time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output Recently in school Alina has learned what are the persistent data structures: they are data structures that alw…
D. Persistent Bookcase Recently in school Alina has learned what are the persistent data structures: they are data structures that always preserves the previous version of itself and access to it when it is modified. After reaching home Alina decided…
题目链接:http://codeforces.com/contest/707/my 看了这位大神的详细分析,一下子明白了.链接:http://blog.csdn.net/queuelovestack/article/details/52269321 搞了两天,终于彻底理解了.本来觉得怎么也不可能和DFS扯上关系,结果以操作的编号建树,对于其他3个操作,直接dfs即可. 在执行操作④之后,书架的状态其实已经回到了之前的某种状态k那么,如果我们从状态k出发,直接去推算出所有经操作④会回到状态k的状态…
题目链接:D Directed Roads 题意:给出n个点和n条边,n条边一定都是从1~n点出发的有向边.这个图被认为是有环的,现在问你有多少个边的set,满足对这个set里的所有边恰好反转一次(方向反转),使得这个图里没有环. 思路:感觉关键是,n个点n条边,且每个点的出度为1,所以图里一定没有复环.想要使图里没环,对于每个连通块(点数为i)里的环(如果有环 点数为j),只要不是全翻和全不翻都是满足题意的set, 一共满足题意得set  即为 2^(i-j) * (2^j-2).所有的连通块…
Persistent Bookcase Problem Description: Recently in school Alina has learned what are the persistent data structures: they are data structures that always preserves the previous version of itself and access to it when it is modified. After reaching…
D. Persistent Bookcase 题目连接: http://www.codeforces.com/contest/707/problem/D Description Recently in school Alina has learned what are the persistent data structures: they are data structures that always preserves the previous version of itself and a…
Persistent Bookcase CodeForces - 707D time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output Recently in school Alina has learned what are the persistent data structures: they are data structures…
D. Persistent Bookcase time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output Recently in school Alina has learned what are the persistent data structures: they are data structures that always pr…
题目链接:http://codeforces.com/contest/707/problem/A A. Brain's Photos time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Small, but very brave, mouse Brain was not accepted to summer school of y…
Persistent Bookcase time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output Recently in school Alina has learned what are the persistent data structures: they are data structures that always prese…
CF707D Persistent Bookcase 洛谷评测传送门 题目描述 Recently in school Alina has learned what are the persistent data structures: they are data structures that always preserves the previous version of itself and access to it when it is modified. After reaching h…
// Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问题的思路: // // 第一个假设a字符串和b字符串相等,说直接YES // 假设b串全是0,直接YES // 注意到a串有一个性质,1的个数不会超过本身的加1. // a有个1的上限设为x,b有个1的个数设为y,则假设x < y // 那么直接NO. // // 如今普通情况下.就是模拟啦,找到a…
Problem   Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Description Input Output Print exactly one integer — the beauty of the product of the strings. Sample Input 3aba Sample Output 3 题解:这个题的思维难度其实不大,需要维护什么东西很容易想到,或…
Problem   Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Input The first line contains a single integer nn (2≤n≤150000) — the number of kittens. Each of the following n−1lines contains integers xi and yi (1≤xi,…
Problem   Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input Output The first line of output should contain "Yes", if it's possible to do a correct evaluation for all the dishes, or "No" otherwis…
Problem   Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input The first and only line contains a single integer mm (1≤m≤100000,1≤m≤100000). Output Print a single integer — the expected length of the array aa writte…
# [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原点开始走,方向自选(<- or ->),在过程中,若遇到一个权值>0的点,则将此权值计入答案,并归零.当次.此方向上的所有点均为0后,输出此时的答案. 然后,进行分析: 我们很容易想到这是一个贪心,我们将正的和负的分别存入两个数组,最初的方向为: \(zhengsum > fusum…
一个n*m的矩阵,有四种操作: 1.(i,j)处变1: 2.(i,j)处变0: 3.第i行的所有位置1,0反转: 4.回到第k次操作以后的状态: 问每次操作以后整个矩阵里面有多少个1. 其实不好处理的操作只有第四个,但是这题的思路很巧妙,123三种操作全部建立顺边,第四种操作将k和这次操作的序号建边,然后dfs进行操作即可,遇到尽头,则退回到前一个分岔点,并且回溯的过程中将操作反转. 具体见代码: #include <stdio.h> #include <algorithm> #i…
Description Recently in school Alina has learned what are the persistent data structures: they are data structures that always preserves the previous version of itself and access to it when it is modified. After reaching home Alina decided to invent…
time limit per test2 seconds memory limit per test512 megabytes inputstandard input outputstandard output Recently in school Alina has learned what are the persistent data structures: they are data structures that always preserves the previous versio…
题目链接:http://codeforces.com/problemset/problem/707/D  有一个n*m的书架,有K个操作,求每个操作后一共有多少本书:有4种操作: 1:x y 如果 x y 位置没有书,放一本书在上面: 2:x y如果 x y 位置有书,移走: 3:x,表示把第x行的所有又书的拿走,没书的放上去: 4:k,回到第k个操作后的状态: 离线处理k个操作:当操作不为 4 时,把操作i连在i-1后,=4时把操作 i 连在a[i].x后: 这样建一棵树,然后遍历即可,在回溯…
题目链接: http://codeforces.com/problemset/problem/707/D 题目大意: 一个N*M的书架,支持4种操作 1.把(x,y)变为有书. 2.把(x,y)变为没书. 3.把x行上的所有书状态改变,有变没,没变有. 4.回到第K个操作时的状态. 求每一次操作后书架上总共多少书. 题目思路: [离线][深搜][树] 现场有思路不过没敢写哈.还是太弱了. 总共只用保存一张图,把操作看成一棵树,一开始I操作连接在I-1操作后,如果遇到操作4的话,把I操作与I-1操…
[题目链接] http://codeforces.com/problemset/problem/707/D [题目大意] 给出一个矩阵,要求满足如下操作,单个位置x|=1或者x&=0,一行的数全部取反,回到第k个操作.要求每次操作后输出这个矩阵中数字的和. [题解] 由于存在操作回溯,考虑使用可持久化数据结构或者建立离线操作树.因为懒,没写持久化.对于每个操作,将它和时间顺序上的上一个节点连边,这样子就形成了一棵树,对这棵树从根节点开始遍历,递归处理,每次处理完一棵子树就回溯操作,这样子就能离线…
$dfs$,优化. $return$操作说明该操作完成之后的状态和经过操作$k$之后的状态是一样的.因此我们可以建树,然后从根节点开始$dfs$一次(回溯的时候复原一下状态)就可以算出所有状态的答案. 对于$1$和$2$操作,可以开一个数组$a[i][j]$记录每一格子被操作$1$和$2$操作了几次. 然后开一个数组$r[i]$记录每一行被操作$3$操作了几次. 每一格真正的状态为$\left( {a\left[ i \right]\left[ j \right] + r\left[ i \ri…
比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注冊的时候非常想好好的做一下,可是网上喝了个小酒之后.也就迷迷糊糊地看了题目,做了几题.一觉醒来发现rating掉了非常多,那个心痛啊! 只是.后来认真的读了题目,发现这次的div2并非非常难! 官方题解:http://codeforces.com/blog/entry/13568 A. Appleman and Easy Task 解析:         一个水题,推断每一个细胞周围是否都是有偶数…
Recently in school Alina has learned what are the persistent data structures: they are data structures that always preserves the previous version of itself and access to it when it is modified. After reaching home Alina decided to invent her own pers…
J. Deck Shuffling Time Limit: 2   Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/problem/J Description The world famous scientist Innokentiy continues his innovative experiments with decks of cards. Now he has a deck of n cards and k…
Problem A. Poetry Challenge Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/attachments Description Let’s check another challenge of the IBM ICPC Chill Zone, a poetry challenge. One says a poetry string that starts with a…
题目链接:http://codeforces.com/contest/580/problem/C #include<cstdio> #include<vector> #include<cstring> #define MAX 100010 using namespace std; vector <int> a[MAX]; int visit[MAX]; int cat[MAX]; int leaf[MAX]; int ans,m; void dfs(int…