题目传送门

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. C# 给DataTable去重

    using System; using System.Data; namespace DelegateTest { public class Program { public static void ...

  2. 一、.Net Core 分块上传文件

    一..Net Core 分块上传文件 一.前端实现 @* For more information on enabling MVC for empty projects, visit http://g ...

  3. 21eval 函数

    eval() 函数十分强大 ---- 将字符串 当成 有效的表达式 来求职 并 返回计算结果 # 基本的数学计算 # 字符串重复 print(eval("'*' * 5")) # ...

  4. JS原型和原型链(3)

    构造函数创建对象: function Person() { } var person = new Person(); person.name = 'Kevin'; console.log(person ...

  5. LeetCode--050--Pow(x,n)

    实现 pow(x, n) ,即计算 x 的 n 次幂函数. 示例 1: 输入: 2.00000, 10 输出: 1024.00000 示例 2: 输入: 2.10000, 3 输出: 9.26100 ...

  6. python学习笔记(十五)python操作数据库

    1.连接mysql,ip,端口号,密码,账号,数据库 2.建立游标 3.执行sql 4.获取结果 5.关闭连接,关闭游标 游标打开仓库的大门: import pymysql conn=pymysql. ...

  7. 新手立体四子棋AI教程(4)——启发式搜索与主程序

    通过前面几篇文章的学习,我们的四子棋程序已经有了框架.搜索几大部分,但是还有着不少问题,我们的程序只能迭代很有限的步骤,导致棋力低下,在这一篇我们将通过启发式搜索极大的优化搜索效率. 一.原因 我们之 ...

  8. windows server IIS启用Windows authentication

    双击打开IIS网站的authentication,如果有Windows authentication,直接右键启用即可,如果没有的话需要先安装一下Windows authentication,Micr ...

  9. JQuery触发hover事件无效时使用js原生的触发事件方法

    需求:在开发一个从微信公众号后台管理网页上爬取数据的chrome插件时,有部分页面元素是只显示了部分摘要信息的,需要把鼠标移上去后才能显示全部信息(类似title的弹出显示).这就需要在chrome插 ...

  10. 不间断电源(UPS)

    UPS电源一般指不间断电源 UPS(Uninterruptible Power System/Uninterruptible Power Supply),即不间断电源,是将蓄电池(多为铅酸免维护蓄电池 ...