HDU 2575 Count Problem (水题)
2016-03-01 21:26
302 查看
Problem Description
In this problem,we need to count the number that accord with the following rule(include the input number n).Read a integer number n(1<=n<=2^31 - 1) first,then do as following ways:
(1)Do nothing, then exit the process.
(2)Add a digit to the left of it,but the digit should not bigger than the half of the original first digit.For example,from 36 to 136 is legal,but 36 to 236 is illegal because 2 is bigger than half of 3.
(3)After add the digit,continue the process,until could not add digit anymore.
Input
The first line of the input contains an integer T which means the number of test cases.Then T lines follow, each line starts with a number n(1<=n<=2^31 - 1).
Output
For each test case, you should output one line contains the number that accord with the rule start from n.
Sample Input
2
1
6
Sample Output
1
6
Hint
The first case 1 cannot any digital to the leftmost, so the number so only 1.
The second case 6 can add 1, 2, 3 to the leftmost so 16,26,36 are legal. And then 26, 36 also can add 1 to the leftmost so get 126, 136. So 6,16,26,36,126,136 are all legal.The result is 6.
题意:给定一个数n,从n的左边开始添加整数,要求添加的整数满足不大于n的最高位(first digit)的一半,直到不能添加为止;
比如 n=6,满足条件的有6、16、26、36、126、136共6种情况;
n=10;只有10一种情况,因为10的最高位为1,
故只需要穷举n从1~9共9种情况,
以下AC代码:
In this problem,we need to count the number that accord with the following rule(include the input number n).Read a integer number n(1<=n<=2^31 - 1) first,then do as following ways:
(1)Do nothing, then exit the process.
(2)Add a digit to the left of it,but the digit should not bigger than the half of the original first digit.For example,from 36 to 136 is legal,but 36 to 236 is illegal because 2 is bigger than half of 3.
(3)After add the digit,continue the process,until could not add digit anymore.
Input
The first line of the input contains an integer T which means the number of test cases.Then T lines follow, each line starts with a number n(1<=n<=2^31 - 1).
Output
For each test case, you should output one line contains the number that accord with the rule start from n.
Sample Input
2
1
6
Sample Output
1
6
Hint
The first case 1 cannot any digital to the leftmost, so the number so only 1.
The second case 6 can add 1, 2, 3 to the leftmost so 16,26,36 are legal. And then 26, 36 also can add 1 to the leftmost so get 126, 136. So 6,16,26,36,126,136 are all legal.The result is 6.
题意:给定一个数n,从n的左边开始添加整数,要求添加的整数满足不大于n的最高位(first digit)的一半,直到不能添加为止;
比如 n=6,满足条件的有6、16、26、36、126、136共6种情况;
n=10;只有10一种情况,因为10的最高位为1,
故只需要穷举n从1~9共9种情况,
以下AC代码:
#include<stdio.h> int main() { int t,n,a[10]={0,1,2,2,4,4,6,6,10,10}; scanf("%d",&t); while(t--) { scanf("%d",&n); while(n>9) n/=10; printf("%d\n",a ); } return 0; }
相关文章推荐
- Linux学习笔记(8)----基础正则表达式
- Dubbo与Zookeeper、SpringMVC整合和使用(负载均衡、容错)(转)
- CF 126B KMP/Z
- GDKOI2016
- 谈谈IIS与ASP.NET管道
- Pocket Cube
- python学习笔记-Day16-jquery(文档处理/事件/插件)
- Hadoop2.7.1 配置三个.xml文件的创建地址
- 获取在线人员数量
- LeetCode 144. Binary Tree Preorder Traversal
- ORA-10458,ORA-01196,ORA-01110处理
- 关于js和java的一点点不同
- 跨域的方法
- 3876: [Ahoi2014]支线剧情|有上下界的费用流
- 1>XxxDlg.obj : error LNK2005: "char * * tabPageData" (?tabPageData@@3PAPADA) 已经在 XxxDlg.obj 中定义
- 234. Palindrome Linked List&回文链表
- ContentProvider 跨程序间数据沟通
- 网易云课堂 数据结构01-复杂度2 Maximum Subsequence Sum
- 内存管理
- bootstrap样式使用标准(转)