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. python与pycharm

    什么叫自动化测试? 通俗来说,自动化测试就是通过写代码来帮我们测试软件.用来做自动化测试的语言很多,python,Java,php,Go,ruby等.而且软件系统开发语言与自动化测试语言可以不一致.例 ...

  2. Djang下载虚拟环境设置

    下载安装 教程地址 https://docs.djangoproject.com/en/1.11/howto/windows/ 有一个步骤是创建虚拟环境 创建环境 mkvirtualenv env1 ...

  3. 《剑指offer》面试题39 二叉树的深度(java)

    摘要: 今天翻到了<剑指offer>面试题39,题目二中的解法二是在函数的参数列表中通过指针的方式进行传值,而java是没有指针的,所以函数要进行改造.然而我翻了下别人的java版本(我就 ...

  4. 动态规划:树形DP-选课(树形背包)

    学校开设了N(N<300)门的选修课程,每个学生可选课程的数量M是给定的.学生选修了这M门课并考核通过就能获得相应的学分.在选修课程中,有些课程可以直接选修,有些课程需要一定的基础知识,必须在选 ...

  5. 蓝桥杯 地宫寻宝 DFS 动态规划

    #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <cstdio> #include <cstdl ...

  6. [Luogu 3128] USACO15DEC Max Flow

    [Luogu 3128] USACO15DEC Max Flow 最近跟 LCA 干上了- 树剖好啊,我再也不想写倍增了. 以及似乎成功转成了空格选手 qwq. 对于每两个点 S and T,求一下 ...

  7. Web API: Client: HttpClient Message Handlers

    原文地址: http://www.asp.net/web-api/overview/web-api-clients/httpclient-message-handlers using System; ...

  8. [整理]Node入门 » 一本全面的Node.js教程 - Demo实践所遇到的问题

    花了一个上午看完[转载]Node入门 » 一本全面的Node.js教程 根据里面的Demo自己手动实现过程中还是遇到了些问题,特整理在此. <1>.由于node.msi安装包已经自动添加了 ...

  9. 【专题】计数问题(排列组合,容斥原理,Prufer序列)

    [容斥原理] 对于统计指定排列方案数的问题,一个方案是空间中的一个元素. 定义集合x是满足排列中第x个数的限定条件的方案集合,设排列长度为S,则一共S个集合. 容斥原理的本质是考虑[集合交 或 集合交 ...

  10. HDU 1160 FatMouse's Speed (最长上升子序列)

    题目链接 题意:n个老鼠有各自的重量和速度,要求输出最长的重量依次严格递增,速度依次严格递减的序列,n最多1000,重量速度1-10000. 题解:按照重量递增排序,找出最长的速度下降子序列,记录序列 ...