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 ...
随机推荐
- clientX,pageX,screenX,offsetLeft,scrollTop
出处:点击打开链接 一直不太明白,今天看了一下,感觉挺详细,先转载过来....... clientX 观点:鼠标相对于WINDOWS的坐标. 这里这个WINDOWS是指我们能看见的浏览器大小.所以不可 ...
- bootstrap-js(3)滚动监听
导航条实例 ScrollSpy插件根据滚动的位置自动更新导航条中相应的导航项. 拖动下面区域的滚动条,使其低于导航条的位置,注意观察active类的变化.下拉菜单中的子项也会跟着变为高亮状态. 1.调 ...
- 在 PL/SQL Developer 中执行SQL文件的方法
打开 command Window SQL> @'D:\My Documents\Downloads\bde_chk_cbo.sql'; 整个路径及文件两边要有单引号哦!
- C# 懒人常用异步方法
Winform this.Invoke(new Action(() => { })); Wpf this.Dispatcher.Invoke(DispatcherPriority.Normal, ...
- vb 添加状态栏
1.新建一工程2.添加"部件" ms windows common controls 6.03.将StatusBar控件加至窗体中4.右键点击该控件,选"属性" ...
- property、synthesize、id
1.@property int age; 在编译器情况下会自动编译展开为: <age在setter中首字母大写,点语法为p.age> - (void)setAge:(int)age; - ...
- Some good questions
(一)#include <stdio.h>#include <stdlib.h>void getmemory(char *p){ p=(char *) malloc(100); ...
- 编程策略类note
2016-1-15 LOG LOG最重要的作用即是为程序出bug时调试提供思路, 一个自定义的log,需要有几个要素: 1. 时间,以知道哪些log是我们所需要的, 2. 标签,判断哪些log是属于哪 ...
- 游标-----内存中的一块区域,存放的是select 的结果
游标-----内存中的一块区域,存放的是select 的结果 游标用来处理从数据库中检索的多行记录(使用SELECT语句).利用游标,程序可以逐个地处理和遍历一次检索返回的整个记录集 ...
- Cortex-M3学习日志(六) -- ADC实验
上一次简单的总结了一下DAC方面的知识,好吧,这次再来总结一下ADC方面的东东.ADC即Analog-to-Digital Converter的缩写,指模/数转换器或者模拟/数字转换器.现实世界是由模 ...