大意:给定n个长为3的子串, 求一个长为n+2的字符串包含所有子串. 相邻两个字符开一个节点, 建图跑欧拉回路, 若存在的话长度一定是$\le n+2$.…
D. Tanya and Password Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/508/problem/D Description While dad was at work, a little girl Tanya decided to play with dad's password to his secret database. Dad's password is a stri…
Description While dad was at work, a little girl Tanya decided to play with dad characters. She has written all the possible n three-letter continuous substrings of the password on pieces of paper, one for each piece of paper, and threw the password…
[题目链接]:http://codeforces.com/problemset/problem/508/D [题意] 给你一个字符的所有连续3个的子串; 让你复原出原串; (包含小写.大写字母以及数字); [题解] 相当于给你n条边; 每条边的两端; 一个点是由s[0]s[1]组成的; 另一端是s[1]s[2]组成的; (用map很容易做hash..) 然后让你求一个欧拉通路; 即经过所有的边仅一次的路径(一笔画); 有向图; 可以先算出每个点的入度和出度; 设入度和出度的差的点数为1的个数为c…
题目链接 给你n个长度为3的子串, 这些子串是由一个长度为n+2的串分割得来的, 求原串, 如果给出的不合法, 输出-1. 一个欧拉通路的题, 将子串的前两个字符和后两个字符看成一个点, 比如acb, 就是ac->cb. 然后建图. #include <iostream> #include <vector> #include <cstdio> #include <cstring> #include <algorithm> #include…
( ̄▽ ̄)" //不知道为什么,用scanf输入char数组的话,字符获取失效 //于是改用cin>>string,就可以了 //这题字符的处理比较麻烦,输入之后转成数字,用到函数get(char),get_num(string,int) //最后字符的输出是反向输出的,用到函数get_char(int) //这道题也算是到无向图输出欧拉路的模板题,判有无欧拉路用到函数ok() #include<iostream> #include<cstdio> #incl…
[题目链接]:http://codeforces.com/problemset/problem/507/D [题意] 让你找符合这样数字的数的个数: 1.有n个数码 2.某个后缀%k的值为0 3.大于0 [题解] 数位DP; 设f[i][j][0]和f[i][j][1]分别表示; (把最后的数字倒过来) 前i个数字组成的数%k的结果为j; 且前i-1个数字没有出现过%k结果为0; 前i-1个数字有出现过%k结果为0的方案数; 枚举新添加的一位; 看看新的取余值是啥; 然后想一想转移方程就好; d…
题面 传送门 题目大意: 有n条线段,每条线段染红色或蓝色,使得数轴上每个点被红色线段覆盖的次数与被蓝色线段覆盖数差的绝对值小于等于1.输出染色方案. 分析 题意其实可以这样理解: 一段初始全为0 的序列a,给区间[li,ri]" role="presentation">[li,ri][li,ri]+1或-1,使得操作结束后序列中的所有位置绝对值不超过1 可采用差分的思想,给al+1,ar+1−1" role="presentation"&…
A. Pasha and Pixels     题意就是给一个n*m的矩阵,k次操作,一开始矩阵全白,一次操作可以染黑一个格子,问第几次操作可以使得矩阵中存在一个2*2的黑色矩阵.直接模拟即可 代码: #include<cstdio> #include<algorithm> #include<map> #include<cstring> #include<vector> #include<cmath> #include<stri…
Tanya and Toys CodeForces - 659C In Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1 to 109. A toy from the new collection of the i-th type costs i bourles. Tania has…
Tanya and Postcard CodeForces - 518B 有个小女孩决定给他的爸爸寄明信片.她已经想好了一句话(即长度为n的字符串s),包括大写和小写英文字母.但是他不会写字,所以她决定将报纸里的字母剪下来贴到明信片上,最好能够把字符串s拼凑出来.报纸里包含字符串t,包括大写和小写英文字母.我们知道,t的长度大于或等于串s的长度.   如果在s串中的某些位置上的字母能够在报纸串t中找到对应一模一样的字符,那么,她会高兴地喊“耶!”,如果在s串中的某些位置的字母只能在报纸串t中找到…
题目链接:http://codeforces.com/problemset/problem/518/B 题目意思:给出字符串 s 和 t,如果 t 中有跟 s 完全相同的字母,数量等于或者多过 s,就将 s 这个数量加到 YAY! 的答案里,少于的话就加 t 中有的数量:如果 t 中有跟 s 相同的字母但是大小写不对应(例如A-a,z-Z),就加到 WHOOPS 的答案里. 举个例子就很容易明白了.例如 s 和 t 分别为: ncMeXssLHS uwyeMcaFatpInZVdEYpwJQSn…
B. Kolya and Tanya Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/problem/B Description Kolya loves putting gnomes at the circle table and giving them coins, and Tanya loves studying triplets of gnomes, sitting in the v…
C. Tanya and Toys 题目链接http://codeforces.com/contest/659/problem/C Description In Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1 to 109. A toy from the new collectio…
C. Dasha and Password 题目连接: http://codeforces.com/contest/761/problem/C Description After overcoming the stairs Dasha came to classes. She needed to write a password to begin her classes. The password is a string of length n which satisfies the follo…
Codeforces Round #296 (Div. 1)C. Data Center Drama Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xxx  Solved: 2xx 题目连接 http://codeforces.com/contest/528/problem/C Description The project of a data center of a Big Software Company consists of n compu…
\(>Codeforces \space 196\ E. Tricky\ and\ Cleve\ Password<\) 题目大意 : 给出一个有 \(n\) 个结点,\(m\) 条边的连通带权无向图,有k个点设有传送门.开启的传送门可以花费 \(0\) 的代价传送,走一条边要话费等同边权的代价, 一开始,所有传送门关闭, 每当你到达一个有传送门的点,那个传送门就会永久开启, 求从 \(1\) 号点出发开启所有传送门所需的最小代价 \(1 \leq n, m \leq 10^5\) 解题思路…
\(>Codeforces \space 30\ E. Tricky\ and\ Cleve\ Password<\) 题目大意 : 给出一个串 \(S\),让你找出 \(A, B, C\) 三个串,满足 \(C\) 是一个后缀, \(A + B + C\)是一个回文串,\(B\) 是一个长度为奇数的回文串,且 \(A, C\) 可以为空,并最大化 \(|A| + |B| + |C|\) \(1 \leq |S| \leq 10^5\) 解题思路 : 考虑 \(B\) 是不能为空的,不妨先用…
C. Tanya and Toys 题目连接: http://www.codeforces.com/contest/659/problem/C Description In Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1 to 109. A toy from the new col…
原题链接:http://codeforces.com/gym/100431/attachments/download/2421/20092010-winter-petrozavodsk-camp-andrew-stankevich-contest-37-asc-37-en.pdf 题意 给你一个n,让你构造一个环,使得相邻的节点的颜色不一样,问最多能使用多少颜色,并且输出染色方案. 题解 首先,我们来考察对于k个颜色,我们至少需要多少节点.每个点可以连接两个点,将边考虑为有向边,如果我们不浪费任…
题目链接:http://codeforces.com/problemset/problem/761/C C. Dasha and Password time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output After overcoming the stairs Dasha came to classes. She needed to w…
Codeforces 126B. Password 题意:一个字符串,找出最长的子串t,它既是前缀又是后缀,还出现在中间.输出t,不存在则输出Just a legend. 思路:利用KMP算法处理出next数组,由next数组的意义可以知道i为尾的最长相同前缀后缀.则ne[n-1],ne[ne[n-1]],ne[ne[ne[n-1]]]......均为可能的解,且长度递减,为了高效的逐一验证,则需要预处理出整个字符串有多少个与该前缀相同的子串.用到DP思想,cnt[next[i]]+=cnt[i…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output After overcoming the stairs Dasha came to classes. She needed to write a password to begin her classes. The password is a string of length n whi…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output After overcoming the stairs Dasha came to classes. She needed to write a password to begin her classes. The password is a string of length n whi…
Codeforces 题面传送门 & 洛谷题面传送门 果然我不具备融会贯通的能力/ll 看到这样的设问我们可以很自然地联想到这道题,具体来说我们可以通过某种方式建出一张图,然后根据"每个点度都是偶数的图必然每个连通块都存在欧拉回路"这一条件构造出原图的欧拉回路进而求解答案.因此现在问题转化为如何构建出这样一张图出来. 首先一个非常直观的想法是对于每个区间新建一个左部点,对于数轴上每一个整点新建一个右部点,然后从每个区间表示的左部点向这段区间中所有整点表示的右部点连边,这样问题可…
Codeforces 题面传送门 & 洛谷题面传送门 一道非常神仙的题 %%%%%%%%%%%% 首先看到这样的设问,做题数量多一点的同学不难想到这个题.事实上对于此题而言,题面中那个"Classical and Easy"的问题就是那题的弱化版,具体来说,借鉴那题的思路,我们考虑建立一个虚点 \(V\)​,然后对于所有度为奇数的点 \(x\),我们连一条 \(x\) 与 \(V\) 之间的双向边,然后跑欧拉回路.对于每一条原二分图中的边,假设其左部点为 \(x\),右部点为…
Codeforces 题目传送门 & 洛谷题目传送门 u1s1 感觉这个题作为 D1C 还是蛮合适的-- 首先不难发现答案不超过 \(20\),所以可以直接暴力枚举答案并 check 答案是否合法,当然二分也是没问题的,转最优性问题为判定性问题. 考虑怎样判断一个答案 \(k\) 是否合法,由于所有相连的线 \(u,v\) 都有 \(2^k\mid a_u\oplus a_v\),那么 \(a_u\bmod 2^k=a_v\bmod 2^k\) 一定成立.因此我们可以将每个点的权值看作 \(a_…
Codeforces 题目传送门 & 洛谷题目传送门 首先考虑将题目中的条件转化为图论的语言.看到"行""列",我们很自然地想到二分图中行.列转点,点转边的套路,对于每一行 \(x\) 新建一个点 \(R(x)\),对于每一列 \(x\) 也新建一个点 \(C(y)\).考虑对于点 \((x_i,y_i)\),若其被染上红色,就连边 \(R(x_i)\to C(y_i)\),否则连边 \(C(y_i)\to R(x_i)\).那么显然对于每一行而言,其红色格…
B. Tanya and Postcard time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message — string s of le…
Problem One-Way Reform 题目大意 给一张n个点,m条边的无向图,要求给每条边定一个方向,使得最多的点入度等于出度,要求输出方案. 解题分析 最多点的数量就是入度为偶数的点. 将入度为奇数的点每两个组成一队,连一条无向边,之后求出欧拉回路即可. 参考程序 #include <map> #include <set> #include <stack> #include <queue> #include <cmath> #inclu…