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 ...
随机推荐
- 认识Linux分区
前言 今年目标是熟练Linux系统与内核,没有老司机带只能自己慢慢参照鸟哥教程学习了.如果有老司机麻烦指导一下便捷路线,作为这方便的新手还是很乐意接受各位的意见.今天第一步就是熟悉安装Linux中分区 ...
- ADO.NET复习总结(6)-断开式数据操作
一.基础知识 主要类及成员(和数据库无关的)(1)类DataSet:数据集,对应着库,属性Tables表示所有的表(2)类DataTable:数据表,对应着表,属性Rows表示所有的行(3)类Data ...
- Django将request对象传入模板配置
对于很多时候,需要从模板中获取很请求中很多内容,比如当前请求的url,当前的session变量中的某个值,这时候我们可以通过配置可将request对象传递进模板. django1.10版本: sett ...
- ceph rbd 封装api
1.安装python,uwsgi,nginx环境 pip安装省略 yumgroupinstall"Developmenttools" yuminstallzlib-develbzi ...
- 爬取知名社区技术文章_items_2
item中定义获取的字段和原始数据进行处理并合法化数据 #!/usr/bin/python3 # -*- coding: utf-8 -*- import scrapy import hashlib ...
- awk匹配某一段内容,打印第一段
要求: awk 文本在文本中搜索abc搜到后再从搜到的那一行开始一直输出后面的行,直到某一行含有bcd就停止 测试文本: [root@localhost]# cat awktest sadfj sdj ...
- NIO笔记---上
小弟前端时间由于开发个管理系统导致断更了近20天!!马上就要春招了,学习了一下NIO,将笔记记录下,希望和我一样的18届毕业生都能找到满意的公司!! 本文记录了NIO与IO的区别,缓冲区的数据存取,直 ...
- pat 1014 1017 排队类问题
1.用循环模拟时间 2.采用结构体模拟客户和窗口对象 3.合理处理边界,去除无用信息 4.使用自带排序sort()结合自定义功能函数compare()实现排序
- Windows--查看使用某端口的进程
场景: 有时候我们希望查找某个端口被那个进程使用,如何操作呢? 比如查找8000端口被按个进程使用? 首先使用netstat -ano |grep 8000查看 13776就是使用的进程ID 然后使用 ...
- openstack开发基础