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 ...
随机推荐
- SharePoint CMAL方式处理的 增,删,查,改
SPContext.Current.Web.Lists["UserInfo"]:获取网站的List,名称是:UserInfo userlist.AddItem():添加数据到Lis ...
- UVa 11489 (博弈) Integer Game
一个数字能被3整除就等价于这个数的各个数字之和被3整除. 所以一开始的时候先要拿一个能使剩下的数字是3的倍数的数. 然后就一直拿0.3.6.9直到某人不能再拿为止. #include <cstd ...
- SDOI 2010 and SXOI 2014 地精部落 (递推)
用E[i,j]表示共有i个数字,以1..j开头且一开始下降的方案数的总和.则我们有: E[i,j]:=E[I,J-1]+E[i-1,i-j] 我们先来证明上升与下降的方案是一一对应的. 事实上,若有a ...
- ActivityManager: Warning: Activity not started, its current task has been brought to the front 的的问题
运行android程序的时候提示:ActivityManager: Warning: Activity not started, its current task has been brought t ...
- [转:CSS3-前端] CSS3发光和多种图片处理
原文链接:http://www.qianduan.net/css3-image-styles.html 一些上流的CSS3图片样式 神飞 发表于 24. Sep, 2011, 分类: CSS , 46 ...
- 对于随机变量的标准差standard deviation、样本标准差sample standard deviation、标准误差standard error的解释
参考:http://blog.csdn.net/ysuncn/article/details/1749729
- 关于FastDFS Java客户端源码中的一个不太明白的地方
下面代码是package org.csource.fastdfs下TrackerGroup.java文件中靠近结束的一段代码,我下载的这个源码的版本是1.24. /** * return connec ...
- 最简单的视音频播放示例2:GDI播放YUV, RGB
前一篇文章对“Simplest Media Play”工程作了概括性介绍.后续几篇文章打算详细介绍每个子工程中的几种技术.在记录Direct3D,OpenGL这两种相对复杂的技术之前,打算先记录一种和 ...
- String.IsNullOrEmpty 方法
参数 value:一个String引用 返回值 如果 value 参数为 空引用(在 Visual Basic 中为 Nothing) 或空字符串 (""),则为 true:否则为 ...
- IOS 五星评分控件
程序中需要打分的功能,在网上找了几个,都不是很满意.下面是实现出的效果.可以点击,可以拖动. 使用方法:初始化控件. TQStarRatingView *starRatingView = [[TQSt ...