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 ...
随机推荐
- VS2015预览版中的C#6.0 新功能(一)
VS2015预览版中的C#6.0 新功能(二) VS2015预览版中的C#6.0 新功能(三) VS2015的预览版在11月12日发布了,下面让我们来看看C#都提供了哪些新的功能. 字符串添写(Str ...
- 自己对WSO2 ESB 见解
这周没想到要更新什么内容,就把我最近工作接触的WSO2 ESB简单介绍下吧. 前提: 一切文档,知识都要与官方文档为准. WSO2 ESB: http://wso2.com/products/ ...
- HDU 5815 - Golden Week
题意: 王国地图为 n 个节点的根树,首都为 1, m 个旅行家要去不同的终点旅游,他们分别有各自的预算,如果路上总费用超过预算就不去了 给每条路定价, 让赚的钱最多 分析: DP[i][j]表 ...
- 字符串在 UNICODE、MBCS编码下面的区别
1:SBCS (single byte character set)单字节字符集.在这种编码格式下,所有字符都用一个字节表示.ASCII码就是单字节字符.用“0”来表示一个字节的结束.2 :Unico ...
- python单元测试--深入理解unittest
单元测试的重要性就不多说了,可恶的是python中有太多的单元测试框架和工具,什么unittest, testtools, subunit, coverage, testrepository, nos ...
- uploadify ,前端页面获取值,json,ajax
针对这几月的技术,做一次小总结 上传控件uploadify function inexel() { $("#btnExcel").uploadify({ 'method': 'po ...
- [c language] getopt 其参数optind 及其main(int argc, char **argv) 参数解释
getopt被用来解析命令行选项参数.#include <unistd.h> extern char *optarg; //选项的参数指针extern int optind, //下一次调 ...
- Mysql MERGE 引擎在分表环境下得使用
应用场景:当我们在做分表的时候,通常会把一个大表的数据拆分成若干个分表,这也是数据库优化中的分表概念.随着分表随之而来的问题就是多表查询. 现在有 t1,t2 两张数据表,需要满足不同的查询条件同时从 ...
- C++----练习--string 从文件中一个一个单词的读直到文件尾
从文件中读取单词.并每行显示一个: 1. #include<iostream> #include<string> #include<vector> int main ...
- Maven的使用--Eclipse在线安装Maven插件m2e
我使用的Eclipse版本是3.7(Indigo) 通过Eclipse的help选项,点击“Install New Software...”弹出安装对话框, 点击add按钮,在Location里输入h ...