UVaLive 7637 Balanced String (构造)】的更多相关文章

题意:给定一个括号的序列,原先的序列是碰到左括号加1,碰到右括号减1,然后把序列打乱,让你找出字典序最小的一个答案. 析:直接从第一个括号判断就好了,优先判断左括号,如果不行就加右括号. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cma…
原题链接 题意:给出一个打乱顺序的序列,问是否能构造出一个括号匹配的字符串.每个数字为此前读取到的左括号数减去右括号数. 分析:有左括号开始构造,不够的话就找右括号.注意特殊情况待处理.详情看代码 #include <iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<queue> #include<s…
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=5659 题意: 你有一个只包含"(" 和 ")" 的串,每一个位置有个数值,这个数值是当前的左括号-右括号的值. 例:()() 数值就是1010. 给你一个打乱了的数值,要你构造出字典序最小的字符串. 题解: 因为左括号比右括号…
题目传送门 /* 贪心:按照0或1开头,若不符合,选择后面最近的进行交换.然后选取最少的交换次数 */ #include <cstdio> #include <algorithm> #include <cstring> #include <string> #include <cmath> #include <vector> #include <map> #include <queue> using namesp…
题目链接: D. Recover the String time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output For each string s consisting of characters '0' and '1' one can define four integers a00, a01, a10 and a11, where …
题目链接:点击打开链接 题意: 给定一个n*n的01矩阵 我们跑一下例子== 4 0111 0000 0100 0110 0123 \|____ 0|0111 1|0000 2|0100 3|0110 用0-n-1随便构造一个序列: 如:1230 我们计算1230的权值 : int ans = 0; 对于个位0,我们查找第0行:0111,0前面的数有123, 则ans += a[0][1], ans+=a[0][2], ans+=a[0][3] 对于十位3.我们查找第3行:0110.3前面的数有…
String类创建对象的方法可以分为以下三种 1.String a = "123"; 2.String b = new String("123"); 3.String c = "12" + "3"; 1程序执行时,会先去jvm的常量池(在方法区中)中寻找有没有"123" 的String 对象,如果已经存在,则无须新建对象,直接把常量池中的对象地址返回给栈中的引用 a (此时没有建立对象) 如果没有存在,则在…
B. Recover the String 题目连接: http://www.codeforces.com/contest/708/problem/B Description For each string s consisting of characters '0' and '1' one can define four integers a00, a01, a10 and a11, where axy is the number of subsequences of length 2 of…
原题链接在这里:https://leetcode.com/problems/replace-the-substring-for-balanced-string/ 题目: You are given a string containing only 4 kinds of characters 'Q', 'W', 'E' and 'R'. A string is said to be balanced if each of its characters appears n/4 times where…
题意 B - Balanced Neighbors 给定一个整数 $N$($3\leq N \leq 100$),构造一个顶点编号为 $1...N$ 的无向图,需满足如下两个条件: 简单图且连通 存在一个整数 $S$,使得对于每个顶点,与其相连的顶点的编号和都为 $S$ 可以证明至少有一个满足上述条件的图,请输出这样的图. 分析 手动尝试一下 $n=3,4,5$,可以找到一个构造方法. 考虑完全 $k$ 分图(类比完全二分图),并保证这 $k$ 部分的和都相等. 如果 $n$ 为偶数,那么我们可…