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 ...
随机推荐
- Git学习记录--git仓库
Git是一款强大的版本控制工具,与svn相比git的分布式提交,本地仓库等在使用时确实比较方便.当然两者之间各有优劣,我在这里不多做比较.由于之前少有接触git,只是零星大致地了解一点,所以找时间系统 ...
- Netty 拆包粘包和服务启动流程分析
Netty 拆包粘包和服务启动流程分析 通过本章学习,笔者希望你能掌握EventLoopGroup的工作流程,ServerBootstrap的启动流程,ChannelPipeline是如何操作管理Ch ...
- 关于富文本在Android中的应用以及遇到的坑
富文本可以为用户提供更加多样化的文本展示形式,但由于其使用了H5标签的特殊性,一般都需要第三方框架的支持.这里推荐一款合适的第三方富文本框架,richeditor. 首先我们要使用该功能需要引入相关j ...
- 11_什么是sql注入?
什么是sql注入? --因为后台会把用户输入的插入到后台的sql语句中,来进行sql查询判断用户输入是否存在数据库中, 来验证用户是否合法,就会出现一个问题,用户在做用户验证的时候,在输入框注 ...
- php微信扫码支付
一 概述 扫码支付是商户系统按微信支付协议生成支付二维码,用户再用微信"扫一扫"完成支付的模式.该模式适用于PC网站支付.实体店单品或订单支付.媒体广告支付等场景.前几天公司需要做 ...
- @@IDENTITY详细测试
今天看数据库SQL,有发现存储过程中有使用到SCOPE_IDENTITY()这个函数,后来问了下谷歌大婶,搜到一个比较重要的博客,链接如下:https://dotblogs.com.tw/kkman0 ...
- Java8内存模型—永久代(PermGen)和元空间(Metaspace)(转)
Java8内存模型—永久代(PermGen)和元空间(Metaspace) 查看原文点击传送门:http://www.cnblogs.com/paddix/p/5309550.html 提示:本文做了 ...
- grep的小技巧
grep '^[^#]' /etc/openvpn/server.conf 中括号必须匹配一个字符^$属于标志位,不属于字符 grep没把\n看成字符 grep把空行看成^$ 还是perl的标准,空行 ...
- Linux 系统监控常用命令
简介 列举操作系统级监控常用的几个方法,建议收藏使用 CPU top 命令可用于监控系统整体负载,包括cpu.内存使用等,能够实时显示系统中各个进程的资源占用状况 输出样例 top - 19:37:4 ...
- 【django之orm小练习】
作业1 创建单表Book表,要求字段: 1 主键 nid 2 书名 title 3 价格 price 4 出版日期 pubDate 5 出版社 publisher(普通字符串字段) class Boo ...