You are given three integers a, b and x. Your task is to construct a binary string s of length n=a+b such that there are exactly a zeroes, exactly b ones and exactly x indices i (where 1≤i<n) such that si≠si+1. It is guaranteed that the answer always…
2037. Richness of binary words 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=2037 Description For each integer i from 1 to n, you must print a string si of length n consisting of letters 'a' and 'b' only. The string si must contain exactly i dis…
题目链接: http://acm.hust.edu.cn/vjudge/problem/48421 Binary Tree Time Limit: 3000MS 问题描述 Binary Tree is a tree data structure where each node has at most two children, usually they are distinguished as left and right child. And the node having the child…
Description In computer science, a binary tree is a tree data structure in which each node has at most two children. Consider an infinite full binary tree (each node has two children except the leaf nodes) defined as follows. For a node labelled v it…
题意:给一个这样的二叉树,每个节点用一对数(a,b)表示,根节点为(1,1).设父亲为(a,b),左儿子(a+b,b),右儿子(a,a+b). 给几组数据,(i,j),求从根节点到(i,j)节点需要向左子树走多少次,往右子树多少次.思路:可以发现:当i>j时,(i,j)为左儿子;当i<j时,(i,j)为右儿子.    设父节点为(a,b),往左子树需要走l次,往右子树需要走r次,那么:    1.i>j时:i=a+b,j=b -> a=i-j,b=j l++;    2.i<…
题意:给你一个字符串\(s\),原字符串为\(w\),如果\(i>x\)且\(w_{i-x}=1\),那么\(s_{i}=1\),如果\(i+x\le n\)且\(w_{i+x}=1\),那么\(s_{i}=1\),否则\(s_{i}=0\).求\(w\)的一种可能的情况. 题解:对于\(s\)中的\(0\),我们知道,它左右两边距离\(x\)的地方一定都是\(0\),所以我们先假设\(w\)全为\(1\),然后再更新\(s_{i}\)为\(0\)的情况,最后判断一下\(1\)的情况在\(w\)…
题意:给你n,x,均不超过10^5,让你构造一个无重复元素的n个元素的非负整数集合(每个元素不超过10^6),使得它们的Xor和恰好为x. 如果x不为0: 随便在x里面找一个非零位,然后固定该位为0,其他位随意填写,恰好弄出n-1个数来,然后对这n-1个数求xor和,记作sum,再输出x xor sum即可.由于只有最后一个数的该位为1,所以必然可以保证不重. 如果x为0: 如果n不能被4整除,那么输出0 ~ n-2,然后记这些数的异或和为sum,再输出(1<<18)|sum,以及1<&…
Minimum palindrome Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 260    Accepted Submission(s): 127 Problem Description Setting password is very important, especially when you have so many "in…
E. Vasya and Binary String 链接 分析: 对于长度为x的一段序列,我们可以dp出消除的过程的最优方案,背包即可. 然后区间dp,可以先合并完所有的点,即没相同的一段区间合并为一个点.设f[i][j][k]表示消完区间[i,j]和这段区间后面k个元素最大值,其中k个元素的颜色与点j的颜色相同. 转移:可以首先将j和后面k个元素消除,然后消除[i,j-1].也可以枚举一个和j颜色相同的点m,然后分别先消除[m+1,r-1],剩下的区间就和后面k个连在一起了,再求出这段区间的…
You are given three integers aa, bb and xx. Your task is to construct a binary string ssof length n=a+bn=a+b such that there are exactly aa zeroes, exactly bb ones and exactly xx indices ii (where 1≤i<n1≤i<n) such that si≠si+1si≠si+1. It is guarante…