zoukankan      html  css  js  c++  java
  • Codeforces Round #359 (Div. 2) C

    C. Robbers' watch
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches.

    First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hours, and each hour in m minutes. Personal watches of each robber are divided in two parts: first of them has the smallest possible number of places that is necessary to display any integer from 0 to n - 1, while the second has the smallest possible number of places that is necessary to display any integer from 0 to m - 1. Finally, if some value of hours or minutes can be displayed using less number of places in base 7 than this watches have, the required number of zeroes is added at the beginning of notation.

    Note that to display number 0 section of the watches is required to have at least one place.

    Little robber wants to know the number of moments of time (particular values of hours and minutes), such that all digits displayed on the watches are distinct. Help her calculate this number.

    Input

    The first line of the input contains two integers, given in the decimal notation, n and m (1 ≤ n, m ≤ 109) — the number of hours in one day and the number of minutes in one hour, respectively.

    Output

    Print one integer in decimal notation — the number of different pairs of hour and minute, such that all digits displayed on the watches are distinct.

    Examples
    Input
    2 3
    Output
    4
    Input
    8 2
    Output
    5
    Note

    In the first sample, possible pairs are: (0: 1), (0: 2), (1: 0), (1: 2).

    In the second sample, possible pairs are: (02: 1), (03: 1), (04: 1), (05: 1), (06: 1).

    题意: 一天有n个小时,每个小时m分钟  手表为7进制数表示时间,每一位的数字不能重复 问能表示多少种组合的时间

    题解:首先判断 若要表示n小时m分钟需要多少位,若超过7位则输出0

            否则 分别判断n*m的组合 是否满足条件 (缺位的情况下补零)

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    using namespace std;
    int n,m;
    int len1,len2;
    bool  fun(int aa,int bb)
    {
        int sa[10];
        int sb[10];
        memset(sa,0,sizeof(sa));
        memset(sb,0,sizeof(sb));
        int len3=len1;int len4=len2;
         while(1)
         {
             sa[len3--]=aa%7;
             aa/=7;
             if(aa==0)
               break;
         }
         while(len3>1)
            sa[len3--]=0;
         while(1)
         {
             sb[len4--]=bb%7;
             bb/=7;
             if(bb==0)
               break;
         }
         while(len4>1)
            sb[len4--]=0;
         for(int i=1;i<=len1;i++)
            for(int j=i+1;j<=len1;j++)
            if(sa[i]==sa[j])
            return false;
          for(int i=1;i<=len2;i++)
            for(int j=i+1;j<=len2;j++)
            if(sb[i]==sb[j])
            return false;
         for(int i=1;i<=len1;i++)
            for(int j=1;j<=len2;j++)
         {
             if(sa[i]==sb[j])
                return false;
         }
         return true;
    }
    int main()
    {
        scanf("%d %d",&n,&m);
        int q1=n-1,q2=m-1;
        len1=0;len2=0;
        int ans=0;
        while(1)
        {
          q1/=7;
          len1++;
          if(q1==0)
            break;
        }
        while(2)
        {
          q2/=7;
          len2++;
          if(q2==0)
            break;
        }
        if(len1+len2>7)
            printf("0
    ");
        else{
            for(int i=0;i<n;i++)
                for(int j=0;j<m;j++)
            {
                if(fun(i,j))
                    ans++;
            }
            cout<<ans<<endl;
        }
    
        return 0;
    }
  • 相关阅读:
    winform访问https webservice
    rabbitMQ访问失败
    Redis断线测试
    微信消息推送
    线程控制
    Oracle.ManagedDataAccess.dll折腾了我两天
    IPC网络摄像机rtsp视频流web上H5播放方法
    微软补丁下载网站(备忘)
    ABP vnext 种子文件更新
    ABP vnext 使用Swagger账号登录时Chrome浏览器提示【The cookie 'XSRF-TOKEN' has set 'SameSite=None' and must also set 'Secure'.】错误,不能跳转登录
  • 原文地址:https://www.cnblogs.com/hsd-/p/5613789.html
Copyright © 2011-2022 走看看