POJ1023 The Fun Number System】的更多相关文章

题目来源:http://poj.org/problem?id=1023 题目大意: 有一种有趣的数字系统.类似于我们熟知的二进制,区别是每一位的权重有正有负.(低位至高位编号0->k,第i位的权值为2^i 或-2^i) 输入:第一行给定测试用例数.每个用例的第一行为一个正整数k(1<=k<=64),说明该二进制编码的位数长度.接下来一行是一个长度为k的字符串,仅有两种字母p和n,描述了该种编码格式中每一位的权重为正(p)还是为负(n).第三行为一个正整数,N(-2^23<=N<…
这是在看geeksforgeeks时看到的一道题,挺不错的,题目是 Given a number system with only 3 and 4. Find the nth number in the number system. First few numbers in the number system are: 3, 4, 33, 34, 43, 44, 333, 334, 343, 344, 433, 434, 443, 444, 3333, 3334, 3343, 3344, 343…
A number system with moduli is defined by a vector of k moduli, [m1,m2, ···,mk]. The moduli must be pairwise co-prime, which means that, for any pair of moduli, the only common factor is 1. In such a system each number n is represented by a string "-x…
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…
The Stern-Brocot Number System Input: standard input Output: standard output The Stern-Brocot tree is a beautiful way for constructing the set of all nonnegative fractions m / n where m and n are relatively prime. The idea is to start with two fracti…
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…
We define the smallest positive real number as the number which is explicitly greater than zero and yet less than all other positive real numbers except itself. The smallest positive real number, if exists, implies the existence of the second greater…
题目链接:http://lightoj.com/volume_showproblem.php?problem=1172 题意:一个n进制(2<=n<=6)的数字,满足以下条件:(1)至少包含两位且不以0开头,比如012是不行的:(2)相邻数字不同:(3)定义这个数字x的score(x)等于相邻数字差的平方和,比如score(125)=(1-2)*(1-2)+(2-5)*(2-5)=10.现在给出n和m,求满足条件的所有n进制的数字中有多少数字的score为m.(1<=m<=10^9…
想法: 初始化三個數L=0/1, M=1/1, R=1/0,設輸入的分數為a: 如果a<M,那麼要往左邊走,    R = M;    M = (L分子+M分子)/(L分母+M分母); 如果a>M,往右邊走,    L = M;    M = (R分子+M分子)/(R分母+M分母); 如果a==M,停止. 這題和二分搜尋很類似.迭代算法如下: #include <cstdio> using namespace std; struct fraction{ int M; // Mole…
题意: 有一个\(base(2 \leq base \leq 6)\)进制系统,这里面的数都是整数,不含前导0,相邻两个数字不相同. 而且每个数字有一个得分\(score(1 \leq score \leq 10^9)\),得分为 相邻两个数字之差的平方之和. 给出\(base\)和\(score\),求满足条件的整数的个数 \(mod \, 2^{32}\). 分析: 首先考虑DP的做法: 设\(dp(i, j)\)表示满足当前分数为\(i\)最后一个数字是\(j\)的数字的个数. 递推就是枚…
根据CC150的解决方式和Introduction to Java programming总结: 使用了两种方式,递归和迭代 CC150提供的代码比较简洁,不过某些细节需要分析. 现在直接运行代码,输入n(其中用number代替,以免和方法中的n混淆)的值,可以得出斐波那契数. 代码如下: /* CC150 8.1 Write a method to generate the nth Fibonacci number Author : Mengyang Rao note : Use two me…
Lucky Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 294    Accepted Submission(s): 49 Problem Description “Ladies and Gentlemen, It’s show time! ” “A thief is a creative artist who ta…
描述we define f(A) = 1, f(a) = -1, f(B) = 2, f(b) = -2, ... f(Z) = 26, f(z) = -26;Give you a letter x and a number y , you should output the result of y+f(x).   输入 On the first line, contains a number T(0<T<=10000).then T lines follow, each line is a…
表示程序正常退出 System.exit(status) 当status非0时,表示程序为非正常退出. status=0, 关闭当前正在运行的虚拟机. 求质因数分解的程序如下: 两种算法: 一种是用System.exit(0) // 若不加此句,代码在运行完System.out.println(number)后,会回到for中从i++开始执行,不断执行 else和后面的打印语句.是因为递归吗? 代码 package basic40; public class Divid {    public…
System.Data.DbType 与其它DbType的映射关系 有如下类型的映射对照: System.Data.SqlClient.SqlDbType System.Data.OleDb.OleDbType System.Data.Odbc.OdbcType System.Data.OracleClient.OracleType 格式: DbType.枚举名(枚举值) = DbType.枚举名(枚举值) =========== System.Data.SqlClient.SqlDbType…
当进制转换后所剩下的为数较少时(2位.3位),相应的base都比較大.能够用数学的方法计算出来. 预处理掉转换后位数为3位后,base就小于n的3次方了,能够暴力计算. . .. Lucky Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 521    Accepted Submission(s): 150 Probl…
有如下类型的映射对照: System.Data.SqlClient.SqlDbType  System.Data.OleDb.OleDbType System.Data.Odbc.OdbcType System.Data.OracleClient.OracleType 格式: DbType.枚举名(枚举值) = DbType.枚举名(枚举值) =========== System.Data.SqlClient.SqlDbType ========= System.Data.SqlClient.S…
System Board Replacement Notice System Board Replacement Notice for TP 770E and TP 600 Restoring the System Unit Serial Number: The EEPROM on the system board contains vital product data (VPD), such as the system unit serial number and the system boa…
System.arraycopy /* native关键字 本地方法 System类 java.lang.System.class 参数说明: src - 源数组. srcPos - 源数组中的起始位置. dest - 目标数组. destPos - 目标数据中的起始位置. length - 要复制的数组元素的数量. */ public static native void arraycopy(Object src, int srcPos,Object dest, int destPos,int…
System.getproperty(String name) 获取系统属性 System.getProperties() 获取所有系统属性 System.getenv(String name) 获取环境变量 系统属性说明: public class test{ public static void main(String[] args) { System.out.println("Java Runtime Environment version = " + System.getPro…
Index: (1)类型语法.内存管理和垃圾回收基础 (2)面向对象的实现和异常的处理 (3)字符串.集合与流 (4)委托.事件.反射与特性 (5)多线程开发基础 (6)ADO.NET与数据库开发基础 (7)WebService的开发与应用基础 一.字符串处理 1.1 StringBuilder类型有什么作用? 众所周知,在.NET中String是引用类型,具有不可变性,当一个String对象被修改.插入.连接.截断时,新的String对象就将被分配,这会直接影响到性能.但在实际开发中经常碰到的…
原文出处: 付学良的网志 原文出处2: http://www.importnew.com/16270.html -------------------------------------------- Junit 4 和 TestNG 都是 Java 方面非常流行的单元测试框架.在功能上两个框架都非常类似.到底哪个比较好?在Java项目中我们应该选择哪个框架? 下图将会对Junit 4 和 TestNG 做个功能特征的对比. 注解支持 Junit 4 和 TestNG 在注解方面的实现非常相似.…
package com.cl.www.thread; public class NumberHolder { private Integer number = 0; // 增加number public synchronized void increaseNum(){ //不是0就不加 while(number != 0){ try { this.wait(); } catch (InterruptedException e) { e.printStackTrace(); } } number+…
关键字break和continue除了在switch语句中使用break,还可以在一个循环中使用break立即终止该循环. 循环语句有三类: while循环, do-while循环和for循环.循环中需要重复执行的语句所构成的整体称为循环体.循环体执行一次称为循环的一次迭代.无限循环是指循环语句被无限次执行.在设计循环时,既考虑循环控制结构体,还需要考虑循环体.while循环首先检查循环继续条件.如果条件为true,则执行循环体;如果条件为false,则循环体结束.do-while循环与whil…
原创地址:http://www.cnblogs.com/jfzhu/p/4039604.html 转载请注明出处 前面介绍过<Step by Step 创建一个WCF Service>和<使用WCF的Trace与Message Log功能>,本文介绍一下如何用JavaScript来调用WCF Service. WCF Service的代码如下: IHelloService.cs using System.ServiceModel; using System.ServiceModel…
<Java学习笔记(第8版)>学习指导 目录 图书简况 学习指导 第一章 Java平台概论 第二章 从JDK到IDE 第三章 基础语法 第四章 认识对象 第五章 对象封装 第六章 继承与多态 第七章 接口与多态 第八章 异常处理 第九章 Collection与Map 第十章 输入/输出 第十一章 线程与并行API 第十二章 Lambda 第十三章 时间与日期 第十四章 NIO与NIO2 第十五章 通用API 第十六章 整合数据库 第十七章 反射与类加载器 第十八章 自定义类型.枚举 补充:Ja…
循环 打印一个字符串(例如: "Welcome to Java!") 100次,就需要吧下面的输出语句重复写100遍,这是相当繁琐的: System.out.println("Welcome to Java!"); 循环用来控制语句块重复执行的次数 int count = 0;while(coun < 100){  System.out.println("Welcome to Java!");  count++;} Java提供了三种类型的…
第一个,计算字符串的md5值 public static String getMD5(String s){ String newString = null; byte[] inputByteArray = s.getBytes(); ', 'A', 'B', 'C', 'D', 'E', 'F' }; try { MessageDigest md = MessageDigest.getInstance("MD5"); md.update(inputByteArray); byte[]…
Java 抽象类 在面向对象的概念中,所有的对象都是通过类来描绘的,但是反过来,并不是所有的类都是用来描绘对象的,如果一个类中没有包含足够的信息来描绘一个具体的对象,这样的类就是抽象类. 抽象类除了不能实例化对象之外,类的其它功能依然存在,成员变量.成员方法和构造方法的访问方式和普通类一样. 由于抽象类不能实例化对象,所以抽象类必须被继承,才能被使用.也是因为这个原因,通常在设计阶段决定要不要设计抽象类. 父类包含了子类集合的常见的方法,但是由于父类本身是抽象的,所以不能使用这些方法. 在Jav…
http://blog.csdn.net/evangel_z/article/details/7624503 http://blog.163.com/wangzhengquan85@126/blog/static/36082995201182111847325/ http://niuxiaoxia870563296.iteye.com/blog/1749966 To format a number for the current Locale, use one of the factory cl…