组队选拔赛01 ---- slom
来源:互联网 发布:戴尔软件开发公司简介 编辑:程序博客网 时间:2024/06/05 00:17
Problem Description
Little Marin spent all his day generating test data for FOJ. He simply couldn’t make it work, so he had a nervous breakdown and can’t even see clearly anymore. Every time he blinks while reading, the letters in a word get mixed up so that the letters from the second half of the word (the shorter half, if the length is an odd number) “jump in” between the letters from the first half in the following way:
· the last letter “jumps in” between the first and the second letter
· the penultimate letter “jumps in” between the second and the third letter
· the k-th letter from the end “jumps in” between the k-th and the (k+1)-th letter from the beginningFor example, the word “abcdef” would become “afbecd” after blinking.
If Marin blinks again, the same thing happens. After two blinks, the word “abcdef” becomes “adfcbe”.Marin has decided to write a program to help him determine what’s exactly written on the screen.
Unfortunately, after a day’s work, he’s simply too tired and he needs your help. You are given X, the number of blinks, and the word Marin sees on the screen. Write a program to solve the mystery for Marin and determine what was actually the word before he blinked X times.
Input
There are multiple test cases. Please process till EOF.
The first line of input contains a positive integer X (1 ≤ X ≤ 1 000 000 000), the number of times Marin blinked.The second line of input contains the word from the screen, its length being from the interval [3, 1000].
The word will consist only from small letters of English alphabet.
Output
The first and only line of output must contain the original word, before Marin blinked X times.
Sample Input
4
acefdb
1000
aaaaaa
11
srama
Sample Output
abcdef
aaaaaa
sarma
解题思路
题意 一个字符串 经过x次操作 后,会变成哪个串…
首先x的数据规模达到了10^9,直接模拟的话 肯定会超时.
所以 我们可以去找规律— 一个字符串最少要操作次数T后,才能恢复为原来的串
那么 最后只要对 x%T 的次数 进行模拟就行了
参考代码
#include <iostream>#include <string>using namespace std;typedef __int64 ll;int arr[1010],a[1010],t[1010];int main(){ ll x; string s; for (int N = 3;N <= 1000;N++){ int cur = 2; int cnt = 0; while (true){ if (cur%2 == 0) cur = N-cur/2+1; else cur = cur/2+1; cnt++; if (cur == 2) break; } arr[N] = cnt; } while (cin >> x){ cin >> s; int len = s.size(); int left = x%arr[len]; for (int i = 0;i <= len;i++) a[i] = t[i] = i; for (int i = 0;i < left;i++){ for (int j = 2;j <= len;j++) if (j%2 == 0) a[len-j/2+1] = t[j]; else a[j/2+1] = t[j]; for (int j = 1;j <= len;j++) t[j] = a[j]; } for (int i = 0;i < len;i++) cout << s[a[i+1]-1]; cout << endl; } return 0;}
- 组队选拔赛01 ---- slom
- 组队选拔赛01 ---- trener
- 组队选拔赛01 ---- kusac
- 组队选拔赛01 ---- volim
- 组队选拔赛01 ---- misa
- 2015年省赛组队选拔赛1
- 组队选拔赛4场后小结
- 省赛选拔赛——组队赛第一场
- 省赛选拔赛——组队赛第二场
- 省赛选拔赛——组队赛第三场
- 省赛选拔赛——组队赛第四场
- 2014 Multi-University Training Contest 9 -- 组队选拔赛三
- Soj10572 SLOM
- 暑假选拔赛01 ---- Chufa
- 暑假选拔赛01 ---- Prime
- 暑假选拔赛01 ---- code
- 组队
- 2016-2017 ACM-ICPC, NEERC, Northern Subregional Contest 组队选拔赛一
- Spring-02-IOC容器
- 虚函数与多态
- vs2010使用openCV中的imread读不到图片问题的解决方法
- opencv waitKey()详解
- Ajax中向Servlet发送请求时中文乱码问题
- 组队选拔赛01 ---- slom
- 19_Android中图片处理原理篇,关于人脸识别网站,图片加载到内存,图片缩放,图片翻转倒置,网上撕衣服游戏案例编写
- cocos3.2-andoid开发-新手初探-安装配置打包
- Python模块常用的几种安装方式
- String to Integer (atoi)
- CocoaPods安装和使用教程
- Java项目命名
- JavaScript BOM浏览器对象模型
- MySQL-config-slow