【GCJ2016】 round 1A
来源:互联网 发布:怎么认识外国妹子软件 编辑:程序博客网 时间:2024/06/05 14:28
A:The Last Word
题意是给一个字符串,依次取出一个字母,然后将这些字母组成新串,组合的规则,只能放在当前串的串首或者串尾。求字典序最大的新串。
好简单,直接每次判断新取出的字母与当前组成的串的首字母比,比首字母大加到首部,否则加到尾部。
#include <iostream>#include <cstring>#include <cmath>#include <algorithm>#include <cstdio>#include <string>using namespace std;int main(){ //freopen("A-large.in", "r", stdin); //freopen("outAL.txt", "w", stdout); int T; string str; cin >> T; for(int i = 1; i <= T; ++ i) { cin >> str; string ans = ""; ans += str[0]; int len = str.size(); for(int j = 1; j < len; ++ j) { if(str[j] >= ans[0]) { ans = str[j] + ans; } else ans = ans + str[j]; } cout << "Case #" << i << ": " << ans << endl; } //fclose(stdin); //fclose(stdout); return 0;}
B. Rank and File
提议是给出一个2 * n - 1行数,其中这些数矩阵中从左往右递增,从上到下依次递增的的矩阵中的行列。
如 :
1 2 3
2 3 5
3 4 6
这样的一个矩阵,那么给出
1 2 3
2 3 5
3 4 6
1 2 3
2 3 4
求出其中没有列出的那一行或那一列数。
细心的人会发现,矩阵中按照这种规则写出的2 * n行数每个数字出现必为偶数。所以只需要对着2 * n - 1用map保存一下,然后找到个数是奇数的数,最后排序下就得到结果了。
#include <iostream>#include <cstdio>#include <cmath>#include <algorithm>#include <vector>#include <climits>#include <unordered_map>using namespace std;int main(){ //freopen("B-large.in", "r", stdin); //freopen("outBL.txt", "w", stdout); int n, t; cin >> t; for(int i = 1; i <= t; ++ i) { cin >> n; int num; unordered_map<int, int> umap; for(int j = 0; j < 2*n-1; ++ j) for(int k = 0; k < n; ++ k) { cin >> num; umap[num] ++; } unordered_map<int, int>::iterator itr; vector<int> ans; for(itr = umap.begin(); itr != umap.end(); ++ itr) { if(itr->second & 1) ans.push_back(itr->first); } sort(ans.begin(), ans.end()); cout << "Case #" << i << ": " << ans[0]; for(int j = 1; j < ans.size(); ++ j) cout << " " << ans[j]; cout << endl; } //fclose(stdin); //fclose(stdout); return 0;}
0 0
- 【GCJ2016】 round 1A
- TCO13 Round 1A 题解
- TCO 2013 Round 1A
- code strike round 1 A
- 2014 GCJ Round 1A
- codejam 2015 Round 1A
- GCJ Round 1A 2016
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 1)A,B
- 2012 TCO Algorithm - Round 1A
- Codeforces Beta Round #1(A,B)
- Codeforces Beta Round #1 A B C
- Google CodeJam Round 1A 2013
- Codeforces Beta Round #1 A题
- Codeforces Round #202 (Div. 1) A. Mafia
- Codeforces Round #212 (Div. 1) <A>
- Codeforces Round #215 (Div. 1) <A-B>
- Codeforces Beta Round #1 A B C
- Codeforces Round #232 (Div. 1) <A>
- ios多线程操作(九)—— 用NSOperation代替GCD
- 虚拟机对象探秘
- HDU 2071
- 5.3 一致性
- ios多线程操作(十)—— 用NSOperation开启多线程操作
- 【GCJ2016】 round 1A
- 使用ViewPager动画来做出不一样的引导页
- Spring基础知识汇总
- MPAndroidChart图表类框架的使用
- rsync数据备份(二)--RHEL6.5
- 智能计算/计算智能、仿生算法、启发式算法的区别与关系?
- ios多线程操作(十一)—— NSOperation的高级操作
- 一个Java音乐播放器
- 【学习anroid编译】关于运行android模拟器