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 ...
随机推荐
- linux循环递归设置权限
这里给出一个循环递归得到对文件夹和文件分别有效的设置方法: find /path -type f -exec chmod 644 {} \; #对目录和子目录里的文件 find /path -type ...
- OC中的一个特性:延展
OC中的一个特性:延展其实说白了,延展就是弥补C语言中的前向申明,我们知道,在C语言中,如果你想调用一个函数的话,那么在此之前必须要声明一个这个函数,就是有前置性.OC中为了弥补C语言中的这个问题,就 ...
- Spring 整合hibernante 错误java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
1.将所需的jar包全部拷贝到WEB-INF/lib下,再重新启动tomcat便能顺利通过了.参考http://blessht.iteye.com/blog/1104450 最佳答案 spring ...
- Python核心编程读笔 9: 异常
第10章 异常一.异常1 检测和处理异常 (1)try-except语句 try: try_suite #监控这里的异常 except Exception[, reason]: except_suit ...
- JS中格式化数据保留两位小数
问题:在JS中格式化数据保留两位小数的函数的多种方法 最好方法: 保留两位好像是这样吧 var a = 9.39393; alert(a.toFixed(2)); 说明: ...
- 14.java.lang.EOFException
java.lang.EOFException 文件已结束异常 当程序在输入的过程中遇到文件或流的结尾时,引发异常.因此该异常用于检查是否达到文件或流的结尾
- MBG 相关资源链接
MyBatis Generator(MBG)相关资源链接 http://mbg.cndocs.tk/quickstart.html http://www.mybatis.tk/ http://git. ...
- poj1862---变形虫(贪心)
题意:两条虫之间碰在一起,质量变为2*sqrt(m1*m2) 求怎么结合,能使最后的一只虫质量最小 分析:如果让按从大到小的顺序依次结合,可以使大的数被开方的次数最多,得到的结果更小 4 3 2 1 ...
- cf-A. Wet Shark and Odd and Even(水)
A. Wet Shark and Odd and Even time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- ebs清除并法管理器所清除的表
In this Document Goal Solution References Applies to: Oracle Concurrent Processing - Version 1 ...