F - The Fun Number System(第二季水)
Description
Input
Output
Sample Input
2
3
pnp
6
4
ppnn
10
Sample Output
Impossible
1110 这个题~ 我这么笨 一定想不到简单的方法!!! 只有各种复杂办法 基本是不可行的
所以 必然需要求助!! 思路
1.n为奇数 最后一位一定是1,因为只有2的0次方可产生奇数,其他都为偶数。
最后一位若为p(正) 则n=(n-1)/2
若为n(负) 则n=(n+1)/2
n为偶数 最后一位一定是0,n=n/2
2.接下来判断倒数第二位 将其重复步骤1,直至判断完这个字符串系统
最后n若为0 则可表示出
n不为0 则结果为impossible 代码是这样
#include<iostream>
#include<string>
using namespace std;
int main() {
int t,k; cin>>t;
while(t--){
__int64 n;
string str;
cin>>k>>str>>n;
int j=;
int *p=new int[k];
for(int i=k-;i>=;i--){
if(n%==||n%==-){
if(str[i]=='p')n=(n-)/;
else n=(n+)/;
p[j++]=;
}
else {
n/=;
p[j++]=;
}
}
if(n)cout<<"Impossible"<<endl;
else {
for(int i=j-;i>=;i--)cout<<p[i];
cout<<endl;
}
delete []p;
}
//system("pause");
return ;
}
F - The Fun Number System(第二季水)的更多相关文章
- E - Number Sequence(第二季水)
Description A single positive integer i is given. Write a program to find the digit located in the p ...
- D - Counterfeit Dollar(第二季水)
Description Sally Jones has a dozen Voyageur silver dollars. However, only eleven of the coins are t ...
- I - Long Distance Racing(第二季水)
Description Bessie is training for her next race by running on a path that includes hills so that sh ...
- Y - Design T-Shirt(第二季水)
Description Soon after he decided to design a T-shirt for our Algorithm Board on Free-City BBS, XKA ...
- B - Maya Calendar(第二季水)
Description During his last sabbatical, professor M. A. Ya made a surprising discovery about the old ...
- S - 骨牌铺方格(第二季水)
Description 在2×n的一个长方形方格中,用一个1× 2的骨牌铺满方格,输入n ,输出铺放方案的总数. 例如n=3时,为2× 3方格,骨牌的铺放方案有三种, ...
- R - 一只小蜜蜂...(第二季水)
Description 有一只经过训练的蜜蜂只能爬向右侧相邻的蜂房,不能反向爬行.请编程计算蜜蜂从蜂房a爬到蜂房b的可能路线数. 其中,蜂房的结构如下所示. ...
- G - Reduced ID Numbers(第二季水)
Description T. Chur teaches various groups of students at university U. Every U-student has a unique ...
- L - 辗转相除法(第二季水)
Description The least common multiple (LCM) of a set of positive integers is the smallest positive i ...
随机推荐
- iOS nav加角标
写一个类别加上就可以啦 #import "UIBarButtonItem+Badge.h" #import "BadgeView.h" #import < ...
- VisualStudio2013快捷键
visual studio 2013 是一个基本完整的开发工具集,它包括了整个软件生命周期中所需要的大部分工具,如UML工具.代码管控工具.集成开发环境(IDE)等等.VS 2013 中新增了很多提高 ...
- OpenCV——IplImage
IplImage结构: typedef struct _IplImage { int nSize; /* IplImage大小 */ int ID; /* 版本 (=0)*/ int nChannel ...
- python保留指定文件、删除目录其他文件的功能(2)
在(1)中脚本实现了保留指定文件的功能,但不能删除空目录,在此补上删除空目录的方法 def DeleteEmptyDir(path): for i in range(1,100): for paren ...
- information_schema.collations 学习
information_schema.collations 表中的每一行对应一个排序规则 1.information_schema.collations 表中学用列: 1.id :排序规则的ID 2. ...
- Js函数加括号、不加括号(转)
函数只要是要调用它进行执行的,都必须加括号.此时,函数()实际上等于函数的返回值.当然,有些没有返回值,但已经执行了函数体内的行为,这个是根本,就是说,只要加括号的,就代表将会执行函数体代码. 不加括 ...
- github orgmode
http://blog.nicky1605.com/application-github-page.html http://dayigu.github.io/WhyUseOrgModeToWriteB ...
- Window 点击“X”关闭之后无法show
将Window的属性closeAction设置为hide就可以了. var panel1 = Ext.create('Ext.panel.Panel', { title: 'this is panel ...
- Qt Quick - 开启下一代交互动效原型设计(效果很美,相关系列博文)
http://blog.csdn.net/unixzii/article/details/46501265
- 【转】Ubuntu安装ARM架构GCC工具链(ubuntu install ARM toolchain)最简单办法
原文网址:http://www.cnblogs.com/muyun/p/3370996.html 一.安装ARM-Linux-GCC工具链 只需要一句命令: sudo apt-get install ...