Gym 100917L Liesbeth and the String 规律&&胡搞
题目:
Description
Statements
Little Liesbeth likes to play with strings. Initially she got a string of length n, consisting of letters 'a' only.
Then Liesbeth performs next operations with the string:
- If the first letter of the string is 'a', then she adds to the end of the string "bc", and after that removes first two letters of the string.
- If the first letter of the string is 'b', then she adds to the end of the string 'a', and after that removes first two letters of the string.
- If the first letter of the string is 'c', then she adds to the end of the string 'aaa" and after that removes first two letters of the string.
Liesbeth stops when she has the string of length 1. For example, if n = 4, she needs 6 operations :
Liesbeth found that for some n number of operations is too big, and its hard to understand if the process is finite. So she asked You to write the program to help her.
Input
First line of the input contains one integer n (2 ≤ n ≤ 106) — length of the initial string.
Output
Print one integer — number of operations needed to obtain string of length 1. If process is infinite, print - 1 insteaSample Input
4
6
3
24 题目大意:给出一个字符串(只含a)的初始长度,做一下变换,求得到字符串长度为1时的步骤数,变换如下:
1.字符串首字母为a时 字符串末尾加bc 并删除前2个字符
2.字符串首字母为b时 字符串末尾加a 并删除前2个字符
3.字符串首字母为c时 字符串末尾加aaa 并删除前2个字符 题目思路:找规律,
当字符串长度为偶数时:经过n/2步变为只含bc长度为n的形式,再经过n/2步变成只含a长度为n/2的形式
当字符串长度为奇数时:经过(n+1)/2 步变为含c+k(bc)形式长度为n的串,在经过(n+1)/2步变成只含a长度为n/2*3+2的串
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<stdio.h>
#include<stdlib.h>
#include<queue>
#include<math.h>
#define INF 0x3f3f3f3f
#define MAX 10000005
#define Temp 1000000000 using namespace std; int main()
{
long long n,sum;
while(scanf("%lld",&n)!=EOF)
{
sum=;
while(n>)
{
if(n%==)
{
while(n> && n%==)
{
sum+=n;
n/=;
}
} else
{
while(n% && n>)
{
sum+=(n/+);
sum+=(n/+);
n=n/*+;
}
}
}
printf("%lld\n",sum);
}
return ;
}
Gym 100917L Liesbeth and the String 规律&&胡搞的更多相关文章
- HDU 4690 EBCDIC (2013多校 1005题 胡搞题)
EBCDIC Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Others)Total Su ...
- [LeetCode]Integer Break(Dp或胡搞或推公式)
343. Integer Break Given a positive integer n, break it into the sum of at least two positive intege ...
- 胡搞-强化版的light oj-1055-的思路-AI版的6重暴力For循环的BFS
新题目大意: 三个棋子按照先后顺序,可以随意方向合法地走到空位置上(而不是像原题light oj-1055中的一样三个棋子每次走的方向都一致),当三个棋子全部走进目标地点,就结束:求需要指挥的最少次数 ...
- Codeforces Gym 100015A Another Rock-Paper-Scissors Problem 找规律
Another Rock-Paper-Scissors Problem 题目连接: http://codeforces.com/gym/100015/attachments Description S ...
- Codeforces Gym 100114 A. Hanoi tower 找规律
A. Hanoi tower Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descript ...
- Gym 101981G - Pyramid - [打表找规律][2018-2019 ACM-ICPC Asia Nanjing Regional Contest Problem G]
题目链接:http://codeforces.com/gym/101981/attachments The use of the triangle in the New Age practices s ...
- Codeforces Gym 100425D D - Toll Road 找规律
D - Toll RoadTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view ...
- codeforces Gym 100418D BOPC 打表找规律,求逆元
BOPCTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?c ...
- HDU 4681 String 胡搞
设串C的第一个字母在串A中出现的位置是stA, 串C的最后一个字母在串A中出现的位置是edA. 设串C的第一个字母在串B中出现的位置是stB, 串C的最后一个字母在串B中出现的位置是edB. 求出每一 ...
随机推荐
- 3.通过js代码设置css样式
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- priority_queue 优先队列
优先队列是单向队列的一种,可以按照默认或自定义的一种方式来对队列中的数据进行动态排序 template<class _Ty, class _Container = vector<_Ty&g ...
- javascript显式类型的转换
显式类型转换目的:为了使代码变得清晰易读,而做显示类型的转换常使用的函数:Boolean(),String(),Number()或Object()如:Nunber(5) //5String(true) ...
- Linux下gcc编译生成动态链接库*.so文件并调用它【转载】
动态库*.so在linux下用c和c++编程时经常会碰到,最近在网站找了几篇文章介绍动态库的编译和链接,总算搞懂了这个之前一直不太了解得东东,这里做个笔记,也为其它正为动态库链接库而苦恼的兄弟们提供一 ...
- 实现ie6下的居中
代码如下所示,转自 http://w3help.org/zh-cn/causes/RT8003 对于 text-align 的讨论. <div style="width:200px; ...
- HDU3371--Connect the Cities(最小生成树)
Problem Description In 2100, since the sea level rise, most of the cities disappear. Though some sur ...
- 分珠(dfs+并查集)
1140 分珠 时间限制:500MS 内存限制:65536K提交次数:24 通过次数:18 题型: 编程题 语言: G++;GCC Description 如下图所示,有若干珠子,每颗珠子重量不 ...
- android Handler vs Timer
Handler vs Timer 在我们Android开发过程中,经常需要执行一些短周期的定时任务,这时候有两个选择Timer或者Handler.然而个人认为: Handler 在多个方面比Timer ...
- 关于个人网站选择虚拟主机还是VPS服务器的讨论
还记得当初才开始学习建站的时候,选择的第一款虚拟主机是全HTML的主机,那时候的虚拟主机还分为HTML或者是ASP,PHP的都很少,在国内接触的学习较多还是以ASP为主,PHP是最近几年才开始流行.如 ...
- UVA 10480 Sabotage
最小割+输出方案 #include<cstdio> #include<cstring> #include<string> #include<cmath> ...