Hdu 5943 (prime interval + binary graph matching)

Source: Internet
Author: User

Kingdom of Obsession

Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): Accepted submission (s): 64


Problem Descriptionthere is a kindom of obsession, so people in this kingdom do things very strictly.

They name themselves in integer, and there isNPeople with their ID continuous(S+1,S+2,? ,s +n) Standing in a line in arbitrary order, being more obsessively, people with IDxWants to stand at yth Position which satisfy

X mody< Span id= "mathjax-span-41" class= "Mo" style= "font-family:mathjax_main; Padding-left:0.278em ">= 0

Is there any satisfy everyone ' s requirement?

Inputfirst line contains an integerT, which indicates the number of test cases.

Every test case contains one line with the integersN,s.

Limits
1≤T≤ .
1≤n≤9 .
0≤s≤9 .

Outputfor every test case, should output ' case #x: Y ', where xIndicates the case number and counts from 1and yis the result string.

If there is an any-to-satisfy everyone's requirement, yequals ' Yes ', otherwise yequals ' No '.

Sample INPUT25 144 11

Sample outputcase #1: nocase #2: Yes

Source 2016 China University student Program Design Competition (Hangzhou) When I think about the number of prime number two times can not match, but did not think of prime spacing (the subconscious thought that the prime number within 2 billion is definitely spaced very large). 2 billion The maximum interval between two primes will not exceed 300, So more than 600 direct output No. So the solution is the small data binary map matching, big data directly output No. To prevent the intersection of the interval, we should give a special n,s size.
#include <stdio.h>#include<algorithm>#include<string.h>#include<math.h>using namespaceStd;typedefLong LongLL;Const intN = .;intS,n;intGraph[n][n];intLinker[n];BOOLVis[n];BOOLDfsintu) {     for(intI=1; i<=n;i++){        if(graph[u][i]==1&&!Vis[i]) {Vis[i]=true; if(linker[i]==-1||DFS (Linker[i])) {Linker[i]=u; return true; }        }    }    return false;}intMain () {intt =1, Tcase; scanf ("%d",&tcase);  while(tcase--) {scanf ("%d%d",&s,&N); if(s<N) swap (s,n); if(n> +) {printf ("Case #%d:no\n", t++); Continue; } memset (graph,0,sizeof(graph)); intres =0;  for(intI=1; i<=n;i++){            intt = i+s;  for(intj=1; j<=n;j++){                if(t%j==0) {Graph[i][j]=1; }}} memset (linker,-1,sizeof(linker));  for(intI=1; i<=n;i++) {memset (Vis,0,sizeof(VIS)); if(Dfs (i)) res++; }        if(res==N) {printf ("Case #%d:yes\n", t++); }Elseprintf"Case #%d:no\n", t++); }    return 0;}

Hdu 5943 (prime interval + binary graph match)

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.