Kingdom of Obsession---hdu5943(二分匹配)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5943
题意:给你两个数n, s 然后让你判断是否存在(s+1, s+2, s+3, ... , s+n )的任意排列方式使得每个数都满足当前数num,与num所在位置 pos 形成num%pos=0;
例如 n = 4 , s = 11
num = {13, 14, 15, 12}
pos = {1, 2, 3, 4}
每个num与之对应的pos都是num%pos = 0;的关系
分为两种情况:当s+1>n 时,我们只需看第二个数组中是否含有>=2个素数即可, 因为1只有1个;
当s+1<=n时,两个区间有重叠,我们可以忽略这些重叠部分,看两端的即可,其实就是交换一下n,s的值;
其实就是两个数组建图,然后求最大匹配是否为1,当然n比较大,但是连续600个数中间一定包含>=2个素数,所以当n<600时可以用二分匹配来做;
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<vector>
using namespace std;
typedef long long LL;
const int oo = 0xfffffff;
const int N = ; int used[N], vis[N], n, s;
vector<int> G[N]; bool Find(int u)
{
int len=G[u].size();
for(int i=; i<len; i++)
{
int v = G[u][i];
if(!vis[v])
{
vis[v] = ;
if(!used[v] || Find(used[v]))
{
used[v] = u;
return true;
}
}
}
return false;
} int main()
{
int T, t = ;
scanf("%d", &T);
while(T --)
{
scanf("%d %d", &n, &s); if(s+ <= n)///忽略中间重合的部分;
swap(s, n); if(n > )///因为连续600个数中一定有>=2个素数, 1只有一个,所以结果都是No;
{
printf("Case #%d: No\n", t++);
continue;
} for(int i=; i<=n; i++)
G[i].clear(); for(int i=; i<=n; i++)
{
for(int j=; j<=n; j++)
{
if((s+i)%j == )///说明s+i是j的倍数;
G[i].push_back(j);
}
}
memset(used, , sizeof(used));
int ans = ;
for(int i=; i<=n; i++)
{
memset(vis, , sizeof(vis));
ans += Find(i);
}
if(ans != n)///必须要找到所有与之对应的才可以;
printf("Case #%d: No\n", t++);
else
printf("Case #%d: Yes\n", t++);
}
return ;
}
Kingdom of Obsession---hdu5943(二分匹配)的更多相关文章
- HDU 5943 Kingdom of Obsession 【二分图匹配 匈牙利算法】 (2016年中国大学生程序设计竞赛(杭州))
Kingdom of Obsession Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- hdu5943 Kingdom of Obsession 二分图+打表找规律
题目传送门 Kingdom of Obsession Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...
- hdu 5943 Kingdom of Obsession 二分图匹配+素数定理
Kingdom of Obsession Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- HDU 3861 The King’s Problem(tarjan缩点+最小路径覆盖:sig-最大二分匹配数,经典题)
The King’s Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- zoj 2362 Beloved Sons【二分匹配】
题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2361 来源:http://acm.hust.edu.cn/vjudg ...
- POJ 1274 The Perfect Stall、HDU 2063 过山车(最大流做二分匹配)
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24081 Accepted: 106 ...
- [kuangbin带你飞]专题十 匹配问题 二分匹配部分
刚回到家 开了二分匹配专题 手握xyl模板 奋力写写写 终于写完了一群模板题 A hdu1045 对这个图进行 行列的重写 给每个位置赋予新的行列 使不能相互打到的位置 拥有不同的行与列 然后左行右列 ...
- BZOJ 1189 二分匹配 || 最大流
1189: [HNOI2007]紧急疏散evacuate Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1155 Solved: 420[Submi ...
- poj 2060 Taxi Cab Scheme (二分匹配)
Taxi Cab Scheme Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5710 Accepted: 2393 D ...
随机推荐
- C#/.NET Little Wonders: Use Cast() and OfType() to Change Sequence Type(zz)
Once again, in this series of posts I look at the parts of the .NET Framework that may seem trivial, ...
- Eclipse: The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path
Link: http://stackoverflow.com/questions/22756153/the-superclass-javax-servlet-http-httpservlet-was- ...
- ccc this 指针
cc.Class({ extends: cc.Component, properties: { musicPlayer: { default: null, type: cc.AudioSource } ...
- html5调用手机相机并压缩、上传
近日刚做的一个功能,要在app里使用内嵌页面进行图像的上传.从功能上看,原生的实现应该是最好的.毕竟页面上所有的东西都隔着一个浏览器,所有的实现都要依赖浏览器提供的接口,不同的浏览器对接口的实现又有差 ...
- Scheduled Projects
Plans as at 10/03/15 ASB --------> Li ...
- Leetcode Unique Binary Search Trees
Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For examp ...
- Codeforces Round #248 (Div. 2) A. Kitahara Haruki's Gift
解决思路是统计100的个数为cnt1,200的个数为cnt2 则 cnt1 cnt2 奇数 奇数 奇数 偶数 偶数 奇数 偶数 偶数 当cnt1为奇数时一定 ...
- Flex弹性布局在移动设备上的应用
引文 首先,我们有表格布局.当不考虑语义并且利用一些适当的嵌套和其他技巧,我们可以用table建立具有一定功能的布局. 然后是现在大多数人都在使用的浮动布局.我们可以使用任何我们想用的元素,但浮动并不 ...
- 自己收集原生js-2014-2-15
function testforbtn(event){ alert(window.EventUtil.getEventTarget(window.EventUtil.getEvent( event)) ...
- 【bzoj1078】[SCOI2008]斜堆
2016-05-31 16:34:09 题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1078 挖掘斜堆的性质233 http://www.cp ...