A.题意就是把字符串里面的数字按增序排列,直接上代码。
复制代码
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#include <string.h> #include <stdio.h> #include <algorithm> using namespace std; int main() { char s[1005]; int num[105]; while (scanf("%s" , s) != EOF) { int l = strlen(s); int t = 0; int cnt = 0; for (int i = 0; i <= l; i++) { if (s[i] == '+' || !s[i]) { num[++cnt] = t; t = 0; continue; } t = t*10 + s[i]-'0'; } sort(num+1, num+cnt+1); for (int i = 1; i < cnt; i++) printf("%d+", num[i]); printf("%dn", num[cnt]); } return 0; }
B.题意,有n个房子顺时针排成一圈,标号从1到n,只能顺时针走,要按次序到达规定的位置,从一个房子到旁边的房子需要1单位的时间,求总共要多长时间(注意要用64位整形)
复制代码
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#include <iostream> #include <stdio.h> #include <string.h> #include <algorithm> #include <math.h> #include <stdlib.h> using namespace std; int a[100005]; int main() { int n, m; __int64 ans; a[0] = 1; while (scanf("%d %d", &n, &m) != EOF) { ans = 0; for (int i = 1; i <= m; i++) { scanf("%d", &a[i]); if (a[i] >= a[i-1]) ans += (__int64)(a[i] - a[i-1]); else ans += (n-a[i-1]+a[i]); } printf("%I64dn", ans); } return 0; }
最后
以上就是简单小笼包最近收集整理的关于codeforces 339A.Helpful Maths B.Xenia and Ringroad 两水题的全部内容,更多相关codeforces内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复