TOJ 3470.Key Integer
来源:互联网 发布:郸城县乡镇人口数据 编辑:程序博客网 时间:2024/06/07 03:44
题目链接:http://acm.tju.edu.cn/toj/showp3470.html
Time Limit: 4.0 Seconds Memory Limit: 65536K
Total Runs: 211 Accepted Runs: 191
ZSJ likes travel, and sometimes his may find some place that unknow to people. Once he found such a place, he will tell his friend ZXT about this. A few days before, ZXT found a mysterious place. At this place, he saw a big stone-gate. Beside this gate, there are some mysterious letters that ZSJ can't read. So he drew these letters on a piece of paper and went back home to ask ZXT for help. After a few days of hard work, ZXT told ZSJ that : If he want to open the door, he must find the certain integer between 1 and N (inclusively) that fits a fixed condition, but she can't tell what the condition is because she can't understand all those mysterious letters. But the good news is: if ZSJ trys an integer k, he can get one of the three piece of information from the mysterious stone-door: k is just the number that required, k is smaller than the required integere and k is greater than the required integer. Knowing about this, ZSJ decide to use the following method to get the required integer:
x <- 1y <- Nwhile (true) {m <- (x+y)/2try the number m andif m is the required integer, breakif m is smaller, x = m + 1if m is greater, y = m - 1}ZSJ is sure that he can get the required integer by the method mentioned above. But he has a question that when using this method, how many integers he has to try at most.
Input
The first line of input file is a sigle integer T, the number of test cases. Then T lines follows, each line contains a sigle integer N . Its meaning has mentioned above. (1 ≤ T ≤ 27; 1 ≤ N ≤ 100000).
Output
For each test cases, output a single integer: the number of integers he has to try at most.
Sample Input
210427
Sample Output
49
Hint: In the first test cases, the possible key integer to open the door is 1, 2, 3, 4, 5, 6, 7, 8, 9. If the key integer is 1, using the methord above, ZSJ has to try 3 integers: {5, 2, 1}; if the key integer is 2, he has to try: {5, 2}; and so on. When the key integer is 4, he has to try most integers: {5, 2, 3, 4}. So the answer of the first test case is 4.
水题不多bb:
#include <stdio.h>int main(){ int n,T; scanf("%d",&T); while(T--){ scanf("%d",&n); int i = 1,k = 0; while (i<n){ i *= 2; k++; } printf("%d\n",k); } return 0;}
- TOJ 3470.Key Integer
- INTEGER PRIMARY KEY简介
- INTEGER PRIMARY KEY简介
- INTEGER PRIMARY KEY AUTOINCREMENT 和 INTEGER PRIMARY KEY 区别
- Sqlite中INTEGER PRIMARY KEY的修正
- TOJ 2189. The Key Stations 【求无向图的割点】
- TOJ 3708: The Key Locker of Cell Phone (大水题)
- JSTL访问Map问题,key为Integer或Long
- Integer做WeakHashMap的Key应注意的问题
- 取list<Integer,String> list的key和value
- TOJ 2976
- toj 3140
- toj 1153
- TOJ 1772
- TOJ 3250
- TOJ 3051
- TOJ 4303
- TOJ 1005
- Eclipse下搭建NDK开发环境及入门Demo
- linux qt c++11 编译
- struts2与springmvc区别?
- Excel数据分析实例——各省人口数量及增长
- 如何下载POI标注-信息点
- TOJ 3470.Key Integer
- Ubuntu 删除多余内核
- 一个表决心
- 基本线程函数
- JavaScript学习---4
- IIS添加FTP目录
- 线程同步知识点+案例(子线程父线程交替执行,输出10遍我爱你)
- Git:Please enter a commit message to explain why this merge is necessary
- React API