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,题目允许行 ...
随机推荐
- Rancher Server HA的高可用部署实验-学习笔记
转载于https://blog.csdn.net/csdn_duomaomao/article/details/78771731 Rancher Server HA的高可用部署实验-学习笔记 一.机器 ...
- nginx访问日志出现大量的500状态信息,用postman返回 Internal Server Error,Too Many Attempts.错误的解决办法
用postman的post方法访问某个URL时,出现以下错误: { "status": "1", "message": " Int ...
- python中的关键字符
from keyword import kwlistprint(kwlist)for i in kwlist: print(i) 可以显示所有的关键字符,开发者不要重新赋予其他值. a = 10000 ...
- Ubuntu 14.04安装和3556sdk环境配置
1.配置为固定ip: vi /etc/network/interfaces 最后添加 iface eth0 inet staticaddress 192.168.1.100netmask 255.25 ...
- bzoj千题计划173:bzoj1257: [CQOI2007]余数之和sum
http://www.lydsy.com/JudgeOnline/problem.php?id=1257 k%i=k-int(k/i)*i 除法分块,对于相同的k/i用等差序列求和来做 #includ ...
- Docker容器加载宿主机的hosts解析
前言 公司一直在用传统的tomcat下丢war包的架构体系,随着项目的增多.服务器数量的增多.需要为此花费很多时间在不同服务器的系统环境问题上.为了技术的与时俱进和工作的运维效率等方面,笔者引入doc ...
- 经典幻灯片插件Swiper
照着写的demo,搞清楚什么叫分页器Pagination,什么叫nav,搞清楚DOM结构,container,wrapper之类的,就能写了.效果掉渣天! <!DOCTYPE html> ...
- 【CodeForces】914 F. Substrings in a String bitset
[题目]F. Substrings in a String [题意]给定小写字母字符串s,支持两种操作:1.修改某个位置的字符,2.给定字符串y,查询区间[l,r]内出现y多少次.|s|,Σ|y|&l ...
- Personal idea
我的设想是在android上开发一款应用程序,整体上是一个指南针的样式,或许你可以称之为一个圆盘,在不同的场景下可以作为不同的功能,指南针,游戏转盘,数字转盘等等.界面可以在不同的情境下更换样式.
- 20155207 2016-2017-2 《Java程序设计》第七周学习总结
20155207 2016-2017-2 <Java程序设计>第七周学习总结 教材学习内容总结 第13章 时间与日期 13.1 认识时间与日期 13.1.1 时间的度量 格林威治时间(GM ...