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条双向边,将双向边改为单向边,问无法到达的顶点最少有多少个? 分析: 无 ...
随机推荐
- Flask设计带认证token的RESTful API接口[翻译]
上一篇文章, 使用python的Flask实现一个RESTful API服务器端 简单地演示了Flask实的现的api服务器,里面提到了因为无状态的原则,没有session cookies,如果访问 ...
- NYOJ660逃离地球——只为最大存活率~
逃离地球 时间限制:1000 ms | 内存限制:65535 KB 难度: 描述 据霍金的<时间简史>所述,在几亿年之后将再次发生宇宙大爆炸.在宇宙大爆炸后,地球上将新生出许多生物而不 ...
- CentOS 中 YUM 安装桌面环境
CentOS 作为服务器的操作系统是很常见的,但是因为需要稳定而没有很时髦的更新,所以很少做为桌面环境.在服务器上通常不需要安装桌面环境,最小化地安装 CentOS(也就是 minimal CentO ...
- iview自定义配置
说明 iview是一套基于 Vue.js 的高质量 UI 组件库.主要用户PC端页面设计. 官网:https://www.iviewui.com/ 1.在vue-cli项目中,添加该框架 第一步,安装 ...
- 【UOJ179】线性规划(单纯形)
题意: 思路:单纯形模板 ..,..]of double; idx,idy,q:..]of longint; c:..]of double; n,m,i,j,op,x,y:longint; eps,m ...
- hdu3853:LOOPS
题目大意:r*c个点,每个点有Aij的概率回到自己本身,Bij的概率向右一格,Cij的概率向下一格,求从(1,1)到(r,c)的期望步数. 题解:有了hdu4405的经验,从后往前推期望.那么,E(i ...
- C#中的各种排序算法
原文发布时间为:2008-11-26 -- 来源于本人的百度文章 [由搬家工具导入] C#算法(一)选择排序using System;public class SelectionSorter{ ...
- spring boot 没有主清单属性
- CD-----UVa624(01背包+输出路径)
CD You have a long drive by car ahead. You have a tape recorder, but unfortunately your best musi ...
- 前端3D、动画相关开源JS
WebGL http://taobaofed.org/blog/2015/12/21/webgl-handbook/ D3 (或者叫 D3.js )是一个基于 web 标准的 JavaScript 可 ...