题目链接:http://codeforces.com/problemset/problem/686/C

给你n和m,问你有多少对(a, b) 满足0<=a <n 且 0 <=b < m 且a的7进制和n-1的7进制位数相同 且b的7进制和m-1的7进制位数相同,还有a和b的7进制上的每位上的数各不相同。

看懂题目,就很简单了,先判断a和b的7进制位数是否超过7,不超过的话就dfs暴力枚举计算就可以了。

 //#pragma comment(linker, "/STACK:102400000, 102400000")
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
typedef long long LL;
typedef pair <int, int> P;
const int N = 1e5 + ;
int num[], n, m, ans;
bool vis[]; int get(int num[], int len) {
int res = , temp = ;
for(int i = len; i >= ; --i) {
res += num[len] * temp;
temp *= ;
}
return res;
} void dfs(int len1, int len2, int dep) {
if(dep == len1 + len2) {
int sum = , temp = ;
for(int i = len1+len2; i >= len1+; --i) {
sum += temp*num[i];
temp *= ;
}
if(sum < m)
ans++;
return ;
}
else if(dep == len1) {
int sum = , temp = ;
for(int i = len1; i >= ; --i) {
sum += temp*num[i];
temp *= ;
}
if(sum >= n)
return ;
}
dep++;
for(int i = ; i < ; ++i) {
if(vis[i])
continue;
vis[i] = true;
num[dep] = i;
dfs(len1, len2, dep);
vis[i] = false;
} } int main()
{
cin >> n >> m;
int cnt1 = , cnt2 = , temp = n - ;
do {
temp /= ;
++cnt1;
} while(temp);
temp = m - ;
do {
temp /= ;
++cnt2;
} while(temp);
if (cnt1 + cnt2 > ) {
cout << << endl;
} else {
dfs(cnt1, cnt2, );
cout << ans << endl;
}
return ;
}

Codeforces Round #359 (Div. 2) C. Robbers' watch (暴力DFS)的更多相关文章

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

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

  2. 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 ...

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

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

  4. 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 ...

  5. Codeforces Round #359 (Div. 1) B. Kay and Snowflake dfs

    B. Kay and Snowflake 题目连接: http://www.codeforces.com/contest/685/problem/B Description After the pie ...

  6. Codeforces Round #359 (Div. 1)

    A http://codeforces.com/contest/685/standings 题意:给你n和m,找出(a,b)的对数,其中a满足要求:0<=a<n,a的7进制的位数和n-1的 ...

  7. Codeforces Round #359 (Div. 2) B. Little Robber Girl's Zoo 水题

    B. Little Robber Girl's Zoo 题目连接: http://www.codeforces.com/contest/686/problem/B Description Little ...

  8. Codeforces Round #359 (Div. 2) A. Free Ice Cream 水题

    A. Free Ice Cream 题目连接: http://www.codeforces.com/contest/686/problem/A Description After their adve ...

  9. Codeforces Round #359 (Div. 2) C

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

随机推荐

  1. Kaleidoscope for mac

    mac下的对比工具Kaleidoscope,是一款不错的对比工具,界面被广大用户所喜爱. window下使用beyond compare 3,具体设置步骤,请见:http://www.cnblogs. ...

  2. nodejs初写心得

    nodejs安装后如何查看和安装其他工具 网上nodejs的文章已经很多,这里只是写下自己的小小心得,如果能帮到别人当然更好. 安装nodejs这里就不叙述了,直接上nodejs官网下载就好了,初学者 ...

  3. perl基本语法

    标量 标量是 Perl 中最简单的数据类型.大多数的标量是数字(如 255 或 3.25e20)或者字符串(如 hello或者盖茨堡地址). 数字 perl中所有数字内部的格式都是双精度浮点数. 浮点 ...

  4. 4197: [Noi2015]寿司晚宴

    状压dp. 500分解质因数的话,除了最大的质因数只需要8个质数,用二进制x储存,最大的质因数用y来储存(若没有比那8个质数大的质因数就使y=1) 用f[i][j]表示第一个人方案为i,第二个人方案为 ...

  5. 发布 windows 10 universal app 时微软账号验证失败

    具体错误:Visual Studio encountered an unexpected network error and can't contact the Microsoft account s ...

  6. UVa 1658 (拆点法 最小费用流) Admiral

    题意: 给出一个有向带权图,求从起点到终点的两条不相交路径使得权值和最小. 分析: 第一次听到“拆点法”这个名词. 把除起点和终点以外的点拆成两个点i和i',然后在这两点之间连一条容量为1,费用为0的 ...

  7. BNU 4188 Superprime Rib【BFS】

    题意:给出n,输出n位超级质数,超级质数的定义为“依次去掉右边一位后仍然为质数的数” 因为一个n位质数去掉右边一位数之后仍然为质数,说明它是由n-1位超级质数演变而来的, 同理,n-1位超级质数也由n ...

  8. 安卓表格布局android:collapseColumns,android:shrinkColumns和stretchColumn

    TableLayout的行数由开发人员直接指定,即有多少个TableRow对象(或View控件),就有多少行. TableLayout的列数等于含有最多子控件的TableRow的列数.如第一Table ...

  9. HDU 5289 Assignment (数字序列,ST算法)

    题意: 给一个整数序列,多达10万个,问:有多少个区间满足“区间最大元素与最小元素之差不超过k”.k是给定的. 思路: 如果穷举,有O(n*n)复杂度.可以用ST算法先预处理每个区间最大和最小,O(n ...

  10. Java [Leetcode 67]Add Binary

    题目描述: Given two binary strings, return their sum (also a binary string). For example,a = "11&qu ...