【GCJ2016】 round 1A
2016-04-16 11:57
253 查看
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; }
相关文章推荐
- ios多线程操作(十)—— 用NSOperation开启多线程操作
- Linux下git源码安装
- 匈牙利算法模板
- VS学习4——计算工资与扣税
- Mac OSX搭建Jenkins持续集成环境
- 位运算符详细总结
- 手把手教你做一个Shell命令窗口
- HDU 5421 Victor and String
- 手把手教你做一个Shell命令窗口
- motto6
- ios多线程操作(九)—— 用NSOperation代替GCD
- 手把手教你做一个Shell命令窗口
- Android日历控件,还未实现点击日期改变背景色但可获取日期
- 二进制原码,反码以及补码实战
- Unity3d 模拟视锥的实现
- 小明传球
- 1、cas4.0 单点登录 之 https证书
- linux 用户环境变量介绍
- ios多线程操作(八)—— GCD调度组
- wordpress发表文章之后查看显示404