日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【HDU - 5943】Kingdom of Obsession(数论,素数间隔结论,构造,思维,匈牙利算法,匹配问题)

發布時間:2023/12/10 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【HDU - 5943】Kingdom of Obsession(数论,素数间隔结论,构造,思维,匈牙利算法,匹配问题) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

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

They name themselves in integer, and there are?nn?people with their id continuous?(s+1,s+2,?,s+n)(s+1,s+2,?,s+n)?standing in a line in arbitrary order, be more obsessively, people with id?xx?wants to stand at?ythyth?position which satisfy?

xmody=0xmody=0
Is there any way to satisfy everyone's requirement?

Input

First line contains an integer?TT, which indicates the number of test cases.?

Every test case contains one line with two integers?nn,?ss.?

Limits?
1≤T≤1001≤T≤100.?
1≤n≤1091≤n≤109.?
0≤s≤1090≤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?yequals?'No'.

Sample Input

2 5 14 4 11

Sample Output

Case #1: No Case #2: Yes

題目大意:

給定S,N,把S+1,S+2,...S+N這N個數填到1,2,...,N里,要求X只能填到X的因子的位置。(即X%Y=0,那么X才能放在Y位置)。問是否能夠放滿。

解題報告:

首先打表猜出素數的間隔不會超過300,于是乎如果n大于300,那么就是NO,否則的話就是用那些數字去匹配這些位置,考慮匈牙利算法求解匹配問題。

寫完發現怎么都WA,后來發現s==0的時候需要特判,交,WA。然后發現s==1也需要特判,s==2好像也可以特判。。。GG。

賽后知道,因為s和n相差很大的話,中間的都可以抵消掉,所以有多少素數都無所謂,所以可以把s和n互換一下,再去判斷。

AC代碼:

#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define ll long long #define pb push_back #define pm make_pair using namespace std; const int MAX = 300 + 5; double H,h,D; bool bk[MAX]; bool line[MAX][MAX]; int nxt[MAX]; bool used[MAX]; int n,s; bool find(int v) {for(int i = 1; i<=n; i++) {if(!used[i] && line[v][i]) {used[i]=1; if(!nxt[i] || find(nxt[i])) {nxt[i]=v;return 1;}}}return 0 ; } int match(int m) {int res = 0;for(int i = 1; i<=m; i++) {memset(used,0,sizeof used);if(find(i)) res++;}return res; } int main() {int t;cin>>t;int iCase = 0;while(t--) {scanf("%d%d",&n,&s);if(s == 0 || n == 1 || s == 1 || s == 2) {printf("Case #%d: Yes\n",++iCase);continue;}if(s < n) swap(s,n);if(n >= 300) {printf("Case #%d: No\n",++iCase);continue;}ll low = s+1,up = s+n;int flag = 1;memset(line,0,sizeof line);memset(nxt,0,sizeof nxt);for(ll i = low; i<=up; i++) {for(int j = 1; j<=n; j++) {if(i%j==0) line[i-low+1][j] = 1;}}int ans = match(up-low+1);if(ans == n) flag = 1;else flag = 0;if(flag) printf("Case #%d: Yes\n",++iCase);else printf("Case #%d: No\n",++iCase);}return 0 ; }

?

總結

以上是生活随笔為你收集整理的【HDU - 5943】Kingdom of Obsession(数论,素数间隔结论,构造,思维,匈牙利算法,匹配问题)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。