Codeforces Round #359 (Div. 2) C. Robbers ' watch (violent Dfs)

Source: Internet
Author: User

Title Link: Http://codeforces.com/problemset/problem/686/C

Give you n and M, ask you how many pairs (a, b) meet 0<=a <n and 0 <=b < m and a 7 binary and n-1 7 binary bits are the same and B 7 is the same as the 7 digits of the m-1, and there are different numbers on each bit on the 7 binary of A and B.

Read the topic, it is very simple, first of all to determine whether A and B 7 of the number of digits more than 7, not more than the DFS violence enumeration calculation on it.

1 //#pragma COMMENT (linker, "/stack:102400000, 102400000")2#include <algorithm>3#include <iostream>4#include <cstdlib>5#include <cstring>6#include <cstdio>7#include <vector>8#include <cmath>9#include <ctime>Ten#include <list> One#include <Set> A#include <map> - using namespacestd; -typedefLong LongLL; thetypedef pair <int,int>P; - Const intN = 1e5 +5; - intnum[Ten], N, m, ans; - BOOLvis[Ten]; +  - int Get(intNum[],intLen) { +     intres =0, temp =1; A      for(inti = len; I >=1; --i) { atRes + = Num[len] *temp; -Temp *=7; -     } -     returnRes; - } -  in voidDfsintLen1,intLen2,intDEP) { -     if(DEP = = Len1 +len2) { to         intsum =0, temp =1; +          for(inti = Len1+len2; I >= len1+1; --i) { -Sum + = temp*Num[i]; theTemp *=7; *         } $         if(Sum <m)Panax Notoginsengans++; -         return ; the     } +     Else if(DEP = =len1) { A         intsum =0, temp =1; the          for(inti = len1; I >=1; --i) { +Sum + = temp*Num[i]; -Temp *=7; $         } $         if(Sum >=N) -             return ; -     }   thedep++; -      for(inti =0; I <7; ++i) {Wuyi         if(Vis[i]) the             Continue; -Vis[i] =true; WuNUM[DEP] =i; - dfs (LEN1, len2, DEP); AboutVis[i] =false; $     } -  - } -  A intMain () + { theCIN >> N >>m; -     intCnt1 =0, Cnt2 =0, temp = n-1; $      Do { theTemp/=7; the++cnt1; the} while(temp); thetemp = M-1; -      Do { inTemp/=7; the++Cnt2; the} while(temp); About     if(Cnt1 + Cnt2 >7) { thecout <<0<<Endl; the}Else { theDFS (Cnt1, Cnt2,0); +cout << ans <<Endl; -     } the     return 0;Bayi}

Codeforces Round #359 (Div. 2) C. Robbers ' watch (violent Dfs)

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.