uva 10077 - The Stern-Brocot Number System】的更多相关文章

这是在看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://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<…
想法: 初始化三個數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\)的数字的个数. 递推就是枚…
题目链接: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…