Codeforces Round #359 (Div. 2) C. Robbers' watch 暴力枚举

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/swust5120171204/article/details/102740205

题目链接

题意是真的烦,到最后才知道是n个m其实就是限定表的两个时区的位数,所以所当数不够填满时区的时候前边自动补零

思路:首先来说不能有重复的数字的话,小时和分钟的总位数大于7肯定不行。

7的7次方也才823543

所以说我们从把i从0枚举到n,j从0枚举到m即可。为什么复杂度是正确的?

其实就是考虑LenN+LenM<=7且n*m的最大是的多少(Len表示位数有多少)

考虑两个极限N1位,M6位,最大7*7^6 刚刚好7的7次方

                      N4位,M3位,最大7^3*7^4还是7^7,小于1e6的复杂度

//#pragma comment (linker, "/STACK:102400000,102400000")
#include<bits/stdc++.h>
#include<stdio.h>
#include<string.h>
#include<string>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<set>
#include<stack>
#include<vector>
#include<map>
#include<queue>
#include<list>
#include<time.h>
#define myself i,l,r
#define lson i<<1
#define rson i<<1|1
#define Lson i<<1,l,mid
#define Rson i<<1|1,mid+1,r
#define half (l+r)/2
#define lowbit(x) x&(-x)
#define min4(a, b, c, d) min(min(a,b),min(c,d))
#define min3(x, y, z) min(min(x,y),z)
#define max3(x, y, z) max(max(x,y),z)
#define max4(a, b, c, d) max(max(a,b),max(c,d))
//freopen("E://1.in","r",stdin);
//freopen("E://1.out","w",stdout);
typedef unsigned long long ull;
typedef long long ll;
#define pii make_pair
#define pr pair<int,int>
const int inff = 0x3f3f3f3f;
const int dir[4][2] = {0, 1, 0, -1, 1, 0, -1, 0};
const int mdir[8][2] = {0, 1, 0, -1, 1, 0, -1, 0, 1, 1, -1, 1, 1, -1, -1, -1};
const double eps = 1e-10;
const double PI = acos(-1.0);
const double E = 2.718281828459;
using namespace std;
const long long inFF = 9223372036854775807;
const int mod=1e9+7;
const int maxn=1e5+5;
int a[7];
int len1,len2;
int cal(ll x)
{
    x--;
    if(x==0) return 1;
    int ans=0;
    while(x){x/=7;ans++;}
    return ans;
}
bool check(int x,int y)
{
    int cnt=0;
    memset(a,0,sizeof(a));
    while(x){a[x%7]++;x/=7;cnt++;}
    a[0]+=len1-cnt;
    cnt=0;
    while(y){a[y%7]++;y/=7;cnt++;}
    a[0]+=len2-cnt;
    for(int i=0;i<=6;i++)
        if(a[i]>=2)
            return 0;
    return 1;
}
int main()
{
    ll n,m;
    cin>>n>>m;
    len1=cal(n),len2=cal(m);
    if(len1+len2>7)
    {
        cout<<0<<endl;
        return 0;
    }
    ll ans=0;
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            if(check(i,j)) ans++;
    cout<<ans<<endl;
}

猜你喜欢

转载自blog.csdn.net/swust5120171204/article/details/102740205
今日推荐