题目链接:

Water problem

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 23    Accepted Submission(s): 14

Problem Description
If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3+3+5+4+4=19 letters used in total.If all the numbers from 1 to n (up to one thousand) inclusive were written out in words, how many letters would be used?

Do not count spaces or hyphens. For example, 342 (three hundred and forty-two) contains 23 letters and 115 (one hundred and fifteen) contains 20 letters. The use of "and" when writing out numbers is in compliance with British usage.

 
Input
There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases.

For each test case: There is one positive integer not greater one thousand.

 
Output
For each case, print the number of letters would be used.
 
Sample Input
3
1
2
3
 
Sample Output
3
6
11
 
题意:
 
问[1,n]这些数字用英文单词表示的时候一共用了多少个字母;
 
思路:
 
水题;
 
AC代码:
 
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>
#include <stack>
#include <map> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const LL mod=1e9+7;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=5e5+10;
const int maxn=(1<<20)+14;
const double eps=1e-12; int dp[1100]; int check(int x)
{
if(x<=10)
{
if(x==1||x==2||x==6||x==10)return 3;
else if(x==3||x==7||x==8)return 5;
else if(x==4||x==5||x==9)return 4;
}
else if(x<=20)
{
if(x==11||x==12||x==20)return 6;
if(x==13||x==14||x==18||x==19)return 8;
if(x==15||x==16)return 7;
if(x==17)return 9;
}
else if(x<100)
{
if(x%10==0)
{
if(x==30||x==80||x==90)return 6;
else if(x==40||x==50||x==60)return 5;
else if(x==70)return 7;
}
else return check(x%10)+check(x-x%10);
}
else if(x<1000)
{
if(x%100==0)return check(x/100)+7;
else return check(x/100)+10+check(x-(x/100)*100);
}
else return 11;
}
inline void Init()
{
for(int i=1;i<=1000;i++)
{
dp[i]=dp[i-1]+check(i);
}
} int main()
{
int t;
Init();
read(t);
while(t--)
{
int n;
read(n);
print(dp[n]);
}
return 0;
}

  

hdu-5867 Water problem(水题)的更多相关文章

  1. HDU 5832 A water problem 水题

    A water problem 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5832 Description Two planets named H ...

  2. HDU 5867 Water problem (模拟)

    Water problem 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5867 Description If the numbers ...

  3. HDU 5867 Water problem ——(模拟,水题)

    我发这题只是想说明:有时候确实需要用水题来找找自信的~ 代码如下: #include <stdio.h> #include <algorithm> #include <s ...

  4. HDU 5867 Water problem

    处理出1-99的,之后的加上多少hundred和and即可.整百和一千的时候注意一下. #pragma comment(linker, "/STACK:1024000000,10240000 ...

  5. hdu 1106:排序(水题,字符串处理 + 排序)

    排序 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submissi ...

  6. HDU 4950 Monster (水题)

    Monster 题目链接: http://acm.hust.edu.cn/vjudge/contest/123554#problem/I Description Teacher Mai has a k ...

  7. HDU 4813 Hard Code 水题

    Hard Code Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.act ...

  8. HDU 4593 H - Robot 水题

    H - RobotTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.act ...

  9. HDOJ/HDU 2560 Buildings(嗯~水题)

    Problem Description We divide the HZNU Campus into N*M grids. As you can see from the picture below, ...

随机推荐

  1. BlockingQueue的使用 http://www.cnblogs.com/liuling/p/2013-8-20-01.html

    BlockingQueue的使用 本例介绍一个特殊的队列:BlockingQueue,如果BlockQueue 是空的,从BlockingQueue取东西的操作将会被阻断进入等待状态,直到Blocki ...

  2. eclipse 连接 hadoop集群

    1 网上找插件 或者 自己编译 放到eclipse plugin里面 2 重启eclipse 配置MapReduceLocation 通吃端口为9001 9000 看你自己的配置 3 新建mapRed ...

  3. PHPstorm如何导入字体主题

    概要: 今天在安装phpstorm的时候发现导入字体主题时,出了问题,这个问题总是困惑我,并且曾经遇到过,没记录下来,所以想着这次记录下来吧.网上搜的稀里糊涂的,还是自己做个summary! 前提: ...

  4. 修改Jmeter配置使能支持更大并发

    Jmeter做并发测试时,报错 java.lang.OutOfMemoryError:gc overhead limit exceeded. 原因是jmeter默认分配内存的参数很小,256M吧.故而 ...

  5. 【BZOJ2006】[NOI2010]超级钢琴 ST表+堆

    [BZOJ2006][NOI2010]超级钢琴 Description 小Z是一个小有名气的钢琴家,最近C博士送给了小Z一架超级钢琴,小Z希望能够用这架钢琴创作出世界上最美妙的音乐. 这架超级钢琴可以 ...

  6. PLSQL使用技巧----加快你的编程效率

    使用PLSQL 编程效率明显有所提高了 1.登录后默认自动选中My Objects      默认情况下,PLSQL Developer登录后,Brower里会选择All objects,如果你登录的 ...

  7. 九度OJ 1203:IP地址 (字符串处理)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:3038 解决:1496 题目描述: 输入一个ip地址串,判断是否合法. 输入: 输入的第一行包括一个整数n(1<=n<=500) ...

  8. linux c编程:FIFO

    前面介绍的pipe属于匿名管道 管道的主要局限性正体现在它的特点上: 只支持单向数据流: 只能用于具有亲缘关系的进程之间: 没有名字: 管道的缓冲区是有限的(管道制存在于内存中,在管道创建时,为缓冲区 ...

  9. linux c编程:信号(三) sigprocmask和sigpending函数

    信号源为目标进程产生了一个信号,然后由内核来决定是否要将该信号传递给目标进程.从信号产生到传递给目标进程的流程图如下图所示: 进程可以阻塞信号的传递.当信号源为目标进程产生了一个信号之后,内核会执行依 ...

  10. java访问微信接口发送消息

    最近在开发activiti流程的时候有个需求:流程到达每个审批节点后,需要向该节点的审批人发送一个消息,提示有审批需要处理. 参考了一下微信的开发者文档和网络上的一些技术博客,现在记录一下.以便后续继 ...