A.Even Odds
给你n和k, 把从1到n先排奇数后排偶数排成一个新的序列,输出第k个位置的数。
比如 10 3 拍好后就是 1 3 5 7 9 2 4 6 8 10 第3个数是5。
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21//cf 318 A //2013-06-18-20.30 #include <iostream> using namespace std; int main() { __int64 n, k; while (cin >> n >> k) { if (k <= (n+1)/2) cout << (k-1)*2 + 1 << endl; else { k -= (n+1)/2; cout << k*2 << endl; } } return 0; }
B.Sereja and Array
就是找到以“heavy” 开头和“metal”结尾的字符串有多少个。
我的思路是标记“heavy” 和“metal”的位置然后计算以每一个“metal”结尾的有多少个,然后相加。
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46//cf 318 B //2013-06-18-21.01 #include <stdio.h> #include <string.h> #include <iostream> using namespace std; const int maxn = 1000006; char str[maxn]; int s[maxn]; int e[maxn]; int main() { while (scanf("%s", str) != EOF) { memset(s, 0, sizeof(s)); memset(e, 0, sizeof(e)); int l = strlen(str); for (int i = 0; i < l-4; i++) { if (str[i] == 'h' && str[i+1] == 'e' && str[i+2] == 'a' && str[i+3] == 'v' && str[i+4] == 'y') { s[i] = 1; i += 4; continue; } if (str[i] == 'm' && str[i+1] == 'e' && str[i+2] == 't' && str[i+3] == 'a' && str[i+4] == 'l') { e[i] = 1; i += 4; continue; } } __int64 ans = 0; for (int i = 1; i < l; i++) { if (e[i]) ans += s[i-1]; s[i] += s[i-1]; } cout << ans << endl; } return 0; }
最后
以上就是能干豌豆最近收集整理的关于codeforces 318 A.Even Odds B.Sereja and Array的全部内容,更多相关codeforces内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复