Convert Kilometers to Miles 2010.3.6

赤果果的x进制

Convert Kilometers to Miles

Time Limit:1000MS  Memory Limit:65536K

Total Submit:21 Accepted:11

Description

This year, Bruce Force spends his vacationin Flagstaff, Arizona, where he wants to practice for hisnext half marathon (a race over 21 km). At his first training he runs to hisfriend Greedy Gonzales' home which is 21 miles away from Flagstaff.

Arriving there, he is very tired andrealizes that 21 miles are much more than 21 km. Greedy Gonzales tells him that21 km equals 13 miles. 21, 13? Bruce realizes immediately that there must be adeeper relation! Both, 13 and 21 are Fibonacci numbers!

Fibonacci numbers can be defined asfollows:

• F1 = 1

• F2 = 2

• Fn+1 = Fn+Fn-1 for n>1.

Bruce has just learned about the Fibonaccinumber system at his university. Each positive integer x can be written as thesum of different Fibonacci numbers, so this means that there exists numbers kand b1, b2, ..., bk such that x = ∑i=1..k bi * Fi,where bk = 1 and bi (1 ≤ i < k) is either 0 or 1. In short, we can write therepresentation as: b(x) = (bk, bk-1, ..., b1). To make the representationunique, we require that bi * bi-1 = 0 for all i > 1.

For example 21 can be represented as(1,0,0,0,0,0,0) and 13 as (1,0,0,0,0,0) in the Fibonacci system. Bruce noticesthat one can convert a distance x in kilometers into a corresponding distance yto miles as follows: First, write down x in its Fibonacci system representationb(x). Second, shift the bits of b(x) one position to the right (the last bit isdeleted) and get b(y). Third, calculate y from b(y) by evaluating the sum givenabove.

For example, the number 42 written in the Fibonaccisystem is (1,0,0,1,0,0,0,0). In step two we would shift the bits one positionto the right and get (1,0,0,1,0,0,0). In the third step, we would calculate 0*1+ 0*2 + 0*3 + 1*5 + 0*8 + 0*13 + 1*21 = 26.

Now it's your turn to write a program forBruce that converts kilometers into miles according to Bruce's algorithm.

Input

The first line of the input contains t, thenumber of distances Bruce wants to convert from kilometers to miles(0< t< 25000). Each of the next t lines contains an integer distance x (2 < x< 25000) in kilometers.

Output

For each distance x in kilometers outputthe distance y in miles calculated according to Bruce's algorithm.

Sample Input

5

42

100

180

300

360

Sample Output

26

62

111

185

222

Source

ULM 2008

#include <stdio.h>
#include <string.h>#define MAXN 22int num[MAXN+1]={0,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765,10946,17711,28657};
int t,n,m;
int ans[MAXN+1],goal;void main()
{int i,j;scanf("%d",&t);for(i=1;i<=t;i++){scanf("%d",&n);goal=0;memset(ans,0,sizeof(ans));for(j=MAXN;j>=1;j--)if (num[j]<=n){n-=num[j];ans[j]=1;}for(j=1;j<MAXN;j++)goal+=ans[j+1]*num[j];printf("%d\n",goal);}
}

Convert Kilometers to Miles 2010.3.6相关推荐

  1. TOJ 3015.Convert Kilometers to Miles

    题目链接 : http://acm.tju.edu.cn/toj/showp3015.html This year, Bruce Force spends his vacation in Flagst ...

  2. HDU 2370 Convert Kilometers to Miles

    点我看题目 题意 : 按照题目给定的规则将公里转化成英里,就是每个数都可以用斐波那契数列里的数表示,每个数都有一个编码,21可以表示成(1,0,0,0,0,0,0) ,13可以表示成(1,0,0,0, ...

  3. HDU2370——Convert Kilometers to Miles

    题意:将一个给定的数X以斐波那契数列为权写成0,1字串的形式,然后右移以为,再转换为10进制形式. 例如,42写成斐波纳契数列为(1,0,- 0.1,0,- 0,0,- 0),我们将其右移一位获得(1 ...

  4. HOJ 2786 Convert Kilometers to Miles

    http://acm.hit.edu.cn/hoj/problem/view?id=2786 公里转化为英里 公里数用最少个斐波那契数表示 即42表示为34+8 而不是34+5+2+1 #includ ...

  5. HDOJ题目分类大全

    版权声明:本文为博主原创文章,欢迎转载,转载请注明本文链接! https://blog.csdn.net/qq_38238041/article/details/78178043 杭电里面有很多题目, ...

  6. HDU题目分类大全【大集合】

    基础题: 1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029.  1032.1037.1040.1048.1056.105 ...

  7. hdoj杭电问题分类

    杭电上的题虽然多,但是一直苦于找不到问题分类,网页都是英文的,所以平时做题也没怎么看,今天仔细一看,问题分类竟然就在主页....做了那么久的题居然没发现,表示已经狗带..不要笑,不知道有没有像我一样傻 ...

  8. 转载:Hdu 题目分类

    原址点击 基础题:1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029. 1032.1037.1040.1048.1056. ...

  9. hdu与poj题目分类

    POJ 初期: 一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. (4)递推. (5)构造法.(po ...

最新文章

  1. 苹果要为app store速度奇慢付出代价
  2. 华为2011上机笔试题2+参考程序
  3. 学习《apache源代码全景分析》之摘录
  4. HISTFILESIZE与HISTSIZE的区别
  5. android网络框架
  6. BZOJ 3685 普通van Emde Boas树 权值线段树(zkw)
  7. 《R与Hadoop大数据分析实战》一1.1 安装R
  8. Hadoop 2.2.0 在centos6.2 64位下的安装--分布式模式
  9. 以太坊 交易 data字段 内容是什么
  10. SQL Server用户权限详解
  11. 无人驾驶综述:等级划分
  12. Unity 粒子特效
  13. 35+大龄程序员们都在做什么?
  14. 重标极差分析法matlab,重标极差(RS)分析法估计Hurst指数的有效性检验.doc
  15. JS实现waterfall
  16. c++----实数类型.
  17. 推荐一本书《亚马逊网络书店传奇》
  18. Excel 2016 做线性回归分析【高尔顿数据集】与【Anscombe四重奏数据集】
  19. Google巧妙发布Sky星空地图
  20. 常见的随机变量分布律/概率密度、期望、方差以及特征函数

热门文章

  1. Hi3516开发笔记(十一):通过HiTools使用网口将uboot、kernel、roofts烧写进eMMC
  2. redis expire key 过期不删除
  3. 2021年一战南大AI上岸经验贴
  4. Redis系列(五):Redis的过期键删除策略
  5. MAC OS苹果系统密码破解方法
  6. 两个分数化简比怎么化_两个分数的比化简怎么化急用
  7. 【计蒜客】蒜头君的旅游计划
  8. 美的苏宁“超级带货趴”来袭,养成带货达人,大牌净味冰箱带回家
  9. 微搭小课堂-第一课 实现到店导航
  10. 语义分割模型------unet unet++