题目传送门

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. Maven 集成Tomcat插件(引用)

    Maven已经是Java的项目管理标配,如何在JavaEE开发使用Maven调用Web应用,是很多同学关心的问题.本文将介绍,Maven如何介绍Tomcat插件. Maven Tomcat插件现在主要 ...

  2. Winfrom中数据的双向绑定(使用INotifyPropertyChanged)

    在WPF中新建项目是自动实现了INotifyPropertyChanged接口,用于数据绑定时非常的方便在winfrom中也可以实现INotifyPropertyChanged接口 将需要绑定的字段写 ...

  3. Express 2015 RC for Windows 10 安装

    支持的操作系统 Windows 10 Technical Preview 硬件要求 1.6 GHz 或更快的处理器 1 GB RAM(如果在虚拟机上运行,则为 1.5 GB) 4 GB 可用硬盘空间 ...

  4. nodejs 文件读写

    文件读取: //例如: fs.readFile 就是用来读取文件的 //1. 使用require方法来加载 fs 核心模块 var fs = require('fs'); /* *2. 读取文件 * ...

  5. 了解Greenplum (2)

    一.目的 1. 理解Greenplum中的数据分布策略(random 和 distribution),分析不同分布策略的优劣:2. 理解查询执行中的数据广播和数据重分布,分析在何种情况下选择哪种策略, ...

  6. linux里面以指定用户运行命令

    一.chroot方式 [root@localhost ~]# chroot --userspec "nginx:nginx" "/" sh -c "w ...

  7. 迁移数据时 timestamp类型字段报错: 1067 - Invalid default value for 'login_time'

    MySQL数据库升级 8.0.13,原版本5.5:执行导出来的SQL文件时报错 1067 - Invalid default value for 'login_time' 原因:MySQL 5.6以后 ...

  8. iOS---实现简书和知乎的上滑隐藏导航栏下拉显示导航栏效果

    因为自己用简书和知乎比较多,所以对其导航栏的效果比较好奇,自己私下里找资料实现了一下.这个效果的关键点在于下方可供滑动的内容的便宜距离inset的改变,以及滑动的scrollview代理的执行,废话不 ...

  9. WEB前端开发的思考与感悟

    当我想要认真写一篇文章向大家分享我对前端的认识与感悟的时候,突然就深刻的体会到了这句话确实太有道理了. 最近几年对于web前端的传闻很多,比如人才稀缺,简单易学,待遇丰厚,整体势头发展良好等等.遇到过 ...

  10. luoguP4721 【模板】分治 FFT (分治NTT)

    给定 $g[1....n-1]$,求 $f[0],f[1],...,f[n-1]$,其中   $f[i]=\sum_{j=1}^{i}f[i-j]g[j]$    变界为 $f[0]=1$ 答案模 9 ...