题干:

There is a kindom of obsession, so people in this kingdom do things very strictly.

They name themselves in integer, and there are nn people with their id continuous (s+1,s+2,⋯,s+n)(s+1,s+2,⋯,s+n) standing in a line in arbitrary order, be more obsessively, people with id xx wants to stand at ythyth position which satisfy

xmody=0xmody=0
Is there any way to satisfy everyone's requirement?

Input

First line contains an integer TT, which indicates the number of test cases.

Every test case contains one line with two integers nn, ss.

Limits 
1≤T≤1001≤T≤100. 
1≤n≤1091≤n≤109. 
0≤s≤1090≤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 yequals 'No'.

Sample Input

2
5 14
4 11

Sample Output

Case #1: No
Case #2: Yes

题目大意:

给定S,N,把S+1,S+2,...S+N这N个数填到1,2,...,N里,要求X只能填到X的因子的位置。(即X%Y=0,那么X才能放在Y位置)。问是否能够放满。

解题报告:

首先打表猜出素数的间隔不会超过300,于是乎如果n大于300,那么就是NO,否则的话就是用那些数字去匹配这些位置,考虑匈牙利算法求解匹配问题。

写完发现怎么都WA,后来发现s==0的时候需要特判,交,WA。然后发现s==1也需要特判,s==2好像也可以特判。。。GG。

赛后知道,因为s和n相差很大的话,中间的都可以抵消掉,所以有多少素数都无所谓,所以可以把s和n互换一下,再去判断。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
const int MAX = 300 + 5;
double H,h,D;
bool bk[MAX];
bool line[MAX][MAX];
int nxt[MAX];
bool used[MAX];
int n,s;
bool find(int v) {for(int i = 1; i<=n; i++) {if(!used[i] && line[v][i]) {used[i]=1; if(!nxt[i] || find(nxt[i])) {nxt[i]=v;return 1;}}}return 0 ;
}
int match(int m) {int res = 0;for(int i = 1; i<=m; i++) {memset(used,0,sizeof used);if(find(i)) res++;}return res;
}
int main()
{int t;cin>>t;int iCase = 0;while(t--) {scanf("%d%d",&n,&s);if(s == 0 || n == 1 || s == 1 || s == 2) {printf("Case #%d: Yes\n",++iCase);continue;}if(s < n) swap(s,n);if(n >= 300) {printf("Case #%d: No\n",++iCase);continue;}ll low = s+1,up = s+n;int flag = 1;memset(line,0,sizeof line);memset(nxt,0,sizeof nxt);for(ll i = low; i<=up; i++) {for(int j = 1; j<=n; j++) {if(i%j==0) line[i-low+1][j] = 1;}}int ans = match(up-low+1);if(ans == n) flag = 1;else flag = 0;if(flag) printf("Case #%d: Yes\n",++iCase);else printf("Case #%d: No\n",++iCase);}return 0 ;
}

【HDU - 5943】Kingdom of Obsession(数论,素数间隔结论,构造,思维,匈牙利算法,匹配问题)相关推荐

  1. 【HDU - 4185】Oil Skimming (二分图,建图,匈牙利算法)

    题干: Thanks to a certain "green" resources company, there is a new profitable industry of o ...

  2. 华为机试 素数伴侣 匹配匈牙利算法

    题目描述 题目描述 若两个正整数的和为素数,则这两个正整数称之为"素数伴侣",如2和5.6和13,它们能应用于通信加密.现在密码学会请你设计一个程序,从已有的N(N为偶数)个正整数 ...

  3. 匈牙利算法编程c语言,华为oj之素数伴侣---匈牙利算法

    版权声明:本文为博主原创文章,未经博主允许不得转载. 题目描述 若两个正整数的和为素数,则这两个正整数称之为"素数伴侣",如2和5.6和13,它们能应用于通信加密.现在密码学会请你 ...

  4. HDU 4081 Qin Shi Huang's National Road System (次小生成树算法)

    转载自http://blog.csdn.net/shuangde800 D_Double 题目: Problem Description During the Warring States Perio ...

  5. HDU 5943 2016CCPC杭州 K: Kingdom of Obsession(二分匹配)

    题意:给你一张二分图,左边是s+1到s+n这n个数,右边是1到n这n个数 如果x在左边,y在右边,且x%y==0,那么x可以和y匹配,问这个二分图是否存在完美匹配 如果左边有两个以上的质数出现,那么一 ...

  6. 杭电2019多校第三场 HDU-6608 Fansblog(威尔逊定理+素数间隔+逆元)

    威尔逊定理:在初等数论中,威尔逊定理给出了判定一个自然数是否为素数的充分必要条件.即:当且仅当p为素数时:( p -1 )! ≡ -1 ( mod p ),但是由于阶乘是呈爆炸增长的,其结论对于实际操 ...

  7. 张益唐对于素数间隔有限研究概述

    来自人人上王怡的日志 鄙人稍作修改 2013.8.23 张益唐先生报告之证明概要 23号下午张益唐先生受邀到校做了名为<Bounded gaps between primes and relev ...

  8. pku 2635 The Embarrassed Cryptographer 数论——素数筛选法+模拟大数除法

    http://poj.org/problem?id=2635 因为给定的k是两个素数的乘机,所以该数所包含的因子是{1,K,p,q}假设k = p*q p,q为素数,所以只要从小到大枚举小于L的素数, ...

  9. hdu 3123(GCC)数论

    http://acm.hdu.edu.cn/showproblem.php?pid=3123 题目给出的n很大,很明显如果n很大时,是不用处理到n的,所以其中必有蹊跷! 当n大于m时 ,n的阶乘中必定 ...

最新文章

  1. 同时上哈佛,还一起一作发Nature!这对95后学霸情侣让人慕了……
  2. axure中备注线_琉璃:璇玑小本子上,别人名字都有备注唯独司凤没有,意义很浪漫...
  3. 人均年薪400万、公司年亏40亿,正在盖大楼的DeepMind最新财务数据曝光
  4. 使用HTML文件作为中转生成WORD文档
  5. hdu 1042 N! 高精度运算
  6. @ComponentScan配置扫描多个包
  7. Java并发包--线程池框架
  8. PHP-Manual的学习----【语言参考】----【类型】-----【对象】
  9. go设置后端启动_Go语言基础(十四)
  10. 美国散户从90%降到6%,他们是如何被“消灭”的?
  11. 华为交换机初始化_华为交换机的初始配置
  12. 高效能程序员的修炼札记:创建和管理社区
  13. 活动现场大屏幕互动系统源码,包含3D签到投票抽奖等功能
  14. 用计算机画对称图形,人教小学美术五下《第17课电脑美术 对称图形》word教案...
  15. a[i][j] 和 a[j][i] 的区别
  16. AD9361配置(1)
  17. 多个图元合并其中相邻的图元
  18. 用pyhton爬虫技术爬取所有股票的每周价格
  19. Effie:真正的极简主义!秒杀幕布
  20. 系统安全博客3-windowsserver安全加固

热门文章

  1. 可以无限增加iPhone 的图标吗?
  2. oracle 9i从入门到精通读书笔记2
  3. 高中计算机教师招聘试题,中小学信息技术教师招聘考试真题及答案.doc
  4. Slimming Down Windows XP The Complete Guide 【 10章完整版 】
  5. mysql上k8s_通过搭建MySQL掌握k8s(Kubernetes)重要概念(上):网络与持久卷
  6. 为什么将表格的method改为post后就无法工作_用Python将Keras深度学习模型部署为Web应用程序...
  7. 1到n阶乘算法的改进
  8. 1612D. X-Magic Pair
  9. 866. 试除法判定质数
  10. 怎么查看usb读取信息_电脑弹出USB设备时提示该设备正在使用中的解决方法