Kingdom of Obsession

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

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

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-14
const int N=2e5+10,M=1e6+10,inf=1e9+10,mod=1e9+7;
const ll INF=1e18+10;
int prime(int n)
{
if(n<=1)return 0;
if(n==2)return 1;
if(n%2==0)return 0;
int k, upperBound=n/2;
for(k=3; k<=upperBound; k+=2)
{
upperBound=n/k;
if(n%k==0)return 0;
}
return 1;
}
const int MAXN=1505;
map<int,int>linker;
map<int,int>used;
vector<int>mp[MAXN];
int uN;
bool dfs(int u)
{
for(int i=0;i<mp[u].size();i++)
{
if(!used[mp[u][i]])
{
used[mp[u][i]]=1;
if(linker[mp[u][i]]==0||dfs(linker[mp[u][i]]))
{
linker[mp[u][i]]=u;
return true;
}
}
}
return false;
}
int hungary()
{
int u;
int res=0;
linker.clear();
for(u=1;u<=uN;u++)
{
used.clear();
if(dfs(u)) res++;
}
return res;
}
int main()
{
int T,cas=1;
scanf("%d",&T);
while(T--)
{
for(int i=0;i<MAXN;i++)
mp[i].clear();
int n,s;
scanf("%d%d",&n,&s);
if(n>s)swap(n,s);
int p=0;
for(int i=s+1; i<=s+n; i++)
{
if(prime(i))
{
p++;
if(p>=2)break;
}
}
printf("Case #%d: ",cas++);
if(p>=2)
{
printf("No\n");
continue;
}
for(int i=s+1; i<=s+n; i++)
{
for(int j=1; j<=n; j++)
{
if(i%j==0)
{
mp[j].push_back(i);
}
}
}
uN=n;
int hh=hungary();
if(hh==n)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}

hdu 5943 Kingdom of Obsession 二分图匹配+素数定理的更多相关文章

  1. HDU 5943 Kingdom of Obsession 【二分图匹配 匈牙利算法】 (2016年中国大学生程序设计竞赛(杭州))

    Kingdom of Obsession Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  2. HDU 5943 Kingdom of Obsession

    题意:n个人编号为[s+1, s+n],有n个座位编号为[1,n],编号为 i 的人只能坐到编号为它的约数的座位,问每个人是否都有位置坐. 题解:由于质数只能坐到1或者它本身的位置上,所以如果[n+1 ...

  3. HDU 5938 Kingdom of Obsession(数论 + 二分图匹配)

    题意: 给定S,N,把S+1,S+2,...S+N这N个数填到1,2,...,N里,要求X只能填到X的因子的位置.(即X%Y=0,那么X才能放在Y位置) 问是否能够放满. 分析:经过小队的分析得出的结 ...

  4. hdu5943 Kingdom of Obsession 二分图+打表找规律

    题目传送门 Kingdom of Obsession Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Ja ...

  5. hdu 3829 Cat VS Dog 二分图匹配 最大点独立集

    Cat VS Dog Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others) Prob ...

  6. HDU 4685 Prince and Princess 二分图匹配+tarjan

    Prince and Princess 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=4685 Description There are n pri ...

  7. HDU 2236 无题II(二分图匹配+二分)

    HDU 2236 无题II 题目链接 思路:行列仅仅能一个,想到二分图,然后二分区间长度,枚举下限.就能求出哪些边是能用的,然后建图跑二分图,假设最大匹配等于n就是符合的 代码: #include & ...

  8. TTTTTTTTTTTTTTTT hdu 5727 Necklace 阴阳珠 二分图匹配+暴力全排列

    Necklace Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Su ...

  9. hdu 4619 Warm up 2 二分图匹配

    题目链接 给两种长方形, 水平的和垂直的, 大小都为1*2, n个水平的, m个垂直的, 给出它们的坐标. 水平的和垂直的可以相互覆盖, 但是同种类型的没有覆盖. 去掉一些长方形, 使得剩下的全部都没 ...

随机推荐

  1. java小程序整理及排序算法

    1. 利用循环打印如下图形 ***** **** *** ** * public class Main { public static void main(String[] args) { // TO ...

  2. JSONArray.fromObject()注入处理日期Date格式

    package jsonDateProcess; import java.sql.Date; import java.text.SimpleDateFormat; import java.util.L ...

  3. centos7.1-64bit安装qtcreator

    首先,启用 EPEL Repository: yum -y install epel-release 启用 EPEL Repository 後, 可以用 yum 直接安裝qtcreator: yum ...

  4. 搭建HTTP Live Streaming直播系统

    最近,需要将苹果的HTTP Live Streaming系统搭建起来.完全没有头绪,故第一步就是学习. 一.学习资料 官网资料 1. http://developer.apple.com/resour ...

  5. Codeforces 746D:Green and Black Tea(乱搞)

    http://codeforces.com/contest/746/problem/D 题意:有n杯茶,a杯绿茶,b杯红茶,问怎么摆放才可以让不超过k杯茶连续摆放,如果不能就输出NO. 思路:首先,设 ...

  6. HDU 2067:小兔的棋盘

    小兔的棋盘 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Subm ...

  7. Drainage Ditches 分类: POJ 图论 2015-07-29 15:01 7人阅读 评论(0) 收藏

    Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 62016 Accepted: 23808 De ...

  8. Zend Studio集成Xdebug断点调试详解

    转自:http://www.softown.cn/post/115.html Xdebug是PHP开发中两个常用的断点调试工具之一(另一个为Zend Debugger). 现在,我们在Zend Stu ...

  9. WCF 下载“http://localhost:XXX”时出错。无法连接到远程服务器。由于目标计算机积极拒绝,无法连接。

    根据理论,WCF既然查找不到该地址 应该是没打开Service,或者说该端口被防火墙保护了,关了防火墙没解决,最后一试成功了. 我的服务端和客户端都位于一个解决方案中,当运行服务端时,则 [添加服务引 ...

  10. CentOS 配置solr中文分词器

    第一步:使用IK-Analyzer.把分析器的文件夹上传到服务器. 第二步:需要把分析器的jar包添加到solr工程中. [root@bogon IK Analyzer 2012FF_hf1]# cp ...