G - The Fun Number System解题报告(贺奕凯)

今晚在线论坛GVbbs 5.0 主要特色:自由定制的双风格,分桢讨论区,内含GVBBS4.1版升级包<br> 4.2新增功能<br> 1,论坛进站画面增加双风格显示(完整型/简约型)后台基本信息可以订制<br> 2,主题属性增设了积分贴,用户发帖的时候可以自己订制浏览该贴的分数(主要防止论坛太多潜水员)<br> 3,论坛属性之外增设浏览论坛的用户等级(主要防止论坛太多潜水员),这个可以在论坛后台编辑版面的时候设定。<br> 4,论坛分版内增加了本版在线名单,后台可以订制默认是否打开。<br> 5,论坛前台增加了斑竹禁言功能,后台可以订制是否开发此功能!<br> 6,论坛分类,论坛版面后台新增默认风格属性,自由定制用户首次进入的显示风格。<br> 7,去掉了首次进入本站的cookies支持提示,但是用户登陆仍然需要cookies支持才能登陆。<br> 8,用户等级新增多个属性,管理员定制更加灵活。 <br> 9,后台两级管理员,不限量增加,总管理员可在asp文件内定普通管理员权限<br> 10,此外修复一些Bug<br> 4.3新增功能:<br> 1,社区增加个人媒体库,这样大家既可以灵活的上传、 删除自己的文件,又能节约社区有限的空间。<br> 当您的媒体库满了,你可以自行删除老的文件释放空间,也可以向管理员申请给自己大一些上传空间。<br> 2,后台用户管理增加复杂查询,由于功能强大,查询结构复杂请管理员使用仔细看旁边的注释。<br> 3,后台短信管理增加复杂查询,由于功能强大,查询结构复杂请管理员使用仔细看旁边的注释。<br> 4,后台配色模版新增一个色彩变量,就是主题文章背景色。<br> 5,前台配色我们变动了几个变量位置,这样能更加灵活的发挥您的想象力,使配色方案变化更多,新增了三个配色方案<br> 6,新增帮助文件。<br> 7,修复n多bug<br> 4.3.1新增功能:<br> 1,增加页面预载动画<br> 2,修复前台管理权限混乱<br> 3,修复findpass.asp页面错误处理请求<br> 4,过滤不安全字符<br> 5,修复编辑状态上传无法关闭问题<br> 6,过滤大容量写入or编辑操作<br> 7,论坛用户权限设定(后台)<br> 8,修复其它n个bug<br> 默认管理员 gamvan 默认登陆密码 gamvan 立即下载

G - The Fun Number System
Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u

Description

In a k bit 2's complement number, where the bits are indexed from 0 to k-1, the weight of the most significant bit (i.e., in position k-1), is -2^(k-1), and the weight of a bit in any position i (0 ≤ i < k-1) is 2^i. For example, a 3 bit number 101 is -2^2 + 0 + 2^0 = -3. A negatively weighted bit is called a negabit (such as the most significant bit in a 2's complement number), and a positively weighted bit is called a posibit. 
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 first line of the input file contains a single integer t (1 ≤ t ≤ 10), the number of test cases, followed by the input data for each test case. Each test case is given in three consecutive lines. In the first line there is a positive integer k (1 ≤ k ≤ 64). In the second line of a test data there is a string of length k, composed only of letters n, and p, describing the Fun number system for that test data, where each n (p) indicates that the bit in that position is a negabit (posibit). 
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

For each test data, you should print one line containing either a k-bit string representing the given number N in the Funk number system, or the word Impossible, when it is impossible to represent the given number.

Sample Input

2
3
pnp
6
4
ppnn
10

Sample Output

Impossible
1110

题目链接:http://poj.org/problem?id=1023
算法类型:数论
解题思路:这道题的思路是从最后一位开始判断,如果N是奇数,那么说明最后一位肯定是1。因为只有最后一位才是0次方,才有可能得到唯一的奇数1。这时如果最后那位是+时,就把N-1再除以2,得到前面的k-1位数;如果最后那位是-时,就把N+1再除以2,得到前面的k-1位数。如果N是偶数,可以断定最后一位是0,那么直接除以2得到前面k-1位得到的数。依次循环至剩下0位即可。如果循环完毕N没有等于0,可以判断为impossible,因为可以存在负数,上述考虑都是排除负数的情况,有负数也没关系,判断N%2==-1就行了。
算法实现:


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
__int64 N;    
char P[64];
int Er[64];
int d;
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&d);
		memset(P,0,sizeof(P));
		memset(Er,0,sizeof(Er));
		getchar();
		gets(P);
		scanf("%I64d",&N);
		int i=d-1;
		for(i;i>=0;i--)
		{
			if(N%2!=0)
			{
				Er[i]=1;
			    if(P[i]=='n')
				{N=N+1;
				}
				else
				{N=N-1;}
			    N=N/2;
			}
			else
			{
				Er[i]=0;
				N=N/2;
			}
		}
		if(N==0)
		{
			for(int j=0;j<d;j++)
				printf("%d",Er[j]);
			printf("\n");
		}
		else
		{
			printf("Impossible\n");
		}
	}
	return 0;
}




SAP 物料账前期没有运行的解决方法 If you use the actual costing (material ledger), you must have completely closed all period-end closing operations in the actual costing for the penultimate period prior to the period shift. Use the '... 阅读详情

相关推荐

STM32L431电池供电项目实战:用STOP2模式把功耗降到5uA以下(CubeMX配置详解)

本文详细介绍了如何在STM32L431电池供电项目中利用STOP2模式实现5μA以下的超低功耗设计。通过CubeMX配置、硬件优化和软件策略,成功将农业温湿度监测节点的待机功耗控制在4.7μA,确保CR2032电池供电下3年以上的工作寿命。文章包含完整的低功耗实现路径和实测数据,特别适合物联网边缘设备开发者参考。

weixin_30345577的博客 393

POJ_1023 The Fun Number System解题报告

The Fun Number System Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8173   Accepted: 2640 Description In a k bit 2's complement number, where the bits ar

May_heyikai的专栏 753

一文详解Stata重复测量方差分析的概念、原理、适用情形以及操作命令实现、对结果的解读、操作注意事项 附零基础小白友好入门Stata统计学/计量经济学学习路径

重复测量方差分析(Repeated Measures ANOVA)适用于同一受试者在不同时间点或条件下的多次测量数据,如疗效跟踪和跨条件对比研究。其核心特征包括:数据结构为每个受试者多个观测值,数据具有相关性(违反独立性假设),变异分解为个体间和个体内变异。关键假设包括正态性、方差齐性和球形性(通过Mauchly检验验证)。适用场景包括纵向研究和小样本追踪,但不适用于存在滞留效应或学习效应显著的数据。操作步骤涉及数据准备(宽/长格式转换)、正态性与球形性检验、主分析命令(单/多因素)及事后检验。

m0_72274883的博客 1565

poj 1023 --The Fun Number System(分析题)

The Fun Number SystemTime Limit: 1000MS Memory Limit: 10000K Total Submissions: 6988 Accepted: 2176 Description In a k bit 2's complement number, where the bits are indexed from 0 to k-1, the w

蓝色污点的专栏 3385

【ArcGIS微课1000例】0149:Geographic Imager6.6下载安装教程

首先保证电脑上安装对应版本的PS软件,笔者安装的是PS2023(V24.7)版本,然后安装本软件。保持以上窗口运行状态,然后打开PS,自动弹出如下窗口。勾选【Automatically checkout LIcense】,点击Close。双击setup开始安装,点击【确认】,一路默认安装到底。驱动器:DVD-ROM驱动器(用于DVD版本)处理器:2GHz或更快的英特尔或AMD处理器。安装完成后,将Crack中的所有文件拷贝到。硬盘:600 MB的可用硬盘空间用于安装。内存:4GB内存(建议8GB或更高)。

智慧空间实验室 1217

基于Simulink的电力电子负载特性模拟仿真实例

电阻性负载是最简单的负载形式,其阻抗为纯电阻,电流和电压之间的关系符合欧姆定律。电阻性负载的特点是消耗能量,不会存储能量。本示例将以一个典型的直流电源供电系统为例,展示如何利用Simulink进行不同负载特性的仿真模拟。直流电源:提供固定电压输入。逆变器(可选):根据需要产生PWM调制信号,驱动负载。负载模块:模拟不同类型的负载特性,如电阻性负载、电感性负载和容性负载。测量模块:用于观察负载上的电压和电流波形。系统架构视图plaintext深色版本v| || |

xiaoheshang_123的博客 428

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 of the most significant bit (i.e., in position k-1), is -2^(k-1), and the weight of a bit in any

万豪给给的博客 420

Linux----Ubuntu系统官网下载iso镜像文件

Linux----Ubuntu系统官网下载iso镜像文件

MQ0522的博客 5万+

V - The Fun Number System

In a k bit 2's complement number, where the bits are indexed from 0 to k-1, the weight of the most significant bit (i.e., in position k-1), is -2^(k-1), and the weight of a bit in any position i (0 ≤

whhhzs的博客 219

【AI智能体】Hermes Agent 从部署到项目实战操作详解

Hermes Agent 桌面版从安装到实战操作详解

congge 5130

深度剖析XY2-100与SL2-100协议:解锁激光打标核心技术密码

XY2-100和SL2-100是激光打标领域的两种核心控制协议。XY2-100协议采用串行通信,指令集简单,适合常规打标任务,具有成本优势;SL2-100协议支持更高速率(1Mbps以上),具备曲线插补等高级指令,在精密加工领域表现突出。两者的主要差异体现在数据传输(帧结构、速率)、指令集(功能、数量)、参数调节(范围、精度)和错误处理机制等方面。实际应用中,XY2-100适合简单图形的大批量生产,SL2-100更胜任复杂曲面的高精度加工。选择时需综合考虑打标需求、设备兼容性和成本因素,未来两种协议将持续优

远程部署调试 运行安装 项目调试 二次开发 项目技术新 持续迭代 部分源码免费分享 957

POJ1023_The Fun Number System_模拟二进制运算

The Fun Number System Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 10829   Accepted: 3674 Description In a k bit 2's complement number, where the bits a

弱的奋斗之旅 490

cursor AI代码编辑器IDE对接deepseek模型api;字节ai编辑器trae

参考: https://www.cursor.com/ https://platform.deepseek.com/https://www.cursor.com/下载安装后,注册账号登录即可 再高级里选择设置 再模型这注册模型: 模型名称一定要填正确,url地址填好,最后填上秘钥验证

weixin_42357472的博客 1万+

poj 1023 The Fun Number System

The Fun Number SystemTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 6857 Accepted: 2131<br />DescriptionIn a k bit 2's complement number, where the bits are indexed from 0 to k-1, the weight of the most significant bit (i.e., in position k-1), i

kongming_acm的专栏 889

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

BitmapFun 官方资源库地址

google官方Bitmap 管理,缓存,异步加载 de http://developer.android.com/training/displaying-bitmaps/index.html

程序是有生命的精灵 1026

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

POJ 1023 The Fun Number System

题目大意 10的二进制 8 4 2 1 1 0 1 0 现在给每一个位置一个权重 如果是ppnn 那么就是,10就可以表示为 8 4 -2 -1 1 1 1 0 思路梳理 如果要表示的这个数n是奇数(无论正负),那么最后一个位置一定是1 8 4 -2 -1 - - - 1 接着就需要看 8 4 -2 以及每一个位置了 其实相当于给n/2在以下数列中找 4 2 -1 也可以确定一个位置 但是在 8 4 -2 -1 的时候最后一个位置填了1 比实际的数字少了2 所以需要在原来的数字加上2 也

DUT_LYH 458

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

ACM: 一道简单数论题 (重要的是建…

Biorhythms   Description Some people believe that there are three cycles in a person's life that start the day he or she is born. These three cycles are the physical, emotional, and intellectual cycle

smile_benson 429

(POJ 1183)反正切函数的应用

反正切函数的应用 Description反正切函数可展开成无穷级数,有如下公式 (其中0 使用反正切函数计算PI是一种常用的方法。例如,最简单的计算PI的方法: arctan(1/2)+arctan(1/3)=arctan[(1/2

accode的专栏 1131

一、V - The Fun Number System

V - The Fun Number System POJ - 1023 In a k bit 2's complement number, where the bits are indexed from 0 to k-1, the weight of the most significant bit (i.e., in position k-1), is -2^(k-1), and th...

不知道是些什么东西 338

POJ1023 - The Fun Number System 解题报告

POJ1023 - The Fun Number System 解题报告原题解析特殊的计算系统解题思路示例代码 原题解析 题目的大意为,给定一个长度 k [1, 64] 。 给定一个长度为 k 的字符串 s ,由 p 和 n 组成。 给定一个十进制数 n [-263, 263] 。 求一个二进制数 r ,使得 r 按照一个特殊的计算系统可以算得 n 。 特殊的计算系统 正常来说,将一个二进制数转化为十进制数时,需要对应的每一位 0 或 1 乘以系数,既对应位数 k 的 2k-1 ,再全部相加,形如: 0x

oneCertain的博客 267

POJ 1023 The Fun Number System (递推)

给定一个数,在正常的二进制中它的表示是唯一的。 而在这道题中,由许多种表示方法。比如1,可以是1,可以是2+(-1),可以是4+(-2)+(-1),但是有一点是确定的,如果要构造这个1,要么选1,要么选-1和后面的数组合,不可以不选。 所以由低到高枚举N的每个二进制位,如果这一位上是1,那么不管字符串中这一位是正的还是负的都必须选,如果是负的,那么后面就要多凑出1把这个-1对掉,所以N要+1

Baoli1008的专栏 786

poj1023:The Fun Number System有趣的进制系统

题意:给你一个二进制系统,每个位都有一个权重,但是可能为负,由字串ppnppn。。。给出,p代表为正,否则为负,然后给你一个数n(在long long范围内),求此数在这 个有趣的进制系统下的表示。 我的思路是这样的:从低位开始根据pn序列那么可以确定从最低位到当前位所能表示的数字范围,用两个数组存起来,由于字串可能达到64,所以 第64位另外存起来。然后从高位开始判断,如果使用当前位可以使

To lose to pursue. 1034

Java的第20年:Java和我的故事

Java的第20年:Java和我的故事 http://blog.youkuaiyun.com/jackfrued/article/details/44535509

兴趣是最好的老师 644
上一篇: H - 青蛙的约会解题报告(贺奕凯)
下一篇: B - 反正切函数的应用解题报告(贺奕凯)
CSUST_ACM
博客等级 码龄15年 42粉丝 127原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值