题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5812 Description In number theory, a prime is a positive integer greater than 1 that has no positive divisors other than 1 and itself. The distance between two positive integers x and y, denoted by…
Count and Say 思路:递归求出n - 1时的字符串,然后双指针算出每个字符的次数,拼接在结果后面 public String countAndSay(int n) { if(n == 1) return "1"; String front = countAndSay(n - 1); int i = 0; int j = 0; String res = ""; int count = 0; while(j < front.length()){ whi…
排序+构造+预处理 #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; + ; int n, m; int a[maxn], ans[maxn]; int op[maxn], e[maxn]; int pos[maxn]; int first, last; int flag; int p; int tot; bool cmp(c…
poj.org/problem?id=1339 #include<iostream> #include<cstdio> #include<string> #include<cstring> #include<algorithm> #include<queue> using namespace std; int n; ; int main(){ int T; scanf("%d",&T); while(T--…
C. Bear and String Distance time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Limak is a little polar bear. He likes nice strings - strings of length n, consisting of lowercase English letter…
B. Clique Problem time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The clique problem is one of the most well-known NP-complete problems. Under some simplification it can be formulated as f…