codeforces 686C C. Robbers' watch(dfs)
题目链接:
2 seconds
256 megabytes
standard input
standard output
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches.
First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hours, and each hour in m minutes. Personal watches of each robber are divided in two parts: first of them has the smallest possible number of places that is necessary to display any integer from 0 to n - 1, while the second has the smallest possible number of places that is necessary to display any integer from 0 to m - 1. Finally, if some value of hours or minutes can be displayed using less number of places in base 7 than this watches have, the required number of zeroes is added at the beginning of notation.
Note that to display number 0 section of the watches is required to have at least one place.
Little robber wants to know the number of moments of time (particular values of hours and minutes), such that all digits displayed on the watches are distinct. Help her calculate this number.
The first line of the input contains two integers, given in the decimal notation, n and m (1 ≤ n, m ≤ 109) — the number of hours in one day and the number of minutes in one hour, respectively.
Print one integer in decimal notation — the number of different pairs of hour and minute, such that all digits displayed on the watches are distinct.
2 3
4
8 2
5 题意: 每天n小时,每小时m分钟,现在给你一个7进制的表,问出现的所有的时间中数字全不相同的时间有多少个; 思路: 先找出表上有多少位数字,再按位dfs,看最后得到的数是否<n和<m,计数就好; AC代码:
//#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <cstring>
#include <algorithm>
#include <cstdio> using namespace std;
#define Riep(n) for(int i=1;i<=n;i++)
#define Riop(n) for(int i=0;i<n;i++)
#define Rjep(n) for(int j=1;j<=n;j++)
#define Rjop(n) for(int j=0;j<n;j++)
#define mst(ss,b) memset(ss,b,sizeof(ss));
typedef long long LL;
template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<''||CH>'';F= CH=='-',CH=getchar());
for(num=;CH>=''&&CH<='';num=num*+CH-'',CH=getchar());
F && (num=-num);
}
int stk[], tp;
template<class T> inline void print(T p) {
if(!p) { puts(""); return; }
while(p) stk[++ tp] = p%, p/=;
while(tp) putchar(stk[tp--] + '');
putchar('\n');
} const LL mod=1e9+;
const double PI=acos(-1.0);
const LL inf=1e18;
const int N=(<<)+;
const int maxn=; LL n,m,ans=;
int a[],b[],cnt1=,cnt2=,vis[];
LL fn,fm;
LL p[]; void DFS2(int po,LL num)
{
if(po>cnt2)
{
if(num<fm)ans++;
return ;
}
for(int i=;i<;i++)
{
if(!vis[i])
{
vis[i]=;
DFS2(po+,num+(LL)i*p[po]);
vis[i]=;
}
} } void DFS1(int po,LL num)
{
if(po>cnt1)
{
if(num<fn){DFS2(,);}
return ;
}
for(int i=;i<;i++)
{
if(!vis[i])
{
vis[i]=;
DFS1(po+,num+(LL)i*p[po]);
vis[i]=;
}
}
} int main()
{
read(n);read(m);
fn=n,fm=m;
if(n>)n--;
if(m>)m--;
LL w=;
for(int i=;i<;i++)
{
p[i]=w;
w=w*;
}
while(n)
{
a[++cnt1]=n%;
n/=;
}
while(m)
{
b[++cnt2]=m%;
m/=;
}
mst(vis,);
ans=;
DFS1(,);
cout<<ans<<"\n";
return ;
}
codeforces 686C C. Robbers' watch(dfs)的更多相关文章
- codeforces 615 B. Longtail Hedgehog (DFS + 剪枝)
题目链接: codeforces 615 B. Longtail Hedgehog (DFS + 剪枝) 题目描述: 给定n个点m条无向边的图,设一条节点递增的链末尾节点为u,链上点的个数为P,则该链 ...
- codeforces 711D Directed Roads(DFS)
题目链接:http://codeforces.com/problemset/problem/711/D 思路:由于每个点出度都为1,所以没有复杂的环中带环.DFS遍历,若为环则有2^k-2种,若为链则 ...
- Codeforces 600 E. Lomsat gelral (dfs启发式合并map)
题目链接:http://codeforces.com/contest/600/problem/E 给你一棵树,告诉你每个节点的颜色,问你以每个节点为根的子树中出现颜色次数最多的颜色编号和是多少. 最容 ...
- Codeforces 711 D. Directed Roads (DFS判环)
题目链接:http://codeforces.com/problemset/problem/711/D 给你一个n个节点n条边的有向图,可以把一条边反向,现在问有多少种方式可以使这个图没有环. 每个连 ...
- Vasya and a Tree CodeForces - 1076E(线段树+dfs)
I - Vasya and a Tree CodeForces - 1076E 其实参考完别人的思路,写完程序交上去,还是没理解啥意思..昨晚再仔细想了想.终于弄明白了(有可能不对 题意是有一棵树n个 ...
- Codeforces 931D Peculiar apple-tree(dfs+思维)
题目链接:http://codeforces.com/contest/931/problem/D 题目大意:给你一颗树,每个节点都会长苹果,然后每一秒钟,苹果往下滚一个.两个两个会抵消苹果.问最后在根 ...
- Codeforces 375D - Tree and Queries(dfs序+莫队)
题目链接:http://codeforces.com/contest/351/problem/D 题目大意:n个数,col[i]对应第i个数的颜色,并给你他们之间的树形关系(以1为根),有m次询问,每 ...
- Codeforces 667C Reberland Linguistics【DFS】
一道卡题意的题. 题目链接: http://codeforces.com/problemset/problem/667/C 题意: 一个串可以看成一个长度大于4的根,加上其后面的若干个相邻(in a ...
- Codeforces 659E New Reform【DFS】
题目链接: http://codeforces.com/problemset/problem/659/E 题意: 给定n个点和m条双向边,将双向边改为单向边,问无法到达的顶点最少有多少个? 分析: 无 ...
随机推荐
- spring的IOC入门案例
步骤: 一,导入jar 二,创建类,在类里创建方法 三,创建Spring配置文件,配置创建类 四,写代码测试对象创建
- 第八届河南省程序设计大赛-B.最大岛屿0000110011000000
最大岛屿 时间限制: ...
- 【Kubernetes】Kubernetes删除namespace后持续terminating状态
删除isti和foo的配置文件之后,namespace持续terminating状态,此时也无法再创建istio-system的namespace namespace "istio-syst ...
- Linux核心参数Shmmax,shmall,shmni
Linux 下核心参数调整 kernel.shmmax shmmax是核心参数中最重要的参数之一,用于定义单个共享内存段的最大值,shmmax设置应足够大,能在一个共享内存段下容纳下整个的SGA,设置 ...
- 在eclipse中画类图
学习设计模式的时候,希望能够画出类图,理清关系.但是StarUML还有重新去写类名.属性.方法等,不是很方便.网上给出了安装插件的方法额,就可以直接在eclipse中拖拽类,很方便.但是网上给出的插件 ...
- python之-- 异常
异常处理: 语法:try: codeexcept (KeyError..可以写多个) as e: error为抓取的多个错误提示,e为错误信息 print(e) # 打印错误信息except (Ind ...
- 一致性哈希算法-----> 解决memecache 服务器扩容后的数据丢失。
1 基本场景 比如你有 N 个 cache 服务器(后面简称 cache ),那么如何将一个对象 object 映射到 N 个 cache 上呢,你很可能会采用类似下面的通用方法计算 object 的 ...
- FATE---hdu2159(二重背包)
FATE Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- Atom替换换行符
直接[Ctrl]+[F],然后选择正则,输入\n
- DotProject首页、文档和下载 - 项目管理工具 - 开源中国社区
DotProject首页.文档和下载 - 项目管理工具 - 开源中国社区