hdu 5943 Kingdom of Obsession(二分匹配)
来源:互联网 发布:将iphone照片传到mac 编辑:程序博客网 时间:2024/06/11 05:46
Kingdom of Obsession
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1958 Accepted Submission(s): 581
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
Source
2016年中国大学生程序设计竞赛(杭州)
解:首先估计一下两个素数之间的距离大约是500~600,如果序列移动距离超过这个区间即一定存在两个素数
序列重合区间用被重合的数作为最终标号,因为将小的约数留给其他数一定更优
#include <iostream>#include <cstring>#include <cstdio>using namespace std;const int N = 600;typedef long long LL;int w[600][600], vis[600],match[N];int n, s;int dfs(int u){ for(int i=1;i<=n;i++) { if(!w[u][i]||vis[i]) continue; vis[i]=1; if(match[i]==-1||dfs(match[i])) { match[i]=u; return 1; } } return 0;}int main(){ int t, ncase=1; scanf("%d", &t); while(t--) { scanf("%d %d", &n, &s); if(s<n)swap(s,n); if(n>504) printf("Case #%d: No\n",ncase++); else { memset(w,0,sizeof(w)); for(int i=1;i<=n;i++) { int x=i+s; for(int j=1;j<=n;j++) { if(x%j==0) w[i][j]=1; } } int cnt=0; memset(match,-1,sizeof(match)); for(int i=1;i<=n;i++) { memset(vis,0,sizeof(vis)); if(dfs(i)) cnt++; } if(cnt!=n) printf("Case #%d: No\n",ncase++); else printf("Case #%d: Yes\n",ncase++); } } return 0;}
阅读全文
0 0
- HDU-5943 Kingdom of Obsession(数学+二分图匹配)
- HDU 5943 Kingdom of Obsession(二分图匹配+数论)
- hdu 5943 Kingdom of Obsession(二分匹配)
- Hdu 5943 Kingdom of Obsession【素数+二分匹配】
- HDU 5943 - Kingdom of Obsession(二分图匹配+三素数定理)
- HDU 5943 && 2016CCPC杭州 K: Kingdom of Obsession(二分匹配)
- HDU 5943 Kingdom of Obsession (二分图)
- HDU 5943 - Kingdom of Obsession(二分图)
- HDU 5943 Kingdom of Obsession(二分图)
- HDU 5943 Kingdom of Obsession 【二分图匹配 匈牙利算法】 (2016年中国大学生程序设计竞赛(杭州))
- HDU 5943 Kingdom of Obsession [素数间隔+二分图匹配]【数论+图论】
- hdu 5943 Kingdom of Obsession
- HDU-5943 Kingdom of Obsession
- (5943 Kingdom of Obsession)简单的二分图匹配问题
- 【2016-CCPC-K】匈牙利算法,最大基数匹配(Kingdom of Obsession,hdu 5943)
- Kingdom of Obsession HDU
- Kingdom of Obsession HDU
- HDOJ 5943 Kingdom of Obsession【2016杭州现场赛】【二分图匹配暴力】
- 共享房子在深圳等一线城市悄然兴起
- Spring-Session+Redis实现session共享
- 在Dos窗口java程序乱码解决方案
- 给Github上的readme.md加上换行(回车)效果
- mtk alarm group功能 又名alarm白名单功能
- hdu 5943 Kingdom of Obsession(二分匹配)
- C# response输出要下载的文件流到客户端
- 台大-林轩田老师-机器学习基石学习笔记4
- github如何删除一个repository(仓库)
- 几个VS的插件,挺好用
- java 自旋锁(可重入且无死锁)
- 选择结构【C语言程序设计】
- 纯C语言开发经典游戏--俄罗斯方块
- js中replace()、join()、split()的用法