hdu 5943 Kingdom of Obsession 二分图匹配+素数定理
Kingdom of Obsession
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
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 y
th
position which satisfy
Is there any way to satisfy everyone's requirement?
Every test case contains one line with two integers n , s
.
Limits
1≤T≤100 .
1≤n≤109
.
0≤s≤109
.
If there is any way to satisfy everyone's requirement, y equals 'Yes', otherwise y equals 'No'.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-14
const int N=2e5+10,M=1e6+10,inf=1e9+10,mod=1e9+7;
const ll INF=1e18+10;
int prime(int n)
{
if(n<=1)return 0;
if(n==2)return 1;
if(n%2==0)return 0;
int k, upperBound=n/2;
for(k=3; k<=upperBound; k+=2)
{
upperBound=n/k;
if(n%k==0)return 0;
}
return 1;
}
const int MAXN=1505;
map<int,int>linker;
map<int,int>used;
vector<int>mp[MAXN];
int uN;
bool dfs(int u)
{
for(int i=0;i<mp[u].size();i++)
{
if(!used[mp[u][i]])
{
used[mp[u][i]]=1;
if(linker[mp[u][i]]==0||dfs(linker[mp[u][i]]))
{
linker[mp[u][i]]=u;
return true;
}
}
}
return false;
}
int hungary()
{
int u;
int res=0;
linker.clear();
for(u=1;u<=uN;u++)
{
used.clear();
if(dfs(u)) res++;
}
return res;
}
int main()
{
int T,cas=1;
scanf("%d",&T);
while(T--)
{
for(int i=0;i<MAXN;i++)
mp[i].clear();
int n,s;
scanf("%d%d",&n,&s);
if(n>s)swap(n,s);
int p=0;
for(int i=s+1; i<=s+n; i++)
{
if(prime(i))
{
p++;
if(p>=2)break;
}
}
printf("Case #%d: ",cas++);
if(p>=2)
{
printf("No\n");
continue;
}
for(int i=s+1; i<=s+n; i++)
{
for(int j=1; j<=n; j++)
{
if(i%j==0)
{
mp[j].push_back(i);
}
}
}
uN=n;
int hh=hungary();
if(hh==n)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
hdu 5943 Kingdom of Obsession 二分图匹配+素数定理的更多相关文章
- HDU 5943 Kingdom of Obsession 【二分图匹配 匈牙利算法】 (2016年中国大学生程序设计竞赛(杭州))
Kingdom of Obsession Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- HDU 5943 Kingdom of Obsession
题意:n个人编号为[s+1, s+n],有n个座位编号为[1,n],编号为 i 的人只能坐到编号为它的约数的座位,问每个人是否都有位置坐. 题解:由于质数只能坐到1或者它本身的位置上,所以如果[n+1 ...
- HDU 5938 Kingdom of Obsession(数论 + 二分图匹配)
题意: 给定S,N,把S+1,S+2,...S+N这N个数填到1,2,...,N里,要求X只能填到X的因子的位置.(即X%Y=0,那么X才能放在Y位置) 问是否能够放满. 分析:经过小队的分析得出的结 ...
- hdu5943 Kingdom of Obsession 二分图+打表找规律
题目传送门 Kingdom of Obsession Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...
- hdu 3829 Cat VS Dog 二分图匹配 最大点独立集
Cat VS Dog Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others) Prob ...
- HDU 4685 Prince and Princess 二分图匹配+tarjan
Prince and Princess 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=4685 Description There are n pri ...
- HDU 2236 无题II(二分图匹配+二分)
HDU 2236 无题II 题目链接 思路:行列仅仅能一个,想到二分图,然后二分区间长度,枚举下限.就能求出哪些边是能用的,然后建图跑二分图,假设最大匹配等于n就是符合的 代码: #include & ...
- TTTTTTTTTTTTTTTT hdu 5727 Necklace 阴阳珠 二分图匹配+暴力全排列
Necklace Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Su ...
- hdu 4619 Warm up 2 二分图匹配
题目链接 给两种长方形, 水平的和垂直的, 大小都为1*2, n个水平的, m个垂直的, 给出它们的坐标. 水平的和垂直的可以相互覆盖, 但是同种类型的没有覆盖. 去掉一些长方形, 使得剩下的全部都没 ...
随机推荐
- linux设备驱动归纳总结(十二):简单的数码相框【转】
本文转载自:http://blog.chinaunix.net/uid-25014876-id-116926.html linux设备驱动归纳总结(十二):简单的数码相框 xxxxxxxxxxxxxx ...
- linux设备驱动归纳总结(三):3.设备驱动面向对象思想和lseek的实现【转】
本文转自自:http://blog.chinaunix.net/uid-25014876-id-59418.html linux设备驱动归纳总结(三):3.设备驱动面向对象思想和lseek的实现 一. ...
- 161130、Dubbo+SpringMVC工程创建详解
Dubbo出现的目的是为了应对现在高并发,高数据量请求的问题.目前的垂直应用架构已经无法满足现在大数据的冲击,SOA就应运而生,而Dubbo在国内使用的还是比较多,稳定性也比较不错. 架构 节点角色说 ...
- 160921、React入门教程第一课--从零开始构建项目
工欲善其事必先利其器,现在的node环境下,有太多好用的工具能够帮助我们更好的开发和维护管理项目. 我本人不建议什么功能都自己写,我比较喜欢代码复用.只要能找到npm包来实现的功能,坚决不自己敲代码. ...
- webApi FileReader
https://developer.mozilla.org/en-US/docs/Web/API/FileReader https://github.com/node-file-api/FileRea ...
- html状态码与缓存学习
当浏览器访问一个页面时,浏览者的浏览器会向网页所在的服务器发送请求.当浏览器接收并显示网页前,此网页所在的服务器会返回一个包含HTTP状态码的信息头(server header)用以响应浏览器的请求. ...
- css基本样式总结
1:背景(background) <!DOCTYPE html> <html> <head lang="en"> <meta charse ...
- 2016年6月30日 星期四 --出埃及记 Exodus 14:27
2016年6月30日 星期四 --出埃及记 Exodus 14:27 Moses stretched out his hand over the sea, and at daybreak the se ...
- IOSFramework打包。
http://www.cocoachina.com/ios/20150127/11022.html
- SqlSever基础 len函数 计算前后都有空格的字符串的长度时
镇场诗:---大梦谁觉,水月中建博客.百千磨难,才知世事无常.---今持佛语,技术无量愿学.愿尽所学,铸一良心博客.------------------------------------------ ...