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,题目允许行 ...
随机推荐
- iperf测试网络性能
分类: LINUX 2013-06-17 18:52:21 Iperf是一个网络性能测试工具.可以测试TCP和UDP带宽质量,可以测量最大TCP带宽,具有多种参数和UDP特性,可以报告带宽 ...
- Python【logging】模块
# 1.负责往控制台里面输出日志信息的 # 2.往日志文件里面写日志的,按天生成日志,清理日志 import logging from logging import handlers logger = ...
- 使用前端组件化思想修改todolist
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Shell记录-Shell命令(磁盘)
inux中df命令的功能是用来检查linux服务器的文件系统的磁盘空间占用情况.可以利用该命令来获取硬盘被占用了多少空间,目前还剩下多少空间等信息. 1.命令格式 df [选项] [文件] Shell ...
- 如何在Windows系统下隐藏文件
隐藏后只有键入文件夹名称才可访问,如果忘记路径就找不到了 attrib +s +a +h +r e:\bak\tools 取消的方法: attrib -a -s -h -r e:\bak\tools
- Elasticsearch之Java实战
资料 http://www.cnblogs.com/kamong/p/6099914.html 搭建Elasticsearch服务器
- Elasticsearch技术解析与实战(四)shard&replica机制
序言 shard&replica机制 1.index包含多个shard 2.每个shard都是一个最小工作单元,承载部分数据,lucene实例,完整的建立索引和处理请求的能力 3.增减节点时, ...
- 你知道吗?什么是 Responsive JavaScript ?
Responsive Javascript 是什么? 简单来说就是可以根据浏览器的状态做出响应.响应包括对视窗大小的反应,根据你设备是否支持触摸事件或地理定位功能来决定是否显示特定内容,不一而足. 什 ...
- WPF控件收集
1.Extended WPF Toolkit 2.Fluent Ribbon Control Suite 3.WPF Ribbon Control 4.Telerik RadControls for ...
- 详细讲解安全升级MySQL的方法
MySQL升级是非常必要的. 我们在Percona Support上列出了关于MySQL升级最佳实践的各种问题.这篇文章推荐了一些不同情况下升级MySQL的方法. 为什么MySQL升级是必须的? 原因 ...