HDU 5943 Kingdom of Obsession (二分图)
来源:互联网 发布:照片冲印排版软件 编辑:程序博客网 时间:2024/06/07 17:01
Kingdom of Obsession
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 448 Accepted Submission(s): 127
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
Source
2016年中国大学生程序设计竞赛(杭州)
利用素数之间距离比较密的原理,再套个kuangbin的hungry模板就过了。
#include "cstring"#include "cstdio"#include "string.h"#include "iostream"using namespace std;const int MAXN=510;int uN,vN;//u,v数目int g[MAXN][MAXN];int linker[MAXN];bool used[MAXN];bool dfs(int u)//从左边开始找增广路径{ int v; for(v=1;v<=vN;v++)//这个顶点编号从0开始,若要从1开始需要修改 if(g[u][v]&&!used[v]) { used[v]=true; if(linker[v]==-1||dfs(linker[v])) {//找增广路,反向 linker[v]=u; return true; } } return false;//这个不要忘了,经常忘记这句}int hungary(){ int res=0; int u; memset(linker,-1,sizeof(linker)); for(u=1;u<=uN;u++) { memset(used,0,sizeof(used)); if(dfs(u)) res++; } return res;}int main(){ int t; scanf("%d",&t); int cas=1; while(t--) { int n,s; scanf("%d%d",&n,&s); if(s<n)swap(n,s);//抹掉相交区间 画个图很显然 uN=vN=n; if(n>500) { printf("Case #%d: No\n",cas++); continue; } memset(g,0,sizeof(g)); for(int i=s+1;i<=s+n;i++) { for(int j=1;j<=n;j++) { if(i%j==0) { g[i-s][j]=1; } } } if(hungary()==n) printf("Case #%d: Yes\n",cas++); else printf("Case #%d: No\n",cas++); }}
- 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 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 Kingdom of Obsession [素数间隔+二分图匹配]【数论+图论】
- Kingdom of Obsession HDU
- Kingdom of Obsession HDU
- HDU 5943 Kingdom of Obsession 【二分图匹配 匈牙利算法】 (2016年中国大学生程序设计竞赛(杭州))
- HDU 5943 && 2016CCPC杭州 K: Kingdom of Obsession(二分匹配)
- HDOJ 5943 Kingdom of Obsession【2016杭州现场赛】【二分图匹配暴力】
- (5943 Kingdom of Obsession)简单的二分图匹配问题
- Kingdom of Obsession
- CentOS 7 上编译安装MySQL 5.6.23
- Mybatis:org.postgresql.util.PSQLException: ERROR: relation "summarytdglinfo" does not ex
- 将 Session 数据存入数据库
- android 的apk反编译
- Android仿mac音量拖动view实现
- HDU 5943 Kingdom of Obsession (二分图)
- servlet基础知识
- 8. String to Integer (atoi)
- Retrofit源码解析---初始化
- 关于Studio导入项目一直卡在Building xx Gradle project info的解决办法
- hadoop中map和reduce的数量设置问题
- CSS学习 二:选择器
- EL表达式讲解
- j加盟的优先之选 好嘢鸡排