zoukankan      html  css  js  c++  java
  • Codeforces Round #419 (Div. 2) A. Karen and Morning(模拟)

    http://codeforces.com/contest/816/problem/A

    题意:

    给出一个时间,问最少过多少时间后是回文串。

    思路:

    模拟,先把小时的逆串计算出来:

    ① 如果逆串=分钟,那么此时已经是回文串了。

    ② 如果逆串>分钟,那么只需要逆串-分钟即可。(注意此时逆串>=60的情况)

    ③ 如果逆串<分钟,此时在这个小时内要构成回文串已经是不可能的了,那么就加上60-minute分钟,进入一个新的小时,然后重复上述步骤。

     1 #include<iostream>
     2 #include<algorithm>
     3 #include<cstring>
     4 #include<cstdio>
     5 #include<sstream>
     6 #include<vector>
     7 #include<stack>
     8 #include<queue>
     9 #include<cmath>
    10 #include<map>
    11 #include<set>
    12 using namespace std;
    13 typedef long long ll;
    14 typedef pair<int,int> pll;
    15 const int INF = 0x3f3f3f3f;
    16 const int maxn=3*1e5+5;
    17 
    18 char str[10];
    19 
    20 int main()
    21 {
    22     //freopen("in.txt","r",stdin);
    23     while(~scanf("%s",&str))
    24     {
    25         int hour = (str[0]-'0')*10 + (str[1]-'0');
    26         int minute = (str[3]-'0')*10+(str[4]-'0');
    27         int rev_h = (str[1]-'0')*10+str[0]-'0';
    28         int rev_m = (str[4]-'0')*10+(str[3]-'0');
    29 
    30         if(hour==rev_m)   {puts("0");continue;}
    31 
    32         int ans=0;
    33         while(true)
    34         {
    35             rev_h = (hour%10*10) + hour/10;
    36             if(rev_h == minute)  break;
    37             if(rev_h>minute && rev_h<60)
    38             {
    39                 ans+=rev_h-minute;
    40                 break;
    41             }
    42 
    43             else
    44             {
    45                 ans+=60-minute;
    46                 minute=0;
    47                 hour=(hour+1)%24;
    48             }
    49         }
    50         printf("%d
    ",ans);
    51     }
    52     return 0;
    53 }
  • 相关阅读:
    1438.最小公倍数
    1441.人见人爱A^B
    1083.特殊乘法
    1153.括号匹配
    1089.数字翻转
    1042.coincidence(动态规划求最长公共子序列)
    图的m着色问题pascal程序
    最佳调度问题pascal程序
    试卷批分打表程序
    迷宫问题pascal程序
  • 原文地址:https://www.cnblogs.com/zyb993963526/p/7082270.html
Copyright © 2011-2022 走看看