CodeForces 686C-Robbers' watch

时间:2023-03-08 17:24:35
CodeForces 686C-Robbers' watch

题意:
  一个电子手表的示数是7进制的,现在告诉你一天有多少小时和一小时有多少分钟,问你一天里有多少个时刻,这个表上显示的数字各不相同.

分析:
  先找出表上有多少位数字,再按位dfs,看最后得到的数是否<n和<m,把分和时转化为7进制,若位数大于7则直接输出0,若不大于零,则用dfs找到分和时的所有位不相同的情况

代码如下:

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <ctime>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <iterator>
#include <vector> using namespace std; #define LL long long
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define MAXN 10000010
#define MAXM 1000010 #include <iostream>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <ctime>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <iterator>
#include <vector> using namespace std; #define LL long long
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define MAXN 10000010
#define MAXM 1000010 LL n, m;
int weishu_n, zongweishu_n_m, kinds_ans;
int a[]; int check()
{
int sum , x;
sum = ;
x = ;
for(int i = weishu_n-; i >= ; i--)
{
sum += x*a[i];
x *= ;
}
if(sum >= n)
return ;
sum = ;
x = ;
for(int i = zongweishu_n_m-; i >= weishu_n; i--)
{
sum += x*a[i];
x *= ;
}
if(sum >= m)
return ;
return ;
} void dfs(int cnt)
{
if(cnt == zongweishu_n_m)
{
if(check())
kinds_ans++;
}
else
for(int i = ; i < ; i++ )
{
int ok = ;
for(int j = ; j < cnt; j++ )
if(i == a[j])
{
ok = ;
break;
}
if(ok)
{
a[cnt] = i;
dfs(cnt+);
}
}
} int main()
{
int pos;
int kn, km;
while(scanf("%lld%lld", &n, &m)==)
{
memset(a, , sizeof(a));
kinds_ans = ;
weishu_n = ;
zongweishu_n_m = ;
pos = ;
kn = n-;
if(!kn)
pos++;
while(kn)
{
kn /= ;
pos++;
}
weishu_n = pos;
km = m-;
if(!km)
pos++;
while(km)
{
km /= ;
pos++;
}
zongweishu_n_m = pos;
dfs();
if(zongweishu_n_m > )
printf("0\n");
else
printf("%d\n", kinds_ans);
} return ;
}