hrbust 1055 Single【暴力预处理】
来源:互联网 发布:powershell for linux 编辑:程序博客网 时间:2024/05/23 00:05
There are many handsome single boys in our team, for example, me. Some times, we like count singles. For example, in the famous “November 11th” (11.11), there are four singles ,so, single is actually 1. For another example, there are 2 singles in the time “1:01”. We are all boring guys, and here is an boring problem. Time is in the format HH:MM:SS; one day starts from 00:00:00, and ends at 24:00:00, we just want to know how many singles has passed till a certain time (included)
InputFirst line is the number of cases: n, the next n lines are each a time, exactly in the format described above. It's guaranteed that the time is in the right range (00:00:00 ~ 24:00:00)
OutputFor each case, just give us the answer in a single line, no extra character is needed.
Sample Input300:00:00
00:00:01
00:00:02Sample Output0
1
1Authorsanpin
题目大意:
给你一个时间t,让你计算从00:00:00到当前时间(包括当前时间这一秒)一共出现了多少次数字1.
思路:
直接暴力预处理从00:00:00到24:00:00之间这些时刻都出现了多少个1,对应存到数组ans【24*60*60】中即可,对应假设当前时间为:a:b:c,那么此时的答案我们记录到数组ans【a*60*60+b*60+c】中。
那么对应输入a:b:c的时候,直接输出ans【a*60*60+b*60+c】即可。
Ac代码:
#include<stdio.h>#include<string.h>using namespace std;int ans[24*60*60*10];int cal(int num){ int sum=0; while(num) { if(num%10==1)sum++; num/=10; } return sum;}void init(){ int output=0; int a=0,b=0,c=0; while(1) { output+=cal(a); output+=cal(b); output+=cal(c); ans[a*60*60+b*60+c]=output; c++; if(c==60) { c=0; b++; if(b==60) { b=0; a++; if(a==24)break; } } }}int main(){ init(); int t; scanf("%d",&t); while(t--) { int a,b,c; scanf("%d:%d:%d",&a,&b,&c); int tmp=a*60*60+b*60+c; printf("%d\n",ans[tmp]); }}
- hrbust 1055 Single【暴力预处理】
- hrbust 1547 基础数据结构——单链表(2)【水题-暴力预处理】
- HRBUST 1365 预处理+二分+?
- 【hrbust】2298 Diamond 【数学+暴力】
- Hrbust 2178 线段【暴力】水题
- hrbust 1957 干掉坏人【Dfs+暴力枚举】
- hrbust 1241 Blocks【暴力枚举+简单优化】
- Hrbust 1789 通信道路【思维+暴力枚举】
- 火柴等式 预处理 + 暴力
- hrbust/哈理工oj 1660素数矩阵【预处理+思维】
- hrbust 1328 相等的最小公倍数【暴力打表找规律】
- Hrbust 2325 Astonishing Combinatorial Number【前缀和+暴力】
- HRBUST OJ 1660 素数矩阵(素数打表,暴力)
- Hrbust 1201 Zombie’s Treasure Chest【贪心+暴力枚举】
- HRBUST
- HRBUST
- HRBUST
- HRBUST
- 20116.10.26 引用和指针
- MySQL复杂语句查询问题
- JDBC中Statement接口提供的execute、executeQuery和executeUpdate之间的区别
- NIO(3) FileChannel
- APUE笔记---第三章文件I/O
- hrbust 1055 Single【暴力预处理】
- 【HDU 2544】最短路裸题【测板】
- go-tour (1)
- 欧拉回路总结
- 单元测试和Mock方法
- scrapy 在不同的抓取级别的Request之间传递参数的办法
- 【poj】3320 Jessica's Reading Problem 尺取法+离散化
- HDU5080-Colorful Toy-2014鞍山K题-polay计数
- iOS常见面试题总结一