XTU OJ 1160 Harry Potter
来源:互联网 发布:数据库垂直切分 编辑:程序博客网 时间:2024/06/05 03:33
Harry Potter
Accepted : 72 Submit : 223Time Limit : 1000 MS Memory Limit : 65536 KB题目描述
Harry Potter想立刻赶到学校去,假设他和学校处于一条直线上,他一开始处于0点,学校位于X点。在一个单位时间内他可以往前走1格,或者使用魔法把自己变到目前坐标2倍的地方。请问他到学校最少需要多少时间?
输入
第一行是一个整数K,表示样例的个数。 以后每行是一个整数,表示X(0≤X≤10^18)。
输出
每行输出一个整数,表示Harry Potter赶到学校需要的时间。
样例输入
3110100
样例输出
159
最后一次模拟训练,下一周就比赛了,做了一下湘潭大学的联合训练题,好受打击啊,只做出来一道题,还有几道题都没什么思路,这样的状态怎么去比赛啊!!!只做出了这一道水题,后面的一道题,wa了好多次,还超时了好几次,好多模板题,看不出是什么模板啊,还是有好多内容不熟悉啊!!发现了好多问题,说明自己的实力不行!!!还需要加强训练!!
下面是ac的代码:
#include <iostream>#include <cstdio>using namespace std;int main(){ int t; long long x; scanf("%d",&t); while(t--) { long long count=0; scanf("%I64d",&x); while(x) { if(x%2==0) { x/=2; count++; } else { x-=1; count++; } } printf("%I64d\n",count); } return 0;}判断是否是奇数或者是偶数可以用 &1,可能比这样省时间! 位运算!
2 0
- XTU OJ 1160 Harry Potter
- Harry Potter
- OJ 1865: Harry Potter And The Half-Blood Prince
- 读 Harry Potter 7
- Harry Potter's Exam
- XTU OJ
- XTU OJ
- Harry Potter最终版的驾临
- hdu4771Stealing Harry Potter's Precious
- Stealing Harry Potter's Precious
- Stealing Harry Potter's Precious
- Harry Potter and the Deathly Hallows
- New Harry Potter Book Breaks Sales Record
- New Harry Potter Book Breaks Sales Record
- New Harry Potter Book Breaks Sales Record
- New Harry Potter Book Breaks Sales Record
- New Harry Potter Book Breaks Sales Record
- New Harry Potter Book Breaks Sales Record
- codeforces 1A Theatre Square(再来一水题)
- aorg.gjt.mm.mysql.Driver和com.mysql.jdbc.Driver
- 杭电--1870--愚人节的礼物
- &和&&的区别
- 安卓(android)建立项目时失败,出现Android Manifest.xml file missing几种解决方法?(总结中)
- XTU OJ 1160 Harry Potter
- POJ 2559 Largest Rectangle in a Histogram(单调栈)
- Android系统SD驱动浅析
- java 邮件发送实现相关文章
- actionscript3.0 函数重载问题
- IOS的GCD
- Leetcode习题:Pow(x, n)
- Quartus II 13.1正式版(Windows版和Linux版破解)
- 字符串分割--java中String.split()用法