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 ...
随机推荐
- Github+HEXO FATAL bad indentation of a mapping entry at line 84
当配置玩_config.yml文件时,执行hexo g -d时出现错误如下: $ hexo g -d FATAL can not read a block mapping entry; a multi ...
- mysql定时任务,每天的零点执行一个存储过程
1 前言 利用navicat工具来写存储过程及定时执行,此文章是按照自身经验总结的,仅作为记录使用. 2 步骤 2.1 新建过程 2.2 在函数体写你需要执行的代码 CREATE DEFINER=`r ...
- Oracle 数据库导入与出
Oracle 数据库导入与出 导出( EXPORT )是用 EXP 将数据库部分或全对象的结构和导出 . 导入( 导入( IMPORT )是用 )是用 IMP IMP将 OS 文件中的对象结构和数据装 ...
- PHP7运行环境搭建(Windows7)
注:本文来源于< PHP7运行环境搭建(Windows7) > php7号称能直追facebook的HHVM,为了体验一把传说中的高性能,我特意在本地电脑上尝试着安装了php7, ...
- js工具库---Lodash
Lodash是一个一致性.模块化.高性能的 JavaScript 实用工具库 为什么选择 Lodash ? Lodash 通过降低 array.number.objects.string 等等的使用难 ...
- ionic3 极光推送
参考网站:http://www.jianshu.com/p/eb8ab29329d9 遇到的问题是 执行以下命令一直报错 cordova plugin add https://github.com/ ...
- redis客户端、分布式锁及数据一致性
Redis Java客户端有很多的开源产品比如Redission.Jedis.lettuce等. Jedis是Redis的Java实现的客户端,其API提供了比较全面的Redis命令的支持:Redis ...
- LeetCode(96): 不同的二叉搜索树
Medium! 题目描述: 给定一个整数 n,求以 1 ... n 为节点组成的二叉搜索树有多少种? 示例: 输入: 3 输出: 5 解释: 给定 n = 3, 一共有 5 种不同结构的二叉搜索树: ...
- LeetCode(77):组合
Medium! 题目描述: 给定两个整数 n 和 k,返回 1 ... n 中所有可能的 k 个数的组合. 示例: 输入: n = 4, k = 2 输出: [ [2,4], [3,4], [2,3] ...
- mysql 各种关系代数的使用
连接(JOIN) 选择运算表示为: R⋈S ,其中R和S为不同的两个关系 连接运算是选取两个指定关系中的属性满足给定条件的元祖连接在一起来组成一个新的关系 数学形式: JOIN 关系名1 AND 关系 ...