Codeforces 799(Div.4) D. The Clock

Victor has a 24-hour clock that shows the time in the format "HH:MM" (00 ≤ HH ≤ 23, 00 ≤ MM ≤ 59). He looks at the clock every x minutes, and the clock is currently showing time s.

How many different palindromes will Victor see in total after looking at the clock every xx minutes, the first time being at time s?

For example, if the clock starts out as 03:12 and Victor looks at the clock every 360360 minutes (i.e. every 66 hours), then he will see the times 03:12, 09:12, 15:12, 21:12, 03:12, and the times will continue to repeat. Here the time 21:12 is the only palindrome he will ever see, so the answer is 11.

A palindrome is a string that reads the same backward as forward. For example, the times 12:21, 05:50, 11:11 are palindromes but 13:13, 22:10, 02:22 are not.

Input

The first line of the input contains an integer tt (1≤t≤100) — the number of test cases. The description of each test case follows.

The only line of each test case contains a string s of length 5 with the format "HH:MM" where "HH" is from "00" to "23" and "MM" is from "00" to "59" (both "HH" and "MM" have exactly two digits) and an integer x (1≤x≤1440) — the number of minutes Victor takes to look again at the clock.

Output

For each test case, output a single integer — the number of different palindromes Victor will see if he looks at the clock every x minutes starting from time s.

_____________________________________________________________________________

input

6
03:12 360
00:00 1
13:22 2
15:15 10
11:11 1440
22:30 27

_____________________________________________________________________________

output

1
16
10
0
1
1
_____________________________________________________________________________

题解:

从00:00到23:59,回文串是固定的,共有16个。而题目中给了我们一个初始时间,每次要在这个时间上加上x分钟,我们如果直接在现在的时间上加上x分钟得到一个新的时间,执行起来会比较困难,而每个时间其实都对应着一个特定的和00:00的时间差,所以我们可以直接把时间转化成分钟,这样加x分钟执行起来也会很简单。所以我们最终只需要拿到所以可能出现的分钟(最终会回到最初的时间),这里我们可以用到set容器,因为set容器保证不会有重复数据出现。然后逐个判断set容器中的数据是否是回文串。

#include<iostream>
#include<set>
using namespace std;
const int p[16]={0,70,140,210,280,350,601,671,741,811,881,951,1202,1272,1342,1412};
int main(){
    int t;
    cin>>t;
    while(t--){
        char a[6];
        //f记录一开始的时间
        int x,data,sum=0,f;
        set<int>s;
        cin>>a>>x;
        f=((a[0]-'0')*10+(a[1]-'0'))*60+(a[3]-'0')*10+(a[4]-'0');
        s.insert(f);
        data=f+x;
        if(data>=1440){
            data-=1440;
        }
        while(data!=f){
            s.insert(data);
            data+=x;
            if(data>=1440){
                data-=1440;
            }
        }
        for(auto& i:s){
            for(auto& j:p){
                if(i==j){
                    sum++;
                    break;
                }
            }
        }
        cout<<sum<<endl;
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值