题目链接:

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. DB2恢复一例 SQL0928N

    环境是AIX 6.1.DB2版本号9.7.0.7 首先查看db2主进程是否存在 ps -ef|grep db2sys 若不存在使用db2start打开数据库 备份介质为冷备数据源, cd 到介质所在文 ...

  2. 取消eclipse js验证

    去掉Eclipse中的Validating 最近我的Eclipse一直经常效验javascript,我疯了校验了一个多小时还是在验.我只能在项目的.project文件中: 去掉.project文件中的 ...

  3. ubuntu 16.04.3 安装完成后的一些初始化工作

    虚拟机安装前记得把桥接调好! 1. 重置root密码 sudo passwd, 然后系统会让你输入密码,这时输入的密码就是root用户的密码,su root切用户 2. 设置固定IP,有重启服务功能令 ...

  4. c# 当前不会命中断点 未载入该文档

    C#编码时.有时会遇到标题所说的问题,就是说这个文件和方法明明存在,可总是提示找不到方法.解决方法例如以下: 1.清理全部项目(或相关项目)生成 2.又一次加入全部项目(或相关项目)间的互相引用 3. ...

  5. 股神小L 2016Vijos省选集训 day1

    股神小L (stock.c/pas/cpp)============================ 小L厌倦了算法竞赛,希望到股市里一展身手.他凭借自己还行的计算机功底和可以的智商,成功建立一个模型 ...

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

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

  7. fkwの题目(祝松松生日快乐!)

    麓山国际实验学校 傅少,匡哥和巨夫出的题目(共3道) 一.题目概况 题目名称 打地铺 泡妹子 开房间 题目类型 传统 传统 传统 可执行文件名 deeeep soccer room 输入文件名 dee ...

  8. 我的Android进阶之旅------>Android中android:windowSoftInputMode的用法

    面试题:如何在显示某个Activity时立即弹出软键盘? 答案:在AndroidManifest.xml文件中设置<activity>标签的android:windowSoftInputM ...

  9. PAT 1051. 复数乘法 (15)

    复数可以写成(A + Bi)的常规形式,其中A是实部,B是虚部,i是虚数单位,满足i2 = -1:也可以写成极坐标下的指数形式(R*e(Pi)),其中R是复数模,P是辐角,i是虚数单位,其等价于三角形 ...

  10. rails member collection

    resources :theses do resources :document do get :download, :on => :member end end <a class=&qu ...