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 ...
随机推荐
- 如何 查看 WebLogic Server的版本号[转]
如何 查看 WebLogic Server的版本号[转] WebLogic Server 10gR3为例: 1.查看$BEA_HOME/registry.xml => <c ...
- linux android ndk
Android调用so库, so库是c语言编写, 在linux 64位系统+ndk(32位)生成 lib*.so (32位) 1. 所需软件环境: 1)so库开发环境 操作系统: Redhat Ser ...
- 身份证校验程序(下)- 零基础入门学习Delphi49
身份证校验程序 让编程改变世界 Change the world by program [caption id="attachment_2699" align="alig ...
- 1009 Enigma
本题的重点是理解清楚题意并能代码模拟.形式是二战德国密码机,和数据结构.算法联系较少. #include <stdio.h> #include <string.h> int m ...
- asp.net笔记
1. 复习 a) WebForm前后台页面(aspx, aspx.cs)文件在被访问时,会被编译成类,前台类继承于后台类 b) 被访问时,服务器会创建[前台页面类]对 ...
- 在Qt中怎样显示ASCII码大于127的字符
前段时间要显示“≤”符号找了挺久没找到方法,后面发现用以下方法可以解决: ushort gd[]={8805,0}; QString gteq=QString::fromUtf16(gd); 得 ...
- mysql 事务控制
#!/usr/bin/perl use DBI; $db_name='zjzc'; $ip='127.0.0.1'; $user="root"; $passwd="123 ...
- Linux系统编程(16)——正则表达式入门
字符是计算机软件处理文字时最基本的单位,可能是字母,数字,标点符号,空格,换行符,汉字等等.字符串是0个或更多个字符的序列.文本也就是文字,字符串.说某个字符串匹配某个正则表达式,通常是指这个字符串里 ...
- 【LeetCode练习题】Combination Sum
Combination Sum Given a set of candidate numbers (C) and a target number (T), find all unique combin ...
- tomcat https 未测试成功的版本