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 ...
随机推荐
- Webform用户控件
用户控件一 用户控件二
- 内存管理pbuf.h头文件源码解析——LwIP学习
声明:个人所写所有博客均为自己在学习中的记录与感想,或为在学习中总结他人学习成果,但因本人才疏学浅,如果大家在阅读过程中发现错误,欢迎大家指正. LwIP的内核(core文件夹)文件中pbuf.c是包 ...
- Random获得的随机数怎么样减少重复率
C#中的Random在获得随机数的时,如果你想要随机循环取得100个随机数则使用如下代码会出现大量的重复数字.代码如下: using System; namespace ConsoleApplicat ...
- (原)Ubuntu14中安装GraphicsMagick
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5661439.html 参考网址: http://comments.gmane.org/gmane.co ...
- [XMPP]iOS聊天软件学习笔记[四]
昨天完成了聊天界面,基本功能算告一段落 开发时间:五天(工作时间) 开发工具:xcode6 开发平台:iOS8 XMPP框架:XMPPFramework git clone https://githu ...
- httrack,webdup,WinHTTrack,WebZip
怎么下载摄像头游戏jabbo,并使其能离线运行?修改 1.摄像头游戏jabbo:JABBO Ultimatum by LiveMurals Interactive电脑为:windows 7 32位.试 ...
- LD1-M(简单图的判定+构造,Havel定理)
题目链接 /* *题目大意: *给出一个图的每个点的度的序列,求能否构成一个简单图,如果能构出简单图,则输出图的邻接矩阵; * *算法思想: *Havel定理的应用; *给定一个非负整数序列{dn}, ...
- express设置ejs并将后缀改为html
http://www.cnblogs.com/-nothing-/p/4943354.html http://blog.csdn.net/macyang/article/details/8841966 ...
- 国际C语言混乱代码大赛代码赏析(一)【转】
本文转载自:http://blog.csdn.net/ce123_zhouwei/article/details/9073869 国际C语言混乱代码大赛代码赏析(一) 近段时间在看<C专家编程& ...
- 第一个MyBatis程序
最近研究了一些MyBatis技术,虽然工作中还未用到,但是觉得了解一下也是不错的.这里记录了第一个简单的Demo程序,防止自己忘记. 第一步需要配置Mybatis-config.xml文件.注意:这里 ...