题目链接:

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;
}

  

转载于:https://www.cnblogs.com/zhangchengc919/p/5784742.html

hdu-5867 Water problem(水题)相关推荐

  1. Poj1207 The 3n + 1 problem(水题(数据)+陷阱)

    一.Description Problems in Computer Science are often classified as belonging to a certain class of p ...

  2. HDU 6168 Numbers 思维 水题

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=6168 题目描述: 定义数组b是由数组a每两项的和组成的,现在将数组A, B混在一起给你, 筛出数组A ...

  3. 2018焦作网络赛 - Poor God Water 一道水题的教训

    本题算是签到题,但由于赛中花费了过多的时间去滴吧格,造成了不必要的浪费以及智商掉线,所以有必要记录一下坑点 题意:方格从1到n,每一格mjl可以选择吃鱼/巧克力/鸡腿,求走到n格时满足 1.每三格不可 ...

  4. HDU 4393 Throw nails [水题]

    题解写了N多方法,我用的是最水的那种.. 起始区间只有(0 <= Fi <= 500),500秒之后排名必然不会变化了..所以,暴力500秒,然后排个序就行了. 1 #include &l ...

  5. HDU - 2091 空心三角形 水题,但是有点坑...

    空心三角形 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Subm ...

  6. Codeforces Round #360 (Div. 2) C. NP-Hard Problem 水题

    C. NP-Hard Problem 题目连接: http://www.codeforces.com/contest/688/problem/C Description Recently, Pari ...

  7. hdu 4823 Energy Conversion(水题)

    Energy Conversion Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  8. HDU - 1757 A Simple Math Problem(矩阵快速幂,水题)

    题目链接:点击查看 题目大意:实现公式: f(x)=x,x<10 f(x)=a0*f(x-1)+a1*f(x-2)+--+a9*f(x-10) 题目给出a0~a9,一个n和一个m,要求输出f(n ...

  9. HDU 1033 水题

    题意还真的不好懂,摸索数据就出来了,注意顺时针和逆时针时候的方向变化 /*  * Author:lonelycatcher  * problem:hdu 1033  * Type:水题  */ #in ...

最新文章

  1. php制作随机地图,随机生成Roguelike游戏地图算法
  2. 统一配置数据库连接符的方法
  3. Qt文档阅读笔记-对Style Plugin Example实例的解析
  4. Linux监控命令之==sar
  5. 指针(Pointer)
  6. java ic卡读写_使用Java驱动ACR122U对IC卡进行读写,总结
  7. 闲谈IPv6-组播和广播
  8. 【考研】计算机考研复试之智力题测试
  9. OpenHarmony hdc_std无反应的解决办法
  10. 前端剑法第三式————碎岩
  11. 1463: [蓝桥杯2019初赛]年号字串 【水题】
  12. python怎么左对齐_python中如何用ljust()实现字符串左对齐?
  13. 配置路由器用SSH登陆
  14. ESMTP身份验证机制探索手记
  15. 7z文件压缩、解压 (7zTool.exe)
  16. springboot接口安全性_权限系统控制到按钮级别开源推荐 Spring Boot-Shiro-Vue
  17. 将桌面移动到D盘,D盘中的资料填满了整个桌面
  18. while语句和for嵌套c语言,关于循环的嵌套,说法错误的是() 答案:三种循环(while循环、do-while循环和for循 环)不可以互相嵌套。...
  19. 看恐怖片可能会让你变胖:吃掉更多的爆米花和巧克力
  20. catia v5法矢数据软件_CATIA V5完全学习手册

热门文章

  1. pytorch VGG
  2. python contextlib
  3. TensorFlow tf.keras.layers.DenseFeatures
  4. 3.8 激活函数的导数
  5. opencv SIFT角检测
  6. python 字符类型
  7. oracle表空间状态如何离线,六步了解Oracle表空间状态
  8. 安装版mysql5.7_mysql5.7 安装版安装
  9. python语言能做什么游戏好玩_太好玩了我用 Python 制作一款小游戏
  10. 超详细的MySQL工作原理 体系结构