2016杭州ccpc
生活随笔
收集整理的這篇文章主要介紹了
2016杭州ccpc
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Kingdom of Obsession
標簽:?二分圖最大匹配 2016-10-29 16:23?51人閱讀?評論(2)?收藏?舉報 ?分類: 二分圖和最大匹配(2)?版權聲明:本文為棒(xian)棒(yu)博主原創文章,轉載請注明出處哦~
Kingdom of Obsession
Time Limit: 2000/1000 MS (Java/Others)????Memory Limit: 65536/32768 K (Java/Others)Problem Description There is a kindom of obsession, so people in this kingdom do things very strictly.
They name themselves in integer, and there are?n?people with their id continuous?(s+1,s+2,?,s+n)?standing in a line in arbitrary order, be more obsessively, people with id?x?wants to stand at?yth?position which satisfy
xmody=0
Is there any way to satisfy everyone's requirement?
Input First line contains an integer?T, which indicates the number of test cases.
Every test case contains one line with two integers?n,?s.
Limits
1≤T≤100.
1≤n≤109.
0≤s≤109.
Output For every test case, you should output?'Case #x: y', where?x?indicates the case number and counts from?1?and?y?is the result string.
If there is any way to satisfy everyone's requirement,?y?equals?'Yes', otherwise?y?equals?'No'.
Sample Input 2 5 14 4 11
Sample Output Case #1: No Case #2: Yes
題意:我想來到這的都不用講什么題意的吧。
思路:估計也都能想到利用二分圖最大匹配來確定是不是能夠全匹配,重點是n很大啊。
不過我們知道素數有個特性就是因數只有1和它本身。所以素數只能待在位置1或者標號為本身的位置上
1.如果m>n
如果n大于等于兩個素數之間的距離,那么肯定是不可能匹配的。
如果小于直接二分圖匹配一下。
2.如果m<=n
黃色部分長度為m如果m的長度大于等于兩個素數的間隔那肯定是不符合題意。
如果小于那么就把m部分二分圖匹配,匹配的話肯定符合題意,不匹配的話不符合題意,至于為什么不和重合部分匹配,看評論。
這兩個一綜合就會發現第二種如果mn互換和第一種是一樣的。
至于二分圖匹配:
就是n個點之間的匹配,如果兩個點之間滿足等式就連一條邊,最后看看能不能全匹配上就可以了。
[cpp]?view plaincopy print?
總結
以上是生活随笔為你收集整理的2016杭州ccpc的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: POJ3420 Quad Tiling(
- 下一篇: Message Flood