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 ;
}
CodeForces 686C-Robbers' watch的更多相关文章
- codeforces 686C C. Robbers' watch(dfs)
题目链接: C. Robbers' watch time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- Codeforces 658A. Robbers' watch 模拟
A. Robbers' watch time limit per test: 2 seconds memory limit per test: 256 megabytes input: standar ...
- Codeforces Round #359 div2
Problem_A(CodeForces 686A): 题意: \[ 有n个输入, +\space d_i代表冰淇淋数目增加d_i个, -\space d_i表示某个孩纸需要d_i个, 如果你现在手里 ...
- 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 ...
- Codeforces Round #359 (Div. 1) A. Robbers' watch 暴力
A. Robbers' watch 题目连接: http://www.codeforces.com/contest/685/problem/A Description Robbers, who att ...
- 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 ...
- codeforces 359 C - Robbers' watch
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Description Robb ...
- Codeforces Round #359 (Div. 2) C. Robbers' watch 搜索
题目链接:http://codeforces.com/contest/686/problem/C题目大意:给你两个十进制的数n和m,选一个范围在[0,n)的整数a,选一个范围在[0,m)的整数b,要求 ...
- 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 ...
- Robbers' watch CodeForces - 685A (暴力)
大意: 一天n小时, m分钟, 表以7进制显示, 求表显示数字不同的方案数 注意到小时和分钟部分总长不超过7, 可以直接暴力枚举. 关键要特判0, 0的位数要当做1来处理 #include <i ...
随机推荐
- 关于xfce中桌面没法显示回收站以及thunar中无法进行卷管理的解决办法
出现这种问题的原因应该不是当前用户没在storage这个组里,因为我试过将用户从storage组里移除并不对影响桌面上回收站的显示. 问题的原因是没有安装gvfs这个软件,装上之后,重新登录当前用户, ...
- iOS开发Hessian
HessianKit使用参考资料比较少,通过摸索,把测试过程贴出来,代码很乱,未整理,先实现功能,再应用到项目中.供新手参考.如有问题,跟帖指正... HessianService与Java Serv ...
- 解决redmine写操作很慢的问题
以前刚开始时用redmine是直接使用它的webrick服务器来运行的,后来为了提高性能,采用nginx+passenger的方式来驱动redmine,访问速度快了不少,但是在新建问题或更新问题时变得 ...
- Spring aop报错:com.sun.proxy.$Proxy cannot be cast to xxx
准备使用AOP记录所有NamedParameterJdbcTemplate操作数据时的所有日志,没想到出现这个错误,折腾了好久,终于找出原因 解决方案:在 aop-config配置添加上: proxy ...
- VC++6.0在Win7以上系统上Open或Add to Project files崩溃问题 解决新办法
崩溃原因是和office高版本冲突,比如我64位win7装了64位office2013及visio就遇到了这个问题(我很纳闷,记得重装系统前装的是32位office2013及visio就未曾遇到该问题 ...
- 使用VB6制作RTD函数
以前模仿大神在vs里使用c#实现RTD函数功能.(真是很生僻的东东啊)C#制作RTD参考:大神博客跳转.最近想VB里能不能做?就试着做了做,好像基本成了,整套代码有些毛病,勉强能算个样子,暂时不打算再 ...
- ITerm2下使用ssh访问Linux
通常情况下,iTerm2访问远程Linux使用ssh,与Termial基本一样,方法如下: ssh <用户名>@<ip> 然后输入访问的密码即可.当然还有的时候需要指定访问端口 ...
- js判断鼠标进入以及离开容器的方向
(注:以下代码涉及到jQuery,建议前端大牛绕路~~~) 1.遇到的问题 如图当鼠标右箭头位置上下移动的时候 下面的城市列表容器不能隐藏. 2.方法: 网上搜了些前端大牛们的解决办法 ...
- [poj1200]Crazy Search(hash)
Crazy Search Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 26713 Accepted: 7449 Descrip ...
- linux chomd 学习
chomd -R 777 directory_name :递归地给directory目录下所有文件和子目录的属主分配读的权限 ------2016-10-31 -- source: Linux chm ...