Codeforces Round #359 (Div. 2) C. Robbers ' Watch

Source: Internet
Author: User

Topic Link: Portal

The main topic: there is a table, by 7, you will be divided into n hours a day, an hour into M minutes, the table is required to show the number of different, ask how many legal time in the n,m limit

For example n=2,m=3 (0:1), (0:2), ( 1:0), ( 1:2). n=8,m=2 (02:1), (03:1), ( 04:1), ( 05:1 ), (06:1).

Topic idea: Because it is represented by 7, so the number displayed on the watch can not be more than 7, otherwise there must be duplicate (illegal), so we only need a special sentence, and then Dfs can.

This question is still more regrettable, at that time did not make out at night, woke up in the morning to find the boundary situation a bit of a problem, changed a bit over, oneself or is too weak.

#include <iostream>#include<cstdio>#include<cstdlib>#include<cmath>#include<algorithm>#include<cstring>#include<stack>#include<cctype>#include<queue>#include<string>#include<vector>#include<Set>#include<map>#include<climits>#defineLson Root<<1,l,mid#defineRson Root<<1|1,mid+1,r#defineFi first#defineSe Second#definePing (x, y) ((x-y) * (x-y))#defineMST (x, y) memset (x,y,sizeof (x))#defineMCP (x, y) memcpy (x,y,sizeof (y))using namespacestd;#defineGamma 0.5772156649015328606065120#defineMOD 1000000007#defineINF 0x3f3f3f3f#defineN 100005#defineMAXN 1005typedef pair<int,int>Pii;typedefLong LongLL;intn,m,k,x,num,y;intvis[Ten],ans;voidDFS2 (intSumintCNT) {///dfs2 processing minutes (m), other and DFS1 empathy    if(sum>=m)return; if(cnt==y) {++ans;return;}  for(intI=0;i<7;++i) {        if(!Vis[i]) {Vis[i]=1; Sum=sum*7+i; DFS2 (sum,cnt+1); Sum= (sum-i)/7; Vis[i]=0; }    }}voidDFS1 (intSumintCNT) {///DFS1 Processing hour segment (n), sum represents the current time (sum<n),if (sum>=n) return; ///CNT says several numbers have been processed.    if(cnt==x) {         for(intj=0;j<7; ++j)if(!Vis[j]) {Vis[j]=1; DFS2 (J,1); VIS[J]=0; }    }     for(intI=0;i<7;++i) {        if(!Vis[i]) {Vis[i]=1; Sum=sum*7+i; DFS1 (sum,cnt+1); Sum= (sum-i)/7; Vis[i]=0; }    }}intDealintx) {///Special handling, returns how many digits are required to represent n,m    intCnt=0;  while(x) {++CNT; X=x/7; }    returnCNT;}intMain () {inti,j,group,v; scanf ("%d%d",&n,&m); if(n%7==0) X=deal (n1);///It is important to note that if n can be divisible by 7    ElseX=deal (n);///so the number of digits required for n is reduced by one, that is, it is not considered clear, it is a pity.     if(m%7==0) Y=deal (M-1);///m-Empathy processing    Elsey=deal (m); if(x+y>7) {exit (0*printf ("0\n"));}  for(i=0;i<7;++i) {Vis[i]=1; DFS1 (i,1); Vis[i]=0; } printf ("%d\n", ans); return 0;}

Codeforces Round #359 (Div. 2) C. Robbers ' Watch

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.