题意:
  一个电子手表的示数是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 ;
}

CodeForces 686C-Robbers' watch的更多相关文章

  1. codeforces 686C C. Robbers' watch(dfs)

    题目链接: C. Robbers' watch time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  2. Codeforces 658A. Robbers' watch 模拟

    A. Robbers' watch time limit per test: 2 seconds memory limit per test: 256 megabytes input: standar ...

  3. Codeforces Round #359 div2

    Problem_A(CodeForces 686A): 题意: \[ 有n个输入, +\space d_i代表冰淇淋数目增加d_i个, -\space d_i表示某个孩纸需要d_i个, 如果你现在手里 ...

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

    C. Robbers' watch time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  5. Codeforces Round #359 (Div. 1) A. Robbers' watch 暴力

    A. Robbers' watch 题目连接: http://www.codeforces.com/contest/685/problem/A Description Robbers, who att ...

  6. Codeforces Round #359 (Div. 2) C. Robbers' watch (暴力DFS)

    题目链接:http://codeforces.com/problemset/problem/686/C 给你n和m,问你有多少对(a, b) 满足0<=a <n 且 0 <=b &l ...

  7. codeforces 359 C - Robbers' watch

    Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u   Description Robb ...

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

    题目链接:http://codeforces.com/contest/686/problem/C题目大意:给你两个十进制的数n和m,选一个范围在[0,n)的整数a,选一个范围在[0,m)的整数b,要求 ...

  9. Codeforces Round #359 (Div. 2) C. Robbers' watch 鸽巢+stl

    C. Robbers' watch time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  10. Robbers' watch CodeForces - 685A (暴力)

    大意: 一天n小时, m分钟, 表以7进制显示, 求表显示数字不同的方案数 注意到小时和分钟部分总长不超过7, 可以直接暴力枚举. 关键要特判0, 0的位数要当做1来处理 #include <i ...

随机推荐

  1. Java Spring DI之旅

    做过.NET的人很多都用过Microsoft Enterprise Library,里面有一个Dependency injection工具Unity,我们可以使用它来实现依赖注入:什么是依赖注入呢?我 ...

  2. 什么是REST、RESTful

    1.REST 指的是一组架构约束条件和原则.满足这些约束条件和原则的应用程序或设计就是 RESTful. 2.REST 原则是分层系统,这表示组件无法了解它与之交互的中间层以外的组件.通过将系统知识限 ...

  3. 161214、oracle查询表信息

    1.查找表的所有索引(包括索引名,类型,构成列): select t.*,i.index_type from user_ind_columns t,user_indexes i where t.ind ...

  4. mac 安装phpredis扩展

    curl -O https://nodeload.github.com/nicolasff/phpredis/zip/master tar -zxf master cd phpredis-master ...

  5. noi 8780 拦截导弹

    题目链接: http://noi.openjudge.cn/ch0206/8780/ LDS http://paste.ubuntu.com/23402528/

  6. ubuntu环境极其内存情况

    001:安装系统后 002:synergy 003:vim-cscope (修改vim脚本) 004:root 005:bashrc修改 006:bcompare 007:lib 008:git,gi ...

  7. EasyUI datebox 只读和取值

    <input id="dd" type="text" class="easyui-datebox" required="re ...

  8. linux atom 不支持中文

    linux atom 不支持中文 1.首先在ubuntu下安装泉驿正黑字体 sudo apt-get install ttf-wqy-* 2.Edit > Preferences > Se ...

  9. JavaScript高级应用(二)(转)

    1.组件是否安装 //组件是否安装 isComponentInstalled("{6B053A4B-A7EC-4D3D-4567-B8FF8A1A5739}", "com ...

  10. Ubuntu安装R及RStudio

    -------------------------------------------------------------- 自学记录,交流请发送邮件至gxz1984@gmail.com ------ ...