链接:http://codeforces.com/contest/686/problem/C
题意:给定两个数n和m,将时钟区能显示0~n-1,分钟区能显示0~m-1。问所有的时间点中有多少满足要求。时钟区和分钟区的表示方式都是转成7进制表示,要求所有位置不能有重复的数字。
分析:因为是7进制,所有只能表示0~6这7个数字,一旦位置>7个那么肯定无解,然后<=7个位置直接暴力判断就行了。
代码:
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<bitset>
#include<math.h>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int N=100010;
const int MAX=1000000100;
const int mod=100000000;
const int MOD1=1000000007;
const int MOD2=1000000009;
const double EPS=0.00000001;
typedef long long ll;
const ll MOD=998244353;
const int INF=1000000010;
const double pi=acos(-1.0);
typedef double db;
typedef unsigned long long ull;
int wn,wm,tot,a[10];
int di(int x) {
int ret=0;
if (x==0) return 1;
while (x) {
ret++;x/=7;
}
return ret;
}
int check(int x,int y) {
int i,j,w;
w=wn;
while (x) {
a[w]=x%7;x/=7;w--;
}
while (w) { a[w]=0;w--; }
w=wm;
while (y) {
a[wn+w]=y%7;y/=7;w--;
}
while (w) { a[wn+w]=0;w--; }
for (i=1;i<tot;i++)
for (j=i+1;j<=tot;j++)
if (a[i]==a[j]) return 0;
return 1;
}
int main()
{
int i,j,n,m,ans;
scanf("%d%d", &n, &m);
wn=di(n-1);wm=di(m-1);tot=wn+wm;
if (tot>7) printf("0\n");
else {
ans=0;
for (i=0;i<n;i++)
for (j=0;j<m;j++)
if (check(i,j)) ans++;
printf("%d\n", ans);
}
return 0;
}
本文解析了CodeForces上的一道题目,该题要求在7进制表示下,找出时钟区和分钟区所有不重复数字的时间点数量。通过分析得出当位置超过7个时无解,并给出了一种暴力求解的方法。
1354

被折叠的 条评论
为什么被折叠?



