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条双向边,将双向边改为单向边,问无法到达的顶点最少有多少个? 分析: 无 ...
随机推荐
- zoj 2807 Electrical Outlets
Electrical Outlets Time Limit: 2 Seconds Memory Limit: 65536 KB Roy has just moved into a new a ...
- python和搜索
# -*- coding: UTF-8 -*- import re # 搜索逻辑 def querylogic(list): query = {} if len(list) > 1 or len ...
- php对象(继承,多态)
/2.继承//function abc(){// $arr = func_get_args();//}//子类只能有一个父类 一个父类 可以有多个子类//override 重写//overlood 重 ...
- BZOJ2059: [Usaco2010 Nov]Buying Feed 购买饲料
数轴上n<=500个站可以买东西,每个站位置Xi,库存Fi,价格Ci,运东西价格是当前运载重量的平方乘距离,求买K<=10000个东西到达点E的最小代价. f[i,j]--到第i站不买第i ...
- 《effective C++》:条款07——为多态基类声明virtual析构函数
在继承中,基类的析构函数需要定义为虚析构函数数否则: (1)当派生类对象经由一个base类指针删除时,而这个base类的析构函数不是虚函数时,其结果是未定义的. (2)这样做会导致derived类部分 ...
- Hadoop经典书籍资料收藏(35本)转
原文地址:http://www.hadoopor.com/thread-5128-1-2.html 1."Hadoop.Operations.pdf.zip" http://vdi ...
- ArcGIS engine中Display类库——Display
转自原文 ArcGIS engine中Display类库——Display Display类库包括了用于显示GIS数据的对象.除了负责实际输出图像的主要显示对象(display object)外,这 ...
- eclipse导入maven工程步骤
转自:http://jingyan.baidu.com/article/cbf0e500a6e3252eaa2893c1.html 感谢作者 步骤一 : 选择 “Import”操作 有两个途径可以选择 ...
- eclipse需要的环境变量就两个,一个是java_home指向JDK。另一个是Tomcat,自己去preference-sever下new一个
1.eclipse需要的环境变量就两个,一个是java_home指向JDK.另一个是Tomcat,自己去preference-sever下new一个
- 各种Js插件汇总;JavaScript插件
1.jquery信息提示插件: https://blog.csdn.net/u013517229/article/details/78291841 http://www.jqueryfuns.com/ ...