日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【 HRBUST - 1055】Single(模拟,dp,打表)(总结)

發布時間:2023/12/10 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【 HRBUST - 1055】Single(模拟,dp,打表)(总结) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

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)

Input

First 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)

Output

For each case, just give us the answer in a single line, no extra character is needed.

Sample Input

3?
00:00:00?
00:00:01?
00:00:02

Sample Output

0?
1?
1

題目大意:

? ?給你一個時間t,讓你計算從00:00:00到當前時間(包括當前時間這一秒)一共出現了多少次數字1.

解題報告:

? ?預處理到一個dp數組中就好了。tmp那里也可以直接寫成=,然后dp[cur]=dp[cur-1]+tmp。也可以,其實是等價的。

AC代碼:

#include<bits/stdc++.h> #define ll long longusing namespace std; int dp[24*60*60 + 60*60 + 60 + 5]; int cal(int x) {int res=0;while(x) {if(x%10==1) res++;x/=10;}return res; } void init() {int tmp=0;int a=0,b=0,c=0;//時,分,秒 while(a<24) {//計算當前狀態 tmp+=cal(a)+cal(b)+cal(c);dp[a*60*60+b*60+c]=tmp;//預備下一個狀態 c++;if(c==60) {c=0,b++;if(b==60) b=0,a++;}} } int main() {init();int t;cin>>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",dp[tmp]);} }

總結:

? ?熟悉一下模擬時的語句模式和套路:while循環中干兩件事情,1.計算當前狀態下的值,2.將下一個狀態準備好。

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的【 HRBUST - 1055】Single(模拟,dp,打表)(总结)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。