题目链接: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. [转]ASP.NET数据库连接字符串总结

    这个不难,而且很重要,但总忘,找了篇比较全的,作为资料. 原文链接http://developer.51cto.com/art/201107/275406.htm 关于数据库链接字符串的相关知识,我们 ...

  2. UVA 10298 Power Strings 字符串的幂(KMP,最小循环节)

    题意: 定义a为一个字符串,a*a表示两个字符相连,即 an+1=a*an ,也就是出现循环了.给定一个字符串,若将其表示成an,问n最大为多少? 思路: 如果完全不循环,顶多就是类似于abc1这样, ...

  3. Java Socket(1): 入门

    前言:在最近一个即将结束的项目中使用到了Socket编程,用于调用另一系统进行处理并返回数据.故把Socket的基础知识总结梳理一遍. 一.TCP/IP协议 既然是网络编程,涉及几个系统之间的交互,那 ...

  4. Dataguard三种保护模式

    Oracle Data Guard 提供三种高水平的数据保护模式来平衡成本.可用性.性能和事务保护.可以使用任意可用管理界面来轻松地设置这些模式.要确定适当的数据保护模式,企业需要根据用户对系统响应时 ...

  5. cmd远程连接数据库

    在本地配置tnsname 打开C:\oracle\ora92\network\ADMIN\tnsnames.ora 加入如下参数. ora = (DESCRIPTION = (ADDRESS_LIST ...

  6. C#的switch与二维数组.....

    今天由于工作上的需要, 改了几行C#  的代码, 发现有一些细微的语法区别,与C++, 像switch语句那样, 我一般不会在default后面加上break,语句, 可是发现如果不加上的话,就会报下 ...

  7. Asp.net 将DataTable 或者DataSet 转换为Json 格式

    Web 开发中,将从数据库中取到的数据直接转换为 Json 格式的数据,在前台通过Ajax 无刷新显示在界面上,下面提供将DataTable 或者DataSet 转换为Json 的方法 /// < ...

  8. WPF MultiBinding 和 IMultiValueConverter

    MultiBinding,描述附加到单个绑定目标属性的Binding对象的集合.可以指定多个数值绑定. IMultiValueConverter通过转换器使用MultiBingding对象,该对象讲根 ...

  9. 1050 数的计数 c语言实现

    描述 给定一个正整数,求其各位之和. 输入 输入一行,为一个正整数(最多10,000位). 输出 输出各位之和. 样例输入 17 样例输出 8 解析:这题主要是大数计算的问题,因为10000位的数无法 ...

  10. java web 学习五(servlet开发1)

    一.Servlet简介 Servlet是sun公司提供的一门用于开发动态web资源的技术. Sun公司在其API中提供了一个servlet接口,用户若想用发一个动态web资源(即开发一个Java程序向 ...