HDU-5867 Water problem(模拟)
来源:互联网 发布:手机模板软件 编辑:程序博客网 时间:2024/06/06 02:42
题目:https://vjudge.net/problem/469278/origin
题意:每个数有英文表示,计算英文表示的字母个数为这个数所用的字符,计算1~n的字符总数
思路:特判+打表
#include<bits/stdc++.h>using namespace std;int a[15] = {0,3,3,5,4,4,3,5,5,4};int b[25] = {0,0,0,0,0,0,0,0,0,0,3,6,6,8,8,7,7,9,8,8};//十几int c[15] = {0,0,6,6,5,5,5,7,6,6};//几十int f[1005];void Init(){ for(int i = 1;i <= 1000;i++) { int x = i; if(x == 1000) { f[i] += 11; continue; } int s[5] = {0},num = 0; while(x > 0) { s[num++] = x % 10; x /= 10; } if(s[2] == 0) { if(s[1] == 0) { f[i] += a[s[0]]; } else { if(s[1] == 1) f[i] += b[10+s[0]]; else f[i] += c[s[1]] + a[s[0]]; } } else//第一位不为0 { if(s[0] == 0)//hundred { if(s[1] == 0)//第二位等于0 00 { f[i] += 7; f[i] += a[s[2]] + a[s[0]]; } else { f[i] += 7+3; if(s[1] == 1) f[i] += a[s[2]] + b[10+s[0]]; else f[i] += a[s[2]] + c[s[1]] + a[s[0]]; }//4 7 3 6 4 } else//hundred and { f[i] += 7+3; if(s[1] == 0)//第二位等于0 00 { f[i] += a[s[2]] + a[s[0]]; } else { if(s[1] == 1) f[i] += a[s[2]] + b[10+s[0]]; else f[i] += a[s[2]] + c[s[1]] + a[s[0]]; }//4 7 3 6 4 } } }}int main(){ Init(); //for(int i = 100;i <= 200;i++) //cout<<f[i]<<endl; int t,n; cin >> t; while(t--) { scanf("%d",&n); int sum = 0; for(int i = 1;i <= n;i++) sum += f[i]; //cout<<f[n]<<endl; printf("%d\n",sum); } return 0;}
改了一下
#include<bits/stdc++.h>using namespace std;int a[15] = {0,3,3,5,4,4,3,5,5,4};int b[25] = {0,0,0,0,0,0,0,0,0,0,3,6,6,8,8,7,7,9,8,8};//十几int c[15] = {0,0,6,6,5,5,5,7,6,6};//几十int f[1005];void Init(){ for(int i = 1;i <= 1000;i++) { int x = i; if(x == 1000) { f[i] += 11; continue; } int s[5] = {0},num = 0; while(x > 0) { s[num++] = x % 10; x /= 10; } if(s[2] == 0) { if(s[1] == 0) { f[i] += a[s[0]]; } else { if(s[1] == 1) f[i] += b[10+s[0]]; else f[i] += c[s[1]] + a[s[0]]; } } else//第一位不为0 { if(s[1] == 0)//第二位等于0 00 { if(s[0] == 0)//x00 f[i] += a[s[2]] + 7 + a[s[0]]; else f[i] += a[s[2]] + 7 + 3 + a[s[0]]; } else { if(s[1] == 1) f[i] += a[s[2]] + 7 + 3 + b[10+s[0]]; else f[i] += a[s[2]] + 7 + 3 + c[s[1]] + a[s[0]]; }//4 7 3 6 4 } }}int main(){ Init(); //for(int i = 100;i <= 200;i++) //cout<<f[i]<<endl; int t,n; cin >> t; while(t--) { scanf("%d",&n); int sum = 0; for(int i = 1;i <= n;i++) sum += f[i]; //cout<<f[n]<<endl; printf("%d\n",sum); } return 0;}
0 0
- HDU-5867 Water problem(模拟)
- HDU 5867 Water problem (模拟)
- HDU 5867 Water problem——模拟
- hdu 5867 Water problem
- HDU 5867 Water problem
- HDU 5867 Water problem
- HDU 5867 Water problem
- HDU 5867 Water problem 【】
- hdu 5867 Water problem
- HDU 5867 Water problem (模拟水题)
- HDU 5832A water problem 简单模拟
- HDU 5867 Water problem(模拟题目)【HDU多校联合8.18】
- 【HDU5867】Water problem(模拟)
- HDU 4974 A simple water problem 模拟(水
- HDU 5867 Water problem(复杂水题)
- HDU 5867 Water problem(水~)
- HDU 5867Water problem 题如其名
- 水题(Water problem,HDU 5867)
- java线程中try catch finally块和throw抛出异常
- Ubuntu开发环境搭建(4)【安装repo】
- H5 WebSocket实现简单的实时通信
- Scala包和引用
- C语言中返回字符串函数的四种实现方法
- HDU-5867 Water problem(模拟)
- 算法导论 练习题 11.1-2
- 基于Kinect v2+PCL的模型奶牛重建(下)——点云融合
- hbase的搭建
- PCP详解
- APUE:进程和程序
- kafka Partition分发策略
- 同一个Activity在Task中存在多个记录
- Redis键(key)