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 ...
随机推荐
- 通过setDB2Client*来方便的使用TRACE调优jdbc程序
一般来说通过TRACE的report来分析DDF的性能问题的话,基本对DBA都是噩梦一样.因为所有的Thread都是通过DDF一个类型的Thread,所以不管你怎么分类,看Accounting rep ...
- POJ - 1978 Hanafuda Shuffle
最初给牌编号时,编号的顺序是从下到上:洗牌时,认牌的顺序是从上到下.注意使用循环是尽量统一“i”的初始化值,都为“0”或者都为“1”,限界条件统一使用“<”或者“<=”. POJ - 19 ...
- JavaWeb应用开发架构浅谈
本文就我所经历和使用过的技术和框架, 讨论 Java / Javascript 技术组合构成的Web 应用架构. 一. 概述 Web 应用架构可以划分为两大子系统:前端子系统和后台子系统. 前端子系统 ...
- Linux 多线程编程 实例 1
子线程循环 10 次,接着主线程循环 100 次,接着又回到子线程循环 10 次,接着再回到主线程又循环 100 次,如此循环50次,试写出代码. #include <pthread.h> ...
- Intel+Ardruino 101 翻转时点灯
/* =============================================== Example sketch for CurieIMU library for Intel(R ...
- 使用IOS7原生API进行二维码条形码的扫描
使用IOS7原生API进行二维码条形码的扫描 IOS7之前,开发者进行扫码编程时,一般会借助第三方库.常用的是ZBarSDK,IOS7之后,系统的AVMetadataObject类中,为我们提供了解析 ...
- Auty自动化测试框架第三篇——添加异常处理与日志收集
[本文出自天外归云的博客园] 本次对框架进行完善,增加了日志收集功能和修饰运行功能,完善后的lib目录如下:
- WebForm水印照片
水印照片需要的元素 绘制:1.画布2.画笔 样式 粗细 颜色3.画什么东西4.用什么字体画 大小5.位置 展示页面 <%@ Page Language="C#" AutoEv ...
- chrome 开发者工具详解
Google Chrome一共提供了8大组工具: Elements: 允许我们从浏览器的角度看页面,也就是说我们可以看到chrome渲染页面所需要的的HTML.CSS和DOM(Document Obj ...
- 从零开始学iPhone开发(2)——控件的使用
这一节我们开始学习iOS中简单控件的使用. 在iOS编程中,简单的控件有很多,其中主要的用的多的有: UILabel,UIButton,UISegmentedControl, UITextField, ...