Codeforces 922F Divisibility 构造
我们考虑删数字
首先我们可以发现有一类数很特殊就是大于 n / 2的素数, 因为这些素数的贡献只有1, 并且在n大的时候,
这些素数的个数不是很少, 我们可以最后用这些数去调整, 并且删掉一个数的时候删掉的是它的因子个数,
所以可以用素数去控制最后的数量。当n小的时候直接状压枚举。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long using namespace std; const int N = 1e6 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-;
const double PI = acos(-); int n;
LL k;
int rel[N];
bool vis[N];
int now;
vector<int> vc;
set<int> Set;
vector<int> fac[N]; int main() {
scanf("%d%lld", &n, &k);
if(n <= ) {
vector<int> ret;
for(int S = ; S < ( << n); S++) {
ret.clear();
for(int i = ; i < n; i++)
if(S >> i & ) ret.push_back(i + );
int cnt = ;
for(int i = ; i < SZ(ret); i++) {
for(int j = i + ; j < SZ(ret); j++) {
if(ret[j] % ret[i] == ) {
cnt++;
}
}
}
if(cnt == k) {
puts("Yes");
printf("%d\n", SZ(ret));
for(auto& t : ret) printf("%d ", t);
puts("");
return ;
}
}
puts("No");
} else {
for(int i = ; i <= n; i++) {
for(int j = i + i; j <= n; j += i)
vis[j] = true;
}
for(int i = ; i <= n; i++) Set.insert(i);
for(int i = ; i <= n; i++) {
for(int j = i + i; j <= n; j += i) {
now++;
rel[j]++;
rel[i]++;
fac[j].push_back(i);
}
}
if(now < k) {
puts("No");
return ;
}
if(now == k) {
puts("Yes");
printf("%d\n", SZ(Set));
for(auto& t : Set) printf("%d ", t);
puts("");
return ;
}
for(int i = n / + ; i <= n; i++) {
if(!vis[i]) {
vc.push_back(i), now--, Set.erase(i);
rel[]--;
if(now == k) {
puts("Yes");
printf("%d\n", SZ(Set));
for(auto& t : Set) printf("%d ", t);
puts("");
return ;
}
}
}
while(now > k) {
int v = *Set.rbegin();
if(rel[v] <= now - k) {
now -= rel[v];
Set.erase(v);
for(auto& t : fac[v]) rel[t]--;
} else {
int who = v;
for(auto& t : Set)
if(now - rel[t] <= k && rel[t] < rel[who]) who = t;
now -= rel[who];
Set.erase(who);
for(auto& t : fac[who]) rel[t]--;
while(now < k && SZ(vc)) {
now++;
Set.insert(vc.back());
vc.pop_back();
}
}
}
if(now == k) {
puts("Yes");
printf("%d\n", SZ(Set));
for(auto& t : Set) printf("%d ", t);
puts("");
return ;
} else {
puts("No");
}
}
return ;
} /*
*/
Codeforces 922F Divisibility 构造的更多相关文章
- Codeforces 922F Divisibility (构造 + 数论)
题目链接 Divisibility 题意 给定$n$和$k$,构造一个集合$\left\{1, 2, 3, ..., n \right\}$的子集,使得在这个集合中恰好有$k$对正整数$(x, y) ...
- codeforces 1041 e 构造
Codeforces 1041 E 构造题. 给出一种操作,对于一棵树,去掉它的一条边.那么这颗树被分成两个部分,两个部分的分别的最大值就是这次操作的答案. 现在给出一棵树所有操作的结果,问能不能构造 ...
- Codeforces 550C —— Divisibility by Eight——————【枚举 || dp】
Divisibility by Eight time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Codeforces - 474D - Flowers - 构造 - 简单dp
https://codeforces.com/problemset/problem/474/D 这道题挺好的,思路是这样. 我们要找一个01串,其中0的段要被划分为若干个连续k的0. 我们设想一个长度 ...
- [math] Codeforces 597A Divisibility
题目:http://codeforces.com/problemset/problem/597/A Divisibility time limit per test 1 second memory l ...
- Codeforces Global Round 8 B. Codeforces Subsequences(构造)
题目链接:https://codeforces.com/contest/1368/problem/B 题意 构造最短的至少含有 $k$ 个 $codeforces$ 子序列的字符串. 题解 如下表: ...
- Codeforces 410C.Team[构造]
C. Team time limit per test 1 second memory limit per test 256 megabytes input standard input output ...
- Codeforces 716C[数论][构造]
/* CF傻逼构造题 某人要经过n回合游戏,初始分值是2,等级为1. 每次有两种操作 1.无条件,分值加上自己的等级数. 2.当目前的数字是完全平方数并且该数字开方以后是等级数加1的整数倍,那么可以将 ...
- codeforces 630J Divisibility
J. Divisibility time limit per test 0.5 seconds memory limit per test 64 megabytes input standard in ...
随机推荐
- 前端lvs访问多台nginx代理服务时出现404错误的处理
前端lvs访问多台nginx代理服务时出现404错误的处理 环境描述:app --> lvs --> nginx --> server app访问页面购买流量页面(nginx服务器) ...
- 使用mysql自带工具mysqldump进行全库备份以及source命令恢复数据库
mysql数据库提供了一个很好用的工具mysqldump用以备份数据库,下面将使用mysqldump命令进行备份所有数据库以及指定数据库 一.mysqldump一次性备份所有数据库数据 /usr/lo ...
- RabbitMQ:MSVCR120.dll ,c000001d 错误
今天在win7上面安装RabbitMQ,安装过程没有问题,但是RabbitMQ无法启动,错误如下: 今多方查找,原因在于win7没有安装SP1的补丁包,安装完成后,启动RabbitMQ就没有问题了. ...
- POJ 1305
毕达哥斯三元组的模板题 练习练习 #include<iostream> #include<cstring> #include<cstdio> #include< ...
- [正则表达式]匹配Unicode
一.PHP[PCRE]之Unicode PCRE支持的16进制字符编码转义符有 \x00-\xFF,或\x{num},num为任意位16进制数 但并不支持\u0000-\uFFFF这的形式 PCRE运 ...
- tomcat占用cpu比较多
在Linux中当Tomcat启动后,我们只是去查看应用是否能够正常访问来判断Tomcat启动是否正常.一般情况下这样看是没有问题的,但是有时候我们会发现当Tomcat使用了一段时间后,开始出现CPU或 ...
- 41)django-admin
一:介绍 通过django admin可以快速生成后台管理功能. 二:设置 工程同名下settings.py 1)在INSTALLED_APPS中增加django.contrib.admin 2)在I ...
- 30)django-ORM(元信息,级联删除,正反向操作,连表查询优化)
一:元信息 class User(models.Model): name=models.CharField(max_length,index=True) email=model.CharField(m ...
- python中的各种锁
一.全局解释器锁(GIL) 1.什么是全局解释器锁 在同一个进程中只要有一个线程获取了全局解释器(cpu)的使用权限,那么其他的线程就必须等待该线程的全局解释器(cpu)使 用权消失后才能使用全局解释 ...
- PID控制器开发笔记之二:积分分离PID控制器的实现
前面的文章中,我们已经讲述了PID控制器的实现,包括位置型PID控制器和增量型PID控制器.但这个实现只是最基本的实现,并没有考虑任何的干扰情况.在本节及后续的一些章节,我们就来讨论一下经典PID控制 ...