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 < 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)的更多相关文章
- 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
C. Robbers' watch time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- 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 ...
- 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 ...
- Codeforces Round #359 (Div. 1)
A http://codeforces.com/contest/685/standings 题意:给你n和m,找出(a,b)的对数,其中a满足要求:0<=a<n,a的7进制的位数和n-1的 ...
- 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 ...
- 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 ...
- Codeforces Round #359 (Div. 2) C
C. Robbers' watch time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
随机推荐
- WebClient+Fiddler2完美搭配下载远程页面信息
WebClient可以下载远程页面信息,这个大家应该都知道,核心代码如下: WebClient web = new WebClient(); string url = String.Format(&q ...
- Jqgrid入门-显示基本的表格(一)
首先对Jqgrid网格插件做个简要的说明.在众多的表格插件中,Jqgrid的特点是非常鲜明的. 特点如下: 完整的表格呈现与运算功能,包含换页.栏位排序.grouping.新增.修改及 ...
- GridView表头排序方法设置
1.效果图 2.前台代码 说明:红色代码为核心代码 <asp:GridView ID="gvData" runat="server" AutoGenera ...
- poj 1742 Coins
// v给出N种硬币和个数,问可以取到1->M中的多少个值.// 背包 完全背包 或多 重背包(二进制优化)都可以做// #include <iostream> #include & ...
- 修改dbwr后台进程数量
批量执行脚本时,批量数据写回到数据库:从EM中查看到有较多的dbwr的IO请求 查看后台dbwr的进程数量 select * from v$bgprocess 在查询结果中paddr的字段为非'0 ...
- Linux Shell 脚本
1. 写一个脚本,利用循环计算10的阶乘#!/bin/shfactorial=1for a in `seq 1 10`do factorial=`expr $factorial \* $a ...
- 移动开发之浅析cocos2d-x的中文支持问题
题记:这阵子一直在学习cocos2d-x,其跨平台的特性确实让人舒爽,引擎的框架概念也很成熟,虽然相应的第三方工具略显单薄,但也无愧是一件移动开发的利器啊,有兴趣的朋友有时间就多了解吧. 使用引擎的过 ...
- u-boot 源码修改 bootcmd,IP ,BOOTARGS等参数
uboot1.1.6\include\configs\smdk6410.h #define CONFIG_BOOTCOMMAND"nand read 0xc0008000 0x200000 ...
- hdu 4081 Qin Shi Huang's National Road System(最小生成树+dp)2011 Asia Beijing Regional Contest
同样是看别人题解才明白的 题目大意—— 话说秦始皇统一六国之后,打算修路.他要用n-1条路,将n个城市连接起来,并且使这n-1条路的距离之和最短.最小生成树是不是?不对,还有呢.接着,一个自称徐福的游 ...
- Mybatis拦截器介绍
拦截器的一个作用就是我们可以拦截某些方法的调用,我们可以选择在这些被拦截的方法执行前后加上某些逻辑,也可以在执行这些被拦截的方法时执行自己的逻辑而不再执行被拦截的方法.Mybatis拦截器设计的一个初 ...