HDU 5943 Kingdom of Obsession (二分图)

来源:互联网 发布:照片冲印排版软件 编辑:程序博客网 时间:2024/06/07 17:01

Kingdom of Obsession

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

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
2016年中国大学生程序设计竞赛(杭州)

利用素数之间距离比较密的原理,再套个kuangbin的hungry模板就过了。

#include "cstring"#include "cstdio"#include "string.h"#include "iostream"using namespace std;const int MAXN=510;int uN,vN;//u,v数目int g[MAXN][MAXN];int linker[MAXN];bool used[MAXN];bool dfs(int u)//从左边开始找增广路径{    int v;    for(v=1;v<=vN;v++)//这个顶点编号从0开始,若要从1开始需要修改        if(g[u][v]&&!used[v])        {            used[v]=true;            if(linker[v]==-1||dfs(linker[v]))            {//找增广路,反向                linker[v]=u;                return true;            }        }    return false;//这个不要忘了,经常忘记这句}int hungary(){    int res=0;    int u;    memset(linker,-1,sizeof(linker));    for(u=1;u<=uN;u++)    {        memset(used,0,sizeof(used));        if(dfs(u)) res++;    }    return res;}int main(){    int t;    scanf("%d",&t);    int cas=1;    while(t--)    {        int n,s;        scanf("%d%d",&n,&s);        if(s<n)swap(n,s);//抹掉相交区间 画个图很显然        uN=vN=n;        if(n>500)        {            printf("Case #%d: No\n",cas++);            continue;        }        memset(g,0,sizeof(g));        for(int i=s+1;i<=s+n;i++)        {            for(int j=1;j<=n;j++)            {                if(i%j==0)                {                    g[i-s][j]=1;                }            }        }        if(hungary()==n)            printf("Case #%d: Yes\n",cas++);        else            printf("Case #%d: No\n",cas++);    }}
0 0
原创粉丝点击