Canada Cup 2016 C. Hidden Word 构造模拟题
http://codeforces.com/contest/725/problem/C
Each English letter occurs at least once in s.
注意到题目有这样一句话,那么就是说S中只有一个重复的字母。一定要看到这句话,不然做不了。
然后就找到pos1和pos2分别代表那两个字母的位置,把他们中间的所有字母对折一下,放在最右边就可以了。因为这样才能用上同一个位置。
只有连续两个相同的字母才会impossible,同样是因为只有两个相同的字母。
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
const int maxn = + ;
char str[];
int book[maxn];
char ans[maxn][maxn];
void work() {
// for (int i = 1; i <= 2; ++i) {
// for (int j = 1; j <= 13; ++j) {
// ans[i][j] = 'a';
// }
// }
scanf("%s", str + );
for (int i = ; i <= ; ++i) {
book[str[i]]++;
}
int pos[];
int cur = ;
for (int i = ; i <= ; ++i) {
if (book[str[i]] == ) pos[cur++] = i;
}
if (pos[] == pos[] - ) {
cout << "Impossible" << endl;
return;
}
// cout << pos[1] << " " << pos[2] << endl;
int ff = pos[];
int len = pos[] - pos[] - ;
int t = len / ;
ans[][ - t] = str[pos[]];
for (int i = - t + ; i <= ; ++i) {
ans[][i] = str[++ff];
}
int flag = (len % ) == ;
for (int i = ; i >= - t + flag; --i) {
ans[][i] = str[++ff];
} int to = - t - ;
cur = ;
if (to <= ) {
cur = ;
to = ;
}
for (int i = pos[] + ; i <= ; ++i) {
ans[cur][to] = str[i];
if (cur == ) to++;
else to--;
if (to <= ) {
to = ;
cur = ;
}
}
for (int i = ; i <= pos[] - ; ++i) {
ans[cur][to] = str[i];
if (cur == ) to++;
else --to;
if (to <= ) {
to = ;
cur = ;
}
}
for (int i = ; i <= ; ++i) {
for (int j = ; j <= ; ++j) {
cout << ans[i][j];
}
cout << endl;
}
} int main() {
#ifdef local
freopen("data.txt","r",stdin);
#endif
work();
return ;
}
Canada Cup 2016 C. Hidden Word 构造模拟题的更多相关文章
- Canada Cup 2016 C. Hidden Word
C. Hidden Word time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- 【Codeforces Round 725】Canada Cup 2016
模拟Canada Cup 2016,ABC三题,Rank1376 第三题卡住了 Codeforces 725 C 求出两个相同字符的位置,记为x和y. 然后考虑把相同的那个字符放在第一行的什么地方, ...
- Codeforces Canada Cup 2016
A. Jumping Ball time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- Canada Cup 2016 D. Contest Balloons 好题。优先队列 + 简单贪心
http://codeforces.com/contest/725/problem/D 这题一看就是贪心的了,w - t最小的那个,肯定是优先打死. 但是一直都不会写,为什么呢,因为这个太像二分答案了 ...
- CodeForces Canada Cup 2016【A,B,C,D】
CodeForces 725A: 思路就是如果"最左"不是'>'这个了,那么这个右边的一定不可能到达左边了: 同理最右: CodeForces 725B: 有两个空姐,一个从 ...
- Canada Cup 2016 D. Contest Balloons
最近好弱做什么题目都是做一晚上 这是合肥站炼铜后遗症? 这题就是贪心 我已开始还写了1小时---三分-----. #include<bits/stdc++.h> using namespa ...
- Hidden Word
Hidden Word time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...
- Schlumberger Petrel 2016.3 地震解释 油藏模拟
Schlumberger Petrel 2016.3 地震解释 油藏模拟世界上顶尖的三维地质建模软件,软件为用户提供的工具可以用于地震解释.地质建模.油藏数 值模拟等方面的使用,清晰的地质模型可以描述 ...
- 剑指Offer——网易校招内推笔试题+模拟题知识点总结
剑指Offer--网易校招内推笔试题+模拟题知识点总结 前言 2016.8.2 19:00网易校招内推笔试开始进行.前天晚上利用大约1小时时间完成了测评(这个必须做,关切到你能否参与面试).上午利用2 ...
随机推荐
- Call to unavailable function 'system': not available on iOS
使用Xcode 9 导入cocos2d-x 项目,报错 Call to unavailable function 'system': not available on iOS 原因很简单,就是ios ...
- 洛谷 P3804 [模板] 后缀自动机
题目:https://www.luogu.org/problemnew/show/P3804 模仿了一篇题解,感觉很好写啊. 代码如下: #include<cstdio> #include ...
- WPF ValidationRule 触发ErrorTemplate 的注意事项
ValidationRule 验证时, 当验证失败后,再次验证成功, errorTemplate 还是触发, 不会被清掉. 因此需要主动调用 Validation.ClearInvalid(dtpTe ...
- 一致性哈希算法原理、避免数据热点方法及Java实现
一致性哈希算法在1997年由麻省理工学院提出的一种分布式哈希(DHT)实现算法,设计目标是为了解决因特网中的热点(Hot spot)问题,初衷和CARP十分类似.一致性哈希修正了CARP使用的简 单 ...
- C# 使用 MemoryStream 将数据写入内存
转自:http://blog.csdn.net/andrew_wx/article/details/6629951 常用的MemoryStream构造函数有以下3种. 1:MemoryStream() ...
- angular学习的一些Mark
http://www.cnblogs.com/xianrongbin/p/4104596.html http://angular-ui.github.io/
- 11_listview入门
listview是在安卓开发当中很常用的API. 以垂直滚动的列表的方式展示条目的控件. ListAdapter是一个桥梁,给ListView提供数据的.数据是由适配器来进行提供的.Adapter是数 ...
- 《精通Spring4.X企业应用开发实战》读后感第四章
- SQL中的drop,truncate和delete的区别
(1) DELETE语句执行删除的过程是每次从表中删除一行,并且同时将该行的删除操作作为事务记录在日志中保存以便进行进行回滚操作.TRUNCATE TABLE 则一次性地从表中删除所有的数据并不把 ...
- PHP中error_reporting()函数的用法(修改PHP屏蔽错误)
一般在默认的普通PHP文件中输出一个未定义声明的变量是不会报错误的,但在codeigniter框架下却要报错误,这对于想集成 添加 和 修改 页面于一体的”懒人”很不方便,由于是初学者开始还想怎么在代 ...