codeforces 632D. Longest Subsequence 筛法
记录小于等于m的数出现的次数, 然后从后往前筛, 具体看代码。
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, n, a) for(int i = a; i<n; i++)
#define fi first
#define se second
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-;
const int mod = 1e9+;
const int inf = ;
const int dir[][] = { {-, }, {, }, {, -}, {, } };
int a[], cnt[], maxx, pos, flag;
int main()
{
int n, m;
cin>>n>>m;
for(int i = ; i<=n; i++) {
scanf("%d", &a[i]);
if(a[i]<=m) {
cnt[a[i]]++;
flag = ;
}
}
if(!flag) {
puts("1 0");
return ;
}
for(int i = m; i>=; i--) {
for(int j = *i; j<=m; j+=i) {
cnt[j] += cnt[i];
}
}
for(int i = ; i<=m; i++) {
if(cnt[i]>maxx) {
maxx = cnt[i];
pos = i;
}
}
cout<<pos<<" "<<maxx<<endl;
for(int i = ; i<=n; i++) {
if(pos%a[i]==)
printf("%d ", i);
}
return ;
}
codeforces 632D. Longest Subsequence 筛法的更多相关文章
- Codeforces 632D Longest Subsequence 2016-09-28 21:29 37人阅读 评论(0) 收藏
D. Longest Subsequence time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- CodeForces 632D Longest Subsequence
暴力. 虽然$a[i]$最大有${10^9}$,但是$m$最大只有${10^6}$,因此可以考虑暴力. 记$cnt[i]$表示数字$i$有$cnt[i]$个,记$p[i]$表示以$i$为倍数的情况下, ...
- Educational Codeforces Round 9 D. Longest Subsequence dp
D. Longest Subsequence 题目连接: http://www.codeforces.com/contest/632/problem/D Description You are giv ...
- Educational Codeforces Round 9 D - Longest Subsequence
D - Longest Subsequence 思路:枚举lcm, 每个lcm的答案只能由他的因子获得,类似素数筛搞一下. #include<bits/stdc++.h> #define ...
- CF632D Longest Subsequence
D. Longest Subsequence time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- D. Longest Subsequence
D. Longest Subsequence time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- [Codeforces 280D]k-Maximum Subsequence Sum(线段树)
[Codeforces 280D]k-Maximum Subsequence Sum(线段树) 题面 给出一个序列,序列里面的数有正有负,有两种操作 1.单点修改 2.区间查询,在区间中选出至多k个不 ...
- [徐州网络赛]Longest subsequence
[徐州网络赛]Longest subsequence 可以分成两个部分,前面相同,然后下一个字符比对应位置上的大. 枚举这个位置 用序列自动机进行s字符串的下标转移 注意最后一个字符 #include ...
- codeforces632D. Longest Subsequence (最小公倍数)
You are given array a with n elements and the number m. Consider some subsequence of a and the value ...
随机推荐
- arcgis切图问题
头一次用ArcGIS Server切图,所以遇到问题总是摸不着头脑,网上一个劲的搜罗,可惜ArcGIS Server使用的资料实在太少,所以只好自己憋,或者问客服了.切图今天积累了不少了经验,记录下, ...
- 出现"无法连接synaptics定点装置驱动程序"
"开始“--”运行“--regedit(打开注册表)--依次打开 HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows/CurrentVERSION/R ...
- 常用Python第三方库 简介
如果说强大的标准库奠定了python发展的基石,丰富的第三方库则是python不断发展的保证,随着python的发展一些稳定的第三库被加入到了标准库里面,这里有6000多个第三方库的介绍:点这里或者访 ...
- 【grunt整合版】学会使用grunt打包前端代码
grunt 是一套前端自动化工具,一个基于nodeJs的命令行工具,一般用于:① 压缩文件② 合并文件③ 简单语法检查 对于其他用法,我还不太清楚,我们这里简单介绍下grunt的压缩.合并文件,初学, ...
- boa,thttp服务器安装,配置,测试
boa 1, SERVER_ROOT自定义,define.h头文件中,默认“/etc/boa" 2,./configure 3,修改CC,默认CC=gcc,make 4,error util ...
- [原创]linux简单之美(一)
原文链接:linux简单之美(一) 话说windows也有syscall,这是必须的.但是win的syscall可以直接call吗?可以是可以但是破费周折,搞成SDT之类的复杂概念.下面看看linux ...
- 4.java.lang.NumberFormatException(数据类型转换异常)
字符串转换为数字异常 当试图将一个String转换为指定的数字类型,而该字符串确不满足数字类型要求的格式时,抛出该异常.如现在讲字符型的数据“123456”转换为数值型数据时,是允许的. 但是如果字符 ...
- Umbraco Content属性
总算是有个内容还算多的Content的属性介绍,保存一下. https://our.umbraco.org/documentation/Reference/Management-v6/Models/C ...
- git多人协作
多人协作 当你从远程仓库克隆时,实际上Git自动把本地的master分支和远程的master分支对应起来了,并且,远程仓库的默认名称是origin. 要查看远程库的信息,用git remote: $ ...
- 看大数据时代下的IT架构(1)业界消息队列对比
一.MQ(Message Queue) 即 消息队列,一般用于应用系统解耦.消息异步分发,能够提高系统吞吐量.MQ的产品有很多,有开源的,也有闭源,比如ZeroMQ.RabbitMQ. ActiveM ...