题目传送门

Kingdom of Obsession

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3051    Accepted Submission(s): 919

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
 
Recommend
liuyiding   |   We have carefully selected several similar problems for you:  6447 6446 6445 6444 6443 
题意:给你n和s,问你s后面n个数能够完全跟1-n匹配,(s+i)与i匹配,
        如果(s+i)%i==0(1<=n) 
题解:首先n个数中要是出现两个质数那肯定匹配不成功,然后我们通过打表发现
            1-1e8每两个相隔质数的最大距离不超过300,但是这里有一个情况,就是
            当n>s时,是可以容许有两个质数的,比如:n=4,s=3,这里3和5是可以的,其实解决
            的方法就是交换n和s的值,因为求n=4,s=3和n=3,s=4是一样的,就是把一样的数自己
       给匹配掉而已,最后当n<300的时候就是一个二分如完美匹配的问题了
代码:
 
 
#include<iostream>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<math.h>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> PII;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
//head
#define MAX 1005
int t;
ll n,m;
ll a[MAX],b[MAX];
ll nxt[MAX],used[MAX];
bool Find(int x)
{
for(int i=;i<=m;i++)
{
if(!used[i]&&a[x]%b[i]==)
{
used[i]=;
if(nxt[i]==||Find(nxt[i]))
{
nxt[i]=x;
return true;
}
}
}
return false;
}
ll match()
{
ll sum=;
for(int i=;i<=n;i++)
{
memset(used,,sizeof(used));
if(Find(i)) sum++;
}
return sum;
}
int main()
{
cin>>t;
int k=;
while(t--)
{
memset(nxt,,sizeof(nxt));
int d,dd;
cin>>d>>dd;
if(d>dd) swap(d,dd);
cout<<"Case #"<<++k<<": ";
if(d>)
cout<<"No"<<endl;
else
{
n=m=d;
for(int i=;i<=d;i++)
a[i]=++dd;
for(int i=;i<=d;i++)
b[i]=i;
if(match()==n) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
} } return ;
}

邻接矩阵

#include<iostream>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<math.h>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> PII;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
//head
#define MAX 1005
int t;
int n;
vector<int >G[MAX];
int nxt[MAX],used[MAX];
bool Find(int x)
{
for(int i=;i<G[x].size();i++)
{
int v=G[x][i];
if(!used[v])
{
used[v]=;
if(nxt[v]==||Find(nxt[v]))
{
nxt[v]=x;
return true;
}
}
}
return false;
}
int match()
{
int sum=;
for(int i=;i<=n;i++)
{
memset(used,,sizeof(used));
if(Find(i)) sum++;
}
return sum;
}
int main()
{
scanf("%d",&t);
int k=;
while(t--)
{
for(int i=;i<=n;i++)
G[i].clear();
memset(nxt,,sizeof(nxt));
int d,dd;
scanf("%d %d",&d,&dd);
if(d>dd) swap(d,dd);
printf("Case #%d: ",++k);
if(d>)
printf("No\n");
else
{
n=d;
for(int i=;i<=d;i++)
{
int tmp=dd+i;
for(int j=;j<=n;j++)
{
if(tmp%j==)
G[j].push_back(i);
}
}
if(match()==n) printf("Yes\n");
else printf("No\n");
}
}
return ;
}

邻接表

hdu5943 Kingdom of Obsession 二分图+打表找规律的更多相关文章

  1. hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)

    Nim or not Nim? Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Sub ...

  2. HDU 5753 Permutation Bo (推导 or 打表找规律)

    Permutation Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5753 Description There are two sequen ...

  3. HDU 4861 Couple doubi (数论 or 打表找规律)

    Couple doubi 题目链接: http://acm.hust.edu.cn/vjudge/contest/121334#problem/D Description DouBiXp has a ...

  4. HDU2149-Good Luck in CET-4 Everybody!(博弈,打表找规律)

    Good Luck in CET-4 Everybody! Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  5. 【ZOJ】3785 What day is that day? ——浅谈KMP在ACM竞赛中的暴力打表找规律中的应用

    转载请声明出处:http://www.cnblogs.com/kevince/p/3887827.html    ——By Kevince 首先声明一下,这里的规律指的是循环,即找到最小循环周期. 这 ...

  6. HDU 5795 A Simple Nim(SG打表找规律)

    SG打表找规律 HDU 5795 题目连接 #include<iostream> #include<cstdio> #include<cmath> #include ...

  7. hdu_5894_hannnnah_j’s Biological Test(打表找规律)

    题目链接:hdu_5894_hannnnah_j’s Biological Test 题意: 有n个不同的位置围成一个圈,现在要安排m个人坐,每个人至少的间隔为k,问有多少种安排 题解: 先打表找规律 ...

  8. hdu_5795_A Simple Nim(打表找规律的博弈)

    题目链接:hdu_5795_A Simple Nim 题意: 有N堆石子,你可以取每堆的1-m个,也可以将这堆石子分成3堆,问你先手输还是赢 题解: 打表找规律可得: sg[0]=0 当x=8k+7时 ...

  9. hdu_5793_A Boring Question(打表找规律)

    题目链接:hdu_5793_A Boring Question 题意: 自己看吧,说不清楚了. 题解: 打表找规律 #include<cstdio> typedef long long l ...

随机推荐

  1. git 和码云的上传文件代码操作

    Git与Github的连接与使用 一 安装git软件 1.git介绍 ''' git是一款免费.开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目.​ 分布式相比于集中式的最大区别在于开发 ...

  2. Java 遇到的困难

    (1)需求:xml 转 json 依赖的包:commons-beanutils-1.8.3.jarcommons-collections-3.2.1.jarcommons-lang-2.6.jarco ...

  3. linux NFS 服务器的安装

    1. 安装 nfs 服务 [root@allentuns ~]# yum -y install  nfs-utils rpcbind 2. 启动 nfs 服务 [root@allentuns ~]# ...

  4. passwd - 密码文件

    描述 Passwd 是个文本文件, 它包含了一个系统帐户列表, 给出每个帐户一些有用的信息,比如用户 ID,组 ID, 家目录, shell,等. 通常它也包含了每个用户经过加密的密码. 它通常应该是 ...

  5. python面向对象--item方法

    class Foo: def __getitem__(self, item): print("getitem") return self.__dict__[item] def __ ...

  6. java selenium常用API汇总

    (WebElement.iFrame.select.alert.浏览器窗口.事件.js)     一 WebElement相关方法 1.点击操作 WebElement button = driver. ...

  7. Python---基础---list(列表)

    2019-05-20 一. # append()  向列表末尾追加新元素   返回值Nonelist1 = [1,2,3,4,5]print(id(list1))list1.append(6)prin ...

  8. Github熟悉一

    Code/代码 Commits/提交 Issues/问题 Packages/包装 Marketplace/市场 Topics/话题 Wikis/维基百科 Users/用户 Pull requests/ ...

  9. bio编程示例

    直接干代码,用BIO写一个Server端,然后使用telnet模拟客户端发送数据 import java.io.IOException; import java.io.InputStream; imp ...

  10. 史上最全最实用HBuilder快捷键大全

    史上最全最实用HBuilder快捷键大全 一.文件操作二.编辑操作三.插入操作四.转义操作五.选择操作六.跳转操作七.查找操作八.运行九.视图一.文件操作新建菜单: ctrl + N新建: ctrl ...