Kingdom of Obsession
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): Accepted submission (s): 14
Problem Descriptionthere is a kindom of obsession, so people in this kingdom do things very strictly.
They name themselves in integer, and there is NPeople with their ID continuous(s+1,s+2,?,s+n) Standing in a line in arbitrary order, being more obsessively, people with IDx wants to stand at Yth position which satisfy
x mod y =0
Is there any satisfy everyone ' s requirement?
Inputfirst line contains an integer T, 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
SOURCE2016 Chinese College Student Program Design Competition (hangzhou)
recommendliuyiding | We have carefully selected several similar problems for you:5943 5942 5941 5940 5939
Statistic | Submit | Discuss | Note
Topic links:
http://acm.hdu.edu.cn/showproblem.php?pid=5943
Main Topic:
Given s,n, put s+1,s+2, ... S+n This n number is filled to,..., n, requiring X to fill only the position of the factor x. (I.E. x%y=0, then x can be placed in Y Position)
Ask if it can be filled.
Topic ideas:
"binary Map Matching Hungarian algorithm"
first, If s<n, then S+1,S+2...N these numbers directly in S+1,s+2...n's Position.
(if the other number x is placed above these positions, these numbers are not placed in the corresponding position, then the x must be placed in the position of these numbers, so the direct exchange can Be)
So you can swap s and n directly to reduce N.
Then look at n consecutive numbers, if there are 2 Primes. Then there must be no solution (all can only put 1)
So we can estimate the maximum interval of prime number (i take 504), n exceeds the inevitable no Solution.
N less than 504 of the case, direct violence to build the edge (can be evenly divisible on the edge), and then run the two-figure matching can Be.
View Code
HDU 5943 Kingdom of obsession "binary map matching Hungarian algorithm" (2016 Chinese College Student Program Design Competition (HANGZHOU))