Robbers' watch CodeForces

大意: 一天n小时, m分钟, 表以7进制显示, 求表显示数字不同的方案数

注意到小时和分钟部分总长不超过7, 可以直接暴力枚举.

关键要特判0, 0的位数要当做1来处理

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '
'
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
//head




const int N = 1e6+10;
int x, y, tx, ty, vis[N];
int chk(int x, int y) {
	REP(i,0,6) vis[i]=0;
	REP(i,1,tx) ++vis[x%7],x/=7;
	REP(i,1,ty) ++vis[y%7],y/=7;
	REP(i,0,6) if (vis[i]>1) return 0;
	return 1;
}

int main() {
	scanf("%d%d", &x, &y), --x, --y;
	if ((ll)x*y>6543210) return puts("0"),0;
	for (int i=x; i; i/=7) ++tx;
	for (int i=y; i; i/=7) ++ty;
	tx = max(tx,1), ty = max(ty,1);
	int ans = 0;
	REP(i,0,x) REP(j,0,y) ans+=chk(i,j);
	printf("%d
", ans);
}
原文地址:https://www.cnblogs.com/uid001/p/10618067.html