题目传送门

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. MySQL的删除语句

    虽然现在数据库空间越来越大,但处理数据时候还是有要删除的时候,以下整理了一些最常用的删除语句. 分成两种 一个是删除指定数据,另一个删除所有数据. 一.删除指定数据 DELETE FROM 表名 WH ...

  2. [译]深度学习(Yann LeCun)

    深度学习 严恩·乐库  约书亚•本吉奥  杰弗里·希尔顿 摘要深度学习是计算模型,是由多个处理层学习多层次抽象表示的数据.这些方法极大地提高了语音识别.视觉识别.物体识别.目标检测和许多其他领域如药物 ...

  3. Vue的自定义滚动,我用el-scrollbar

    弄了一个持续更新的github笔记,可以去看看,诚意之作(本来就是写给自己看的--)链接地址:Front-End-Basics 此篇文章的地址:Vue的自定义滚动,我用el-scrollbar 基础笔 ...

  4. toj 4063 单词(AC自动机)

    题目: 小张最近在忙毕设,所以一直在读论文.一篇论文是由许多单词组成的. 但小张发现一个单词会在论文中出现很多次,他想知道每个单词分别在论文中出现了多少次. 输入 第一行一个整数N,表示有N个单词.接 ...

  5. Python---编辑器安装和print函数

    Python---编辑器安装和print函数 -------------------------------------------------------- 一.Python是什么? Python是 ...

  6. 对http的研究

    HTTP 简介 HTTP协议(HyperText Transfer Protocol,超文本传输协议)是因特网上应用最为广泛的一种网络传输协议,所有的WWW文件都必须遵守这个标准. HTTP是一个基于 ...

  7. re正则常用示例积累

    2019-12-7 import re ''' 示例1: 提取网站的网址 ''' urls = ['https://blog.csdn.net/xxcupid/article/details/5199 ...

  8. linux运维、架构之路-linux定时任务

    1.基础优化之开机启动服务优化 使用awk拼接的方式 [root@cache01 ~]# chkconfig |egrep -v "crond|network|sshd|rsyslog|sy ...

  9. spring boot 简介(基于SSM框架的一个升级版本吧)

    Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置.通过 ...

  10. stack1顺序栈

    顺序栈 #include<iostream> using namespace std; #define increasesize 10 template <class Object& ...