A. Helpful Maths
题目链接: codeforces 339A
题意:
给个字符串,要求将其中的数字从小到大排序
题解:
简单模拟
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#include <bits/stdc++.h> using namespace std; int main(){ int n, m; string s; while(cin >> s){ int a[105], j = 0; for(int i = 0; i < s.size(); i++){ if(s[i] - '0' == 1 || s[i] - '0' == 2 || s[i] - '0' == 3){ a[j] = s[i]-'0'; j++; } } sort(a, a+j); cout << a[0]; for(int i = 1; i < j; i++){ cout << "+" << a[i]; } cout << endl; } return 0; }
B. Xenia and Ringroad
题目链接:codeforces 339B
题意:
输入 n和m ,第 i 个点的任务只能在 ai 的位置完成,而且只能按顺序完成,往后走一步的花费为 1,求总花费。
4 3
3 2 3
样例说明,总共有4个点,3个任务, 第一个任务只能在 第三个 点完成,第二个任务只能在 第二个 点完成,第三个任务只能在第三个点完成,不能先做第二个任务在完成第一个任务,按顺序进行.
输出6, 从第一个点开始 1 → 2 → 3 (完成第一个任务)→ 4 → 1 → 2(完成第二个任务) → 3(完成第三个任务).
题解:
明显,后一个比前一个的值小,那么它得再走一圈,然后加上最后一个位置
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 2e5 + 5; int main(){ int a[maxn]; ll ans = 0, n, m; cin >> n >> m; for(int i = 1; i <= m; i++){ cin >> a[i]; } for(int i = 2; i <= m; i++){ if(a[i] < a[i-1]){ ans++; } } ans = ans * n + a[m] - 1; cout << ans << endl; return 0; }
最后
以上就是野性老虎最近收集整理的关于codeforces 339A. Helpful Maths,B. Xenia and Ringroad的全部内容,更多相关codeforces内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复