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

Problem Description
There is a kindom of obsession, so people in this kingdom do things very strictly.

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

xmody=0

Is there any way to satisfy everyone's requirement?

 
Input
First line contains an integer T, which indicates the number of test cases.

Every test case contains one line with two integers n, s.

Limits
1≤T≤100.
1≤n≤109.
0≤s≤109.

 
Output
For every test case, you should output 'Case #x: y', where x indicates the case number and counts from 1 and y is the result string.

If there is any way to satisfy everyone's requirement, y equals 'Yes', otherwise y equals 'No'.

 
Sample Input
2
5 14
4 11
 
Sample Output
Case #1: No
Case #2: Yes
 
Source
这个题想到了素数出现两次就不能匹配,但是没想到素数间隔(潜意识认为20亿以内的素数肯定间隔很大).
20亿内两个素数之间最大间隔不会超过300,所以超过600直接输出No.所以解法就是小数据二分图匹配,大数据直接输出No.防止区间相交,要特判一下n,s的大小.
#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(素数间隔+二分图匹配)的更多相关文章

  1. csu 1552(米勒拉宾素数测试+二分图匹配)

    1552: Friends Time Limit: 3 Sec  Memory Limit: 256 MBSubmit: 723  Solved: 198[Submit][Status][Web Bo ...

  2. HDU 1083 网络流之二分图匹配

    http://acm.hdu.edu.cn/showproblem.php?pid=1083 二分图匹配用得很多 这道题只需要简化的二分匹配 #include<iostream> #inc ...

  3. hdu 5727 Necklace dfs+二分图匹配

    Necklace/center> 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5727 Description SJX has 2*N mag ...

  4. HDU 5727 Necklace(二分图匹配)

    [题目链接]http://acm.hdu.edu.cn/showproblem.php?pid=5727 [题目大意] 现在有n颗阴珠子和n颗阳珠子,将它们阴阳相间圆排列构成一个环,已知有些阴珠子和阳 ...

  5. HDU 2819 Swap(二分图匹配)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=2819 [题目大意] 给出一个棋盘,由白格子和黑格子组成,可以交换棋盘的行列, 使得其主对角线为黑格 ...

  6. HDU 5727 - Necklace - [全排列+二分图匹配][Hopcroft-Karp算法模板]

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5727 Problem DescriptionSJX has 2*N magic gems. ...

  7. hdu - 1150 Machine Schedule (二分图匹配最小点覆盖)

    http://acm.hdu.edu.cn/showproblem.php?pid=1150 有两种机器,A机器有n种模式,B机器有m种模式,现在有k个任务需要执行,没切换一个任务机器就需要重启一次, ...

  8. hdu 1045 Fire Net 二分图匹配 && HDU-1281-棋盘游戏

    题意:任意两个个'车'不能出现在同一行或同一列,当然如果他们中间有墙的话那就没有什么事,问最多能放多少个'车' 代码+注释: 1 //二分图最大匹配问题 2 //难点在建图方面,如果这个图里面一道墙也 ...

  9. HDU 2819 隐式二分图匹配

    http://acm.hdu.edu.cn/showproblem.php?pid=2819 这道题乍一看是矩阵变换题,估计用矩阵之类的也可以做 但是分析一下就可以知道 要凑成对角线都是1,题目允许行 ...

随机推荐

  1. C++下实现同接口下多个类作为参数的调用和传参

    /* 实现同接口下不同类的对象的转移 定义类的接口 定义多个继承该接口的类 定义管理类,把接口当作类型, 传入该接口下各种类的对象,进行操作 */ #include<iostream> # ...

  2. python pip安装--不是内部或外部命令--解决方案

    首先在 命令行中输入 python -m ensurepip 创建出pip3.exe  , 并找到pip3.exe所在的Scripts路径 使命令行在Scripts路径下 输入pip3 install ...

  3. Centos6.6下安装nginx1.6.3

    安装环境: [root@nginx ~]# cat /etc/redhat-release CentOS release 6.6 (Final) [root@nginx ~]# uname -r 2. ...

  4. Kubernetes 1.5 配置dns

    在kubernetes1.2的时候,采用了skydns + kube2dns +etcd的方式来部署dns.而从1.3开始,则部署方式有了一点儿变化,将skydns和kube2dns封装到了一个容器镜 ...

  5. 怎样彻底卸载(删除)SQL server2000

    如何完全卸载SQL server 2000 一.卸载安装程序:找到电脑右下角的Windows开始按钮,找到控制面板——卸载程序. 找到server 2000的安装程序,并点击后面的卸载按钮.  是,确 ...

  6. 数据库sharding系列好文收藏

    部分摘自于:http://my.oschina.net/u/188625/blog/104743 1. 又拍网架构中的数据库分库设计 . http://blog.csdn.net/nanjingjia ...

  7. src.rpm包的解压

    有时候,我们在找源码包时候,发现有src.rpm的包:而不是tar.gz/tgz/zip结尾的. 那么如何去看这个src.rpm里面的详细信息呢? 看完下面这个例子,基本上明白了. 1,首先,生成sp ...

  8. python学习笔记2-tuple

    tuple: #元组也是List,但是值不能变 a=(') print(a[1]) mysql=(',''root','123456') print(mysql.count('root')) #例子 ...

  9. 视差插件parallarx

    github上的demo,自己拿来改了改. <!DOCTYPE html> <html> <head> <meta charset="UTF-8&q ...

  10. 【简记】前端对接WebSocket与心跳重连

    前言 最近又在忙着开发别的模块,其中包含了即时通讯这一块,上一次做即时通讯时还是去年年底,一时间代码都在自己的笔记本里,还没带--这里就记录一下前端对接WebSocket的实现,包含心跳重连,简记之. ...