hdu5943 Kingdom of Obsession 二分图+打表找规律
题目传送门
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
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
Is there any way to satisfy everyone's requirement?
Every test case contains one line with two integers n, s.
Limits
1≤T≤100.
1≤n≤109.
0≤s≤109.
If there is any way to satisfy everyone's requirement, y equals 'Yes', otherwise y equals 'No'.
5 14
4 11
Case #2: Yes
#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 二分图+打表找规律的更多相关文章
- hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)
Nim or not Nim? Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Sub ...
- HDU 5753 Permutation Bo (推导 or 打表找规律)
Permutation Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5753 Description There are two sequen ...
- HDU 4861 Couple doubi (数论 or 打表找规律)
Couple doubi 题目链接: http://acm.hust.edu.cn/vjudge/contest/121334#problem/D Description DouBiXp has a ...
- 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 ...
- 【ZOJ】3785 What day is that day? ——浅谈KMP在ACM竞赛中的暴力打表找规律中的应用
转载请声明出处:http://www.cnblogs.com/kevince/p/3887827.html ——By Kevince 首先声明一下,这里的规律指的是循环,即找到最小循环周期. 这 ...
- HDU 5795 A Simple Nim(SG打表找规律)
SG打表找规律 HDU 5795 题目连接 #include<iostream> #include<cstdio> #include<cmath> #include ...
- hdu_5894_hannnnah_j’s Biological Test(打表找规律)
题目链接:hdu_5894_hannnnah_j’s Biological Test 题意: 有n个不同的位置围成一个圈,现在要安排m个人坐,每个人至少的间隔为k,问有多少种安排 题解: 先打表找规律 ...
- hdu_5795_A Simple Nim(打表找规律的博弈)
题目链接:hdu_5795_A Simple Nim 题意: 有N堆石子,你可以取每堆的1-m个,也可以将这堆石子分成3堆,问你先手输还是赢 题解: 打表找规律可得: sg[0]=0 当x=8k+7时 ...
- hdu_5793_A Boring Question(打表找规律)
题目链接:hdu_5793_A Boring Question 题意: 自己看吧,说不清楚了. 题解: 打表找规律 #include<cstdio> typedef long long l ...
随机推荐
- C# 给DataTable去重
using System; using System.Data; namespace DelegateTest { public class Program { public static void ...
- 一、.Net Core 分块上传文件
一..Net Core 分块上传文件 一.前端实现 @* For more information on enabling MVC for empty projects, visit http://g ...
- 21eval 函数
eval() 函数十分强大 ---- 将字符串 当成 有效的表达式 来求职 并 返回计算结果 # 基本的数学计算 # 字符串重复 print(eval("'*' * 5")) # ...
- JS原型和原型链(3)
构造函数创建对象: function Person() { } var person = new Person(); person.name = 'Kevin'; console.log(person ...
- LeetCode--050--Pow(x,n)
实现 pow(x, n) ,即计算 x 的 n 次幂函数. 示例 1: 输入: 2.00000, 10 输出: 1024.00000 示例 2: 输入: 2.10000, 3 输出: 9.26100 ...
- python学习笔记(十五)python操作数据库
1.连接mysql,ip,端口号,密码,账号,数据库 2.建立游标 3.执行sql 4.获取结果 5.关闭连接,关闭游标 游标打开仓库的大门: import pymysql conn=pymysql. ...
- 新手立体四子棋AI教程(4)——启发式搜索与主程序
通过前面几篇文章的学习,我们的四子棋程序已经有了框架.搜索几大部分,但是还有着不少问题,我们的程序只能迭代很有限的步骤,导致棋力低下,在这一篇我们将通过启发式搜索极大的优化搜索效率. 一.原因 我们之 ...
- windows server IIS启用Windows authentication
双击打开IIS网站的authentication,如果有Windows authentication,直接右键启用即可,如果没有的话需要先安装一下Windows authentication,Micr ...
- JQuery触发hover事件无效时使用js原生的触发事件方法
需求:在开发一个从微信公众号后台管理网页上爬取数据的chrome插件时,有部分页面元素是只显示了部分摘要信息的,需要把鼠标移上去后才能显示全部信息(类似title的弹出显示).这就需要在chrome插 ...
- 不间断电源(UPS)
UPS电源一般指不间断电源 UPS(Uninterruptible Power System/Uninterruptible Power Supply),即不间断电源,是将蓄电池(多为铅酸免维护蓄电池 ...