bop_2014_round_2b
来源:互联网 发布:阿里云个人邮箱登录 编辑:程序博客网 时间:2024/06/11 22:29
1. 神奇的数列
仔细观察题目对数列的要求,首先确定1和2表示不出来,因为能表示的最小数是3,之后由于题目要求如果有多个数列,输出任意一个即可,所以直接构造即可。
#include <stdio.h>typedef unsigned long long ULL;int main() { int T; ULL N; scanf("%d", &T); for (int c = 1; T--; ++c) { scanf("%llu", &N); if (N < 3) { printf("Case %d: no solution\n", c); continue; } ULL a1, a2, a3; a3 = 1; a2 = N - a3; a1 = a2 * 2; printf("Case %d: %llu %llu %llu\n", c, a1, a2, a3); } return 0;}
2. 字符串压缩
先将串恢复到游程编码之前,之后计算行数,根据行数将串拆分成行存储在vector中,对vector排序比较即可
#include <iostream>#include <sstream>#include <string>#include <vector>#include <algorithm>using namespace std;typedef unsigned ULL;void Split2Rows(string &raw, vector<string> &rows, int L) { rows.clear(); int cl = raw.length() / L; string row; for (int i = 0; i < cl; ++i) { row.clear(); for (int j = i, k = 0; k < L; j += cl, ++k) { row += raw[j]; } rows.push_back(row); } return;}void Recover(string &str, string &raw) { raw.clear(); stringstream ss(str); int num; char tmp; ss >> num >> tmp; //stream只有读超过末尾才会处于错误状态,最后读到的是脏数据 while (ss) { for (int i = 0; i < num; raw += tmp, ++i) {} ss >> num >> tmp; } return;}int main() { int T, L; string str1, str2, raw1, raw2; vector<string> rows1, rows2; cin >> T; for (int c = 1; T--; ++c) { cin >> L >> str1 >> str2; Recover(str1, raw1); Recover(str2, raw2); if (raw1.length() != raw2.length()) { cout << "Case " << c << ": No" << endl; continue; } Split2Rows(raw1, rows1, L); Split2Rows(raw2, rows2, L); sort(rows1.begin(), rows1.end()); sort(rows2.begin(), rows2.end()); if (rows1 == rows2) cout << "Case " << c << ": Yes" << endl; else cout << "Case " << c << ": No" << endl; } return 0;}
0 0
- bop_2014_round_2b
- week 9
- C语言库——静态库、共享库
- C++ Map容器
- sayhello
- bitmap转成字节流
- bop_2014_round_2b
- 函数热身 练习一
- POJ 2208 Pyramids&&HDU 1411 校庆神秘建筑(欧拉四面体公式)
- C++ Set 容器
- Linux中inode的理解
- Libcurl使用OpenSSL编译出现undefined reference to `COMP_CTX_free'错误备忘
- 在asp.net中使用excel模板
- 二叉树的遍历
- 为什么调用 FragmentPagerAdapter.notifyDataSetChanged() 并不能更新其 Fragment?