Codeforces Round #359 (Div. 2)C. Robbers' watch

本文解析了CodeForces上的一道题目,该题要求在7进制表示下,找出时钟区和分钟区所有不重复数字的时间点数量。通过分析得出当位置超过7个时无解,并给出了一种暴力求解的方法。

链接: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;
}


评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值