POJ 1023 The Fun Number System
Description
A Fun number system is a positional binary number system, where each bit can be either a negabit, or a posibit. For example consider a 3-bit fun number system Fun3, where bits in positions 0, and 2 are posibits, and the bit in position 1 is a negabit. (110)Fun3 is evaluated as 2^2-2^1 + 0 = 3. Now you are going to have fun with the Fun number systems! You are given the description of a k-bit Fun number system Funk, and an integer N (possibly negative. You should determine the k bits of a representation of N in Funk, or report that it is not possible to represent the given N in the given Funk. For example, a representation of -1 in the Fun3 number system (defined above), is 011 (evaluated as 0 - 2^1 + 2^0), and
representing 6 in Fun3 is impossible.
Input
The third line of each test data contains an integer N (-2^63 ≤ N < 2^63), the number to be represented in the Funk number
system by your program.
Output
Sample Input
2
3
pnp
6
4
ppnn
10
Sample Output
Impossible
1110
Source
#include <iostream> using namespace std; int main()
{
int test;
__int64 len, goal;
char str[];
char ans[];
cin >> test;
while (test--)
{
cin >> len >> str >> goal;
ans[len] = '\0';
for (int i = len - ; i >= ; i--)
{
if (goal % == || goal % == -)
{
ans[i] = '';
if (str[i] == 'p') goal = (goal - ) / ;
else goal = (goal + ) / ;
}
else
{
ans[i] = '';
goal /= ;
}
}
if (!goal) cout << ans << endl;
else cout << "Impossible" << endl;
}
return ;
}
POJ 1023 The Fun Number System的更多相关文章
- POJ1023 The Fun Number System
题目来源:http://poj.org/problem?id=1023 题目大意: 有一种有趣的数字系统.类似于我们熟知的二进制,区别是每一位的权重有正有负.(低位至高位编号0->k,第i位的权 ...
- Find n‘th number in a number system with only 3 and 4
这是在看geeksforgeeks时看到的一道题,挺不错的,题目是 Given a number system with only 3 and 4. Find the nth number in th ...
- Moduli number system
A number system with moduli is defined by a vector of k moduli, [m1,m2, ···,mk]. The moduli must be p ...
- F - The Fun Number System(第二季水)
Description In a k bit 2's complement number, where the bits are indexed from 0 to k-1, the weight o ...
- The Stern-Brocot Number System(排序二进制)
The Stern-Brocot Number System Input: standard input Output: standard output The Stern-Brocot tree i ...
- 为什么实数系里不存在最小正数?(Why the smallest positive real number doesn't exist in the real number system ?)
We define the smallest positive real number as the number which is explicitly greater than zero and ...
- POJ #2448 A New Operating System
Time Limit: 20000MS Memory Limit: 65536K Total Submissions: 1165 Accepted: 110 Case Time Limit: ...
- 【POJ】2104 K-th Number(区间k大+主席树)
http://poj.org/problem?id=2104 裸题不说.主席树水过. #include <cstdio> #include <iostream> #includ ...
- poj 3696 The Luckiest Number
The Luckiest Number 题目大意:给你一个int范围内的正整数n,求这样的最小的x,使得:连续的x个8可以被n整除. 注释:如果无解输出0.poj多组数据,第i组数据前面加上Case ...
随机推荐
- sublime text如何保存为uft-8无bom编码格式文件
https://jingyan.baidu.com/article/9158e000388092a2541228b6.html 今天发现自己的文件突然多了很多特殊符号,真是奇了怪,查找html里面也并 ...
- dedecms====phpcms 区别==[工作]
{template "content","header"}{dede:include filename="head.htm"/} ----- ...
- mysql-高性能索引策略
原文转自:http://www.cnblogs.com/happyflyingpig/p/7655762.html 独立索引: 独立索引是指索引列不能是表达式的一部分,也不能是函数的参数 例1: SE ...
- JavaSE-反射-获取类或者对象的四种方法
1.使用Class类的静态方法Class.forName("xxxx"); 新建一个要想要获取的类 package org.burning.sport.javase.classlo ...
- 1_mysql_认识
什么是数据库? -- 数据 -- 处理+存储 信息 -- 数据库 -- 存取数据 软件 本质是对文件系统的上层封装,通过软件去管理文件,管理数 ...
- 前后端分离之CORS和WebApi
目前的项目是前端mv*+api的方式进行开发的,以前都是没有跨域的方案,前后端人员在同一个解决方案里边进行开发,前端人员要用IIS或VS来开发和调试Api,这样就很不方便,迫切需要跨域访问Api. 评 ...
- junit的意义
写了这么久代码了,自己从来没有好好的玩过junit.马上过年了,打算趁这段时间自己来写一套web框架,但是这里有一个很大的尴尬就是我平时编码并没有认真的来写测试类.那么自己在写框架的时候,不测试肯定是 ...
- Linux指令--wget
Linux系统中的wget是一个下载文件的工具,它用在命令行下.对于Linux用户是必不可少的工具,我们经常要下载一些软件或从远程服务器恢复备份到本地服务器.wget支持HTTP,HTTPS和FTP协 ...
- POI--帮助文档
1.创建工作簿 (WORKBOOK) HSSFWorkbook wb = new HSSFWorkbook(); FileOutputStream fileOut = new FileOutputSt ...
- VS中代码覆盖问题
在VS中编写代码时,需要插入代码是,经常是将插入点后面的代码覆盖掉而不是将它向后推. 解决这样的问题,只需要按 Insert 键即可, 我的笔记本是 Fn 加 del