Codeforces Round #253 (Div. 2)
2014-06-20 21:49
218 查看
A. Anton and Letters
地址链接:点击打开链接
思路:找出字符串中不同的小写字母,直接模拟即可
B. Kolya and Tandem Repeat
地址链接:点击打开链接
思路:可以在字符串后添加最多K个字符,找出最大的重复子串,即s[i+len] = s[i]。可以从最长的子串长度来进行枚举,由于最后添加进去的字符可以任意选择,所以只需考虑原本长度内的字符即可,另外添加长度可能会大于字符串原本的长度
D. Andrey and Problem
题目链接:点击打开链接
思路:给主人公一些事件的成功概率,他想恰好只成功一件,问他要选择哪些事件去做,才能让实现的概率最大。
先看只做一件事成功1件的最大概率,再看2件中,3件中,…… 一旦概率没上次高就跳出,就是不知道怎么证明。。。
地址链接:点击打开链接
思路:找出字符串中不同的小写字母,直接模拟即可
#include <iostream> #include <algorithm> #include <stdio.h> #include <string.h> using namespace std; int main() { char s[2000]; char a[2000] = {'\0'}; int cnt = 0; gets(s); for(int i = 0; s[i] != '\0'; i++) { if(s[i] >= 'a' && s[i] <= 'z') { int flag = 1; for(int j = 0; a[j] != '\0'; j++) { if(s[i] == a[j]) { flag = 0; break; } } if(flag == 1) { a[cnt++] = s[i]; } } } cout << cnt << endl; return 0; }
B. Kolya and Tandem Repeat
地址链接:点击打开链接
思路:可以在字符串后添加最多K个字符,找出最大的重复子串,即s[i+len] = s[i]。可以从最长的子串长度来进行枚举,由于最后添加进去的字符可以任意选择,所以只需考虑原本长度内的字符即可,另外添加长度可能会大于字符串原本的长度
#include <iostream> #include <algorithm> #include <stdio.h> #include <string.h> #include <string> using namespace std; int main() { string s; int k; cin >> s; cin >> k; int l = s.length(); int ans = 0; for(int i = (k + l) / 2; i >= 1; i--) { for(int j = 0; j + i * 2 - 1 < k + l; j++) { for(int k = i + j; k < j + i * 2 && k < l; k++) { if(s[k] != s[k - i]) goto hehe; } ans = max(ans, i); hehe: ; } } cout << ans * 2 << endl; return 0; }
D. Andrey and Problem
题目链接:点击打开链接
思路:给主人公一些事件的成功概率,他想恰好只成功一件,问他要选择哪些事件去做,才能让实现的概率最大。
先看只做一件事成功1件的最大概率,再看2件中,3件中,…… 一旦概率没上次高就跳出,就是不知道怎么证明。。。
#include <iostream> #include <algorithm> #include <stdio.h> #include <string.h> #include <string> using namespace std; double sum = 0 , ans = 0; double a[300]; int n; int main() { scanf("%d", &n); double ans = 0, ss = 0; for(int i = 0; i < n; i++) scanf("%lf", &a[i]); sort(a, a + n); ans = a[n - 1]; ss = 1.0 - ans; for(int i = n - 2; i >= 0; i--) { sum = ans * (1 - a[i]) + ss * a[i]; if(sum > ans) ans = sum; else break; ss *= (1 - a[i]); } printf("%.12lf\n", ans); return 0; }
相关文章推荐
- Codeforces Round #253 (Div. 2) D题
- Codeforces Round #253 (Div. 2) A. Anton and Letters
- Codeforces Round #253 (Div. 2) D. Andrey and Problem
- Codeforces Round #253 (Div. 1) (A, B, C)
- codeforces round #253 div1
- Codeforces Round #253 (Div. 1)D题
- Codeforces Round #253 (Div. 1) A. Borya and Hanabi 暴力
- Codeforces Round #253 DIV1 C 馋
- Codeforces Round #253 (Div. 2)B(暴力枚举)
- Codeforces Round #253 (Div. 2) A. Anton and Letters
- Codeforces Round #253 (Div. 2) —— B
- Codeforces Round #253 (Div. 2) C Borya and Hanabi (思维+bitmask)
- Codeforces Round #253 (Div. 2) B - Kolya and Tandem Repeat
- Codeforces Round #253 (Div. 2)——Borya and Hanabi
- Codeforces Round #253 (Div. 1) (A, B, C)
- Codeforces Round #253 (Div. 1) A Borya and Hanabi
- Codeforces Round #253 (Div. 2)
- Codeforces Round #253 (Div. 2), problem: (B)【字符串匹配】
- Codeforces Round #253 (Div. 1) A Borya and Hanabi
- Codeforces Round #253 (Div. 2)——Borya and Hanabi