HDU 5943 二分图
来源:互联网 发布:有什么二次元软件 编辑:程序博客网 时间:2024/06/09 22:50
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 aren 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?
They name themselves in integer, and there are
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 integersn , s .
Limits
1≤T≤100 .
1≤n≤109 .
0≤s≤109 .
Every test case contains one line with two integers
Limits
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'.
If there is any way to satisfy everyone's requirement, y equals 'Yes', otherwise y equals 'No'.
Sample Input
25 144 11
Sample Output
Case #1: NoCase #2: Yes
题意:给出n和s,能不能找出一种方法使得s+1,s+2...s+n,能匹配上1,2...n,也就是能1-n能整除s+1....s+n
题解:在10的9次方中,不可能有连续的50个数都是素数,对于一个素数,只能匹配1和它自身,所以要先去重。
当n>s时 只要将s-n自身匹配即可 也就是交换s和n的值
然后判断剩余的数 ,如果区间有两个以上的素数, 因为只有一个1,所以也就不行,否则用二分图匹配即可。
ps:当然区间也会很小,开55即可。
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;typedef long long ll;ll s,n,a[55][55],match[55],vis[55];ll isprime(ll t){ for(ll i=2;i*i<=t;i++){ if(t%i==0)return 0; } return 1;}bool dfs(ll u){ for(ll v=1;v<=n;v++) if(a[u][v]&&!vis[v]){ vis[v]=true; if(match[v]==-1||dfs(match[v])){ match[v]=u; return true; } } return false;}int main(){ ll cas=1,t; scanf("%lld",&t); while(t--){ scanf("%lld%lld",&n,&s); if(n>s)swap(n,s); ll i,num=0,j; for(i=s+1;i<=s+n;i++){ num+=isprime(i); if(num>1)break; } if(num==2)printf("Case #%lld: No\n",cas++); else{ memset(a,0,sizeof(a)); for(i=s+1;i<=s+n;i++){ for(j=1;j<=n;j++){ if(i%j==0)a[i-s][j]=1; } } ll sum=0; memset(match,-1,sizeof(match)); for(i=1;i<=n;i++){ memset(vis,0,sizeof(vis)); if(dfs(i))sum++; } if(sum==n)printf("Case #%lld: Yes\n",cas++); else printf("Case #%lld: No\n",cas++); } } return 0;}
0 0
- HDU 5943 二分图
- hdu 5943 二分图匹配
- hdu 5943 二分图匹配
- hdu 5943 二分图匹配
- hdu 5943 二分图+素数
- hdu 5943 素数分布+二分图匹配
- HDU 5943 Kingdom of Obsession (二分图)
- 二分图匹配——HDU 5943
- HDU-2444 二分图
- HDU 1083 二分图
- HDU 1150 二分图
- HDU 1151 二分图
- HDU 1281 二分图
- hdu-2063 二分图
- HDU 2444 二分图
- HDU 3829 二分图
- 【HDU 1179 二分图 】
- HDU-1045-二分图
- 学习心得——Action命名问题
- Windows+Ubuntu双系统如何设置Windows为第一启动项
- 如何用scikit-learn求TF-IDF
- linux内核版本命名
- LeetCode No.189 Rotate Array
- HDU 5943 二分图
- ECMAScript6标准Module
- mysql-5.7.16-winx64 安装说明
- 还是这棵树
- 【Abode Air程序开发】打包并导出
- 三种东西永远不要放到数据库里
- 第一个汇编程序
- uses-permission错误情况之一
- 3D技术与应用