hdu 5943(素数间隔+二分图匹配)
Kingdom of Obsession
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 200 Accepted Submission(s): 64
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
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'.
5 14
4 11
Case #2: Yes
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <math.h>
using namespace std;
typedef long long LL;
const int N = ;
int s,n;
int graph[N][N];
int linker[N];
bool vis[N];
bool dfs(int u){
for(int i=;i<=n;i++){
if(graph[u][i]==&&!vis[i]){
vis[i] = true;
if(linker[i]==-||dfs(linker[i])){
linker[i] = u;
return true;
}
}
}
return false;
}
int main()
{
int t = ,tcase;
scanf("%d",&tcase);
while(tcase--){
scanf("%d%d",&s,&n);
if(s<n) swap(s,n);
if(n>) {
printf("Case #%d: No\n",t++);
continue;
}
memset(graph,,sizeof(graph));
int res = ;
for(int i=;i<=n;i++){
int t = i+s;
for(int j=;j<=n;j++){
if(t%j==) {
graph[i][j] = ;
}
}
}
memset(linker,-,sizeof(linker));
for(int i=;i<=n;i++){
memset(vis,,sizeof(vis));
if(dfs(i)) res++;
}
if(res==n){
printf("Case #%d: Yes\n",t++);
}else printf("Case #%d: No\n",t++);
}
return ;
}
hdu 5943(素数间隔+二分图匹配)的更多相关文章
- csu 1552(米勒拉宾素数测试+二分图匹配)
1552: Friends Time Limit: 3 Sec Memory Limit: 256 MBSubmit: 723 Solved: 198[Submit][Status][Web Bo ...
- HDU 1083 网络流之二分图匹配
http://acm.hdu.edu.cn/showproblem.php?pid=1083 二分图匹配用得很多 这道题只需要简化的二分匹配 #include<iostream> #inc ...
- hdu 5727 Necklace dfs+二分图匹配
Necklace/center> 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5727 Description SJX has 2*N mag ...
- HDU 5727 Necklace(二分图匹配)
[题目链接]http://acm.hdu.edu.cn/showproblem.php?pid=5727 [题目大意] 现在有n颗阴珠子和n颗阳珠子,将它们阴阳相间圆排列构成一个环,已知有些阴珠子和阳 ...
- HDU 2819 Swap(二分图匹配)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=2819 [题目大意] 给出一个棋盘,由白格子和黑格子组成,可以交换棋盘的行列, 使得其主对角线为黑格 ...
- HDU 5727 - Necklace - [全排列+二分图匹配][Hopcroft-Karp算法模板]
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5727 Problem DescriptionSJX has 2*N magic gems. ...
- hdu - 1150 Machine Schedule (二分图匹配最小点覆盖)
http://acm.hdu.edu.cn/showproblem.php?pid=1150 有两种机器,A机器有n种模式,B机器有m种模式,现在有k个任务需要执行,没切换一个任务机器就需要重启一次, ...
- hdu 1045 Fire Net 二分图匹配 && HDU-1281-棋盘游戏
题意:任意两个个'车'不能出现在同一行或同一列,当然如果他们中间有墙的话那就没有什么事,问最多能放多少个'车' 代码+注释: 1 //二分图最大匹配问题 2 //难点在建图方面,如果这个图里面一道墙也 ...
- HDU 2819 隐式二分图匹配
http://acm.hdu.edu.cn/showproblem.php?pid=2819 这道题乍一看是矩阵变换题,估计用矩阵之类的也可以做 但是分析一下就可以知道 要凑成对角线都是1,题目允许行 ...
随机推荐
- 团体程序设计天梯赛-练习集 L1-031. 到底是不是太胖了
比较两个实型的数: 若两者相等,也许用a>/b会出错... 我又想到了codeforces有很多这样的坑... #include <stdio.h> #include <std ...
- git<Commit和Push的区别>
git作为支持分布式版本管理的工具,它管理的库(repository)分为本地库.远程库. git commit操作的是本地库,git push操作的是远程库. git commit是将本地修改过的文 ...
- PyCharm引入自定义类报错
This inspection detects names that should resolve but don't. Due to dynamic dispatch and duck typing ...
- CoreDNS配置etcd作为后端
配置说明 官方有使用etcd插件的详细说明,地址如下:https://coredns.io/plugins/etcd/ 需要特别说明的是,目前coredns只支持etcd v2版本的api 这里直接摘 ...
- NATS_10:NATS服务配置文件详解
尽管NATS可以无配置的运行,但也可以使用配置文件配置NATS服务的启动,在实际应用当中,一般都是通过使用配置文件来启动服务的. 1. 配置项包括 客户端监听器端口 Client listening ...
- 关于connect by 误区讲解,纯属个人心得和经验,有图有文字
本博客是自己在学习和工作途中的积累与总结,仅供自己参考,也欢迎大家转载,转载时请注明出处. http://www.cnblogs.com/king-xg/p/6927541.html 如果觉得对您有帮 ...
- git简单使用总结
一.git配置 git config 1.git config --global user.name "ken" 配置用户名2.git config --global user.e ...
- Shell记录-Shell命令(文件查找)
常见解压/压缩命令 tar文件格式解包:tar xvf FileName.tar打包:tar cvf FileName.tar DirName(注:tar是打包,不是压缩!) .gz文件格式解压1:g ...
- JAVA编程之——反射Reflect
说到反射,首先要说一下Java中的类和对象. 在Java中万事万物皆对象(有两个 例外,一个是普通数据类型,另一个是静态的东西,静态的东西不是对象的,是属于类的). 在Java中,类也是对象,类是ja ...
- [转载]PayPal为什么从Java迁移到Node.js,性能提高一倍,文件代码减少44%
http://ourjs.com/detail/52a914f0127c763203000008 大家都知道PayPal是另一家迁移到Node.js平台的大型公司,Jeff Harrell的这篇博文 ...