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 ...
随机推荐
- resEdit
resEdit:一个图形界面编辑工具,它不但可以用来编写程序所图形界面(如修改图标.菜单.鼠标.版本信息等),还支持了对exe.dll等执行文件内的资源(图标.菜单.鼠标指针.位图.版本信息)等进行修 ...
- Codeforces 756C Nikita and stack
Codeforces 756C Nikita and stack 题目大意: 给定一个对栈进行操作的操作序列,初始时序列上没有任何操作,每一次将一个本来没有操作的位置变为某一操作(push(x),po ...
- 洛谷 U6931 灯光
题目背景 明天就是校园活动了,小明作为场地的负责人,将一切都布置好了.但是在活动的前几天,校园里的灯却都坏掉了,无奈之下,只好再去买一批灯.但是很遗憾的是,厂家看马上要过年了,就没有在进货了,现在只剩 ...
- 【Lintcode】118.Distinct Subsequences
题目: Given a string S and a string T, count the number of distinct subsequences of T in S. A subseque ...
- 恋恋风辰 对于redis底层框架的理解(一)
近期学习了redis底层框架,好多东西之前都没听说过,算是大开眼界了. 先梳理下redis正常的通讯流程吧 首先服务器启动都有主函数main,这个main函数就在redis.c里 首先是initser ...
- mysql两主多从
1.实现目标 目标清单: 1)Master(192.168.31.230)为正常运行环境下的主库,为两个Slave(192.168.31.231和192.168.31.232)提供“主-从”复制功能: ...
- QListWidget笔记
1.头文件:#include <QListWidget> 2.继承自:QListView 3.基本代码: #include "mainwindow.h" #includ ...
- 存储过程为参数NULL时的处理方法
准备一些数据: SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[Goods]( ) NULL, ) NULL, ...
- python + requests实现的接口自动化框架详细教程
前段时间由于公司测试方向的转型,由原来的web页面功能测试转变成接口测试,之前大多都是手工进行,利用postman和jmeter进行的接口测试,后来,组内有人讲原先web自动化的测试框架移驾成接口的自 ...
- AtCoder Beginner Contest 052
没看到Beginner,然后就做啊做,发现A,B太简单了...然后想想做完算了..没想到C卡了一下,然后还是做出来了.D的话瞎想了一下,然后感觉也没问题.假装all kill.2333 AtCoder ...