HDU5943-Kingdom of Obsession
来源:互联网 发布:crf算法原理 编辑:程序博客网 时间:2024/06/05 02:03
Kingdom of Obsession
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1162 Accepted Submission(s): 356
Problem Description
There is a kindom of obsession, so people in this kingdom do things very strictly.
They name themselves in integer, and there aren 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?
They name themselves in integer, and there are
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 integersn , s .
Limits
1≤T≤100 .
1≤n≤109 .
0≤s≤109 .
Every test case contains one line with two integers
Limits
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'.
If there is any way to satisfy everyone's requirement, y equals 'Yes', otherwise y equals 'No'.
Sample Input
25 144 11
Sample Output
Case #1: NoCase #2: Yes
Source
2016年中国大学生程序设计竞赛(杭州)
题意:有n个人,每个人的标号以此是s+1到s+n,要求将所有人重新排序之后满足每个人的位置y能够保证被他的标号整除,就是数组重排之后满足每一位的a[i]%i==0
解题思路:一定区间之内最多只有一个质数,所以多于一个质数的直接NO(差不多任意两个相邻之间的素数的差不会超过500),其他情况可以直接二分图匹配去跑,把这段区间和1~n作为2*n个节点直接n^2建图跑匈牙利就行(这段区间和1~n可能有重叠的部分,这段是要删去的,重叠部分一定满足所以不需要匹配,所以最后图中的节点就是一边时1到min(n,s)一边是max(n,s)到n+s)
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <vector>#include <queue>#include <stack>#include <map>#include <set>using namespace std;#define LL long longconst int INF=0x3f3f3f3f;int n,ss;int x[559],y[559];int s[559],nt[260009],e[260009];int visit[559];bool path(int k){ for(int i=s[k]; ~i; i=nt[i]) { int ee=e[i]; if(!visit[ee]) { visit[ee]=1; if(y[ee]==-1||path(y[ee])) { y[ee]=k; x[k]=ee; return 1; } } } return 0;}void MaxMatch(){ int ans=0; memset(x,-1,sizeof x); memset(y,-1,sizeof y); for(int i=1; i<=n; i++) { if(x[i]==-1) { memset(visit,0,sizeof visit); if(path(i)) ans++; } } if(ans==n) printf("Yes\n"); else printf("No\n");}int main(){ int t,cas=0; scanf("%d",&t); while(t--) { printf("Case #%d: ",++cas); scanf("%d%d",&n,&ss); if(ss<=1) { printf("Yes\n"); continue; } if(ss<n) swap(ss,n); if(n>550) { printf("No\n"); continue; } int cnt=1; memset(s,-1,sizeof s); for(int i=ss+1; i<=ss+n; i++) for(int j=1; j<=n; j++) if(i%j==0) nt[cnt]=s[i-ss],s[i-ss]=cnt,e[cnt++]=j; MaxMatch(); } return 0;}
阅读全文
0 0
- HDU5943-Kingdom of Obsession
- HDU5943 Kingdom of Obsession(匹配问题)
- ccpc杭州K题(hdu5943) Kingdom of Obsession
- Kingdom of Obsession
- Kingdom of Obsession HDU
- Kingdom of Obsession HDU
- hdu 5943 Kingdom of Obsession
- HDU-5943 Kingdom of Obsession
- HDU 5943 Kingdom of Obsession (二分图)
- 2016ccpc杭州赛 hdu 5934 K.Kingdom of Obsession
- HDU 5943 - Kingdom of Obsession(二分图)
- HDU-5943 Kingdom of Obsession(数学+二分图匹配)
- HDU 5943 Kingdom of Obsession(二分图)
- Hdu 5943 Kingdom of Obsession【素数+二分匹配】
- HDU 5943 Kingdom of Obsession(二分图匹配+数论)
- hdu 5943 Kingdom of Obsession(二分匹配)
- HDOJ 5943 Kingdom of Obsession【2016杭州现场赛】【二分图匹配暴力】
- 【2016-CCPC-K】匈牙利算法,最大基数匹配(Kingdom of Obsession,hdu 5943)
- 自己的事情
- php session的一点要点
- 51nod1289 大鱼吃小鱼
- Hibernate5调用Oracle中存储过程
- 最大公约数和最小公倍数
- HDU5943-Kingdom of Obsession
- Codeforces Round #421 (Div. 1):B. Mister B and PR Shifts 思维,乱搞
- 数据结构之回文字符串
- <Paper Reading>Need to solve
- RxJava合并Observable——merge和mergeDelayError操作符
- bugku CTF练习平台writeup
- 实验性的亚马逊返利连接编辑系统
- mysql数据库开启远程连接
- <Need to solve>