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 ...
随机推荐
- TCP协议三次握手过程分析
TCP(Transmission Control Protocol) 传输控制协议 TCP是主机对主机层的传输控制协议,提供可靠的连接服务,采用三次握手确认建立一个连接: 位码即tcp标志位,有6种标 ...
- C#去掉字符串中的汉字
string str = "测试一下ilove中国so结束"; Regex reg = new Regex(@"[\u4e00-\u9fa5]"); Label ...
- svn代码版本管理
1.0开发,做dev1.0的branch此时的目录结构svn://proj/ +trunk/ (不负担开发任务) +branches/ ...
- php simple_html_dom 一个iconv错误引起解析中断的问题,貌似内存溢出
环境: $pageNum = 8; for ($i = 1; $i < $pageNum; $i++) { $html = new simple_html_dom(); $host = 'htt ...
- Android ORM SQL Top 5
If you are developing an Android application, you will likely need to store data somewhere. You may ...
- ScrollView属性fillViewport解决android布局不能撑满全屏的问题
转:http://blog.sina.com.cn/s/blog_6cf2ea6a0102v61f.html 开发项目中遇到一个问题,布局高度在某些国产酷派小屏幕手机上高度不够全部显示,于是使用了Sc ...
- Linux LVM硬盘管理及LVM分区扩容
LVM磁盘管理 一.LVM简介... 1 二. LVM基本术语... 2 三. 安装LVM... 3 四. 创建和管理LVM... 4 2. 创建PV.. 6 3. 创建VG.. 7 4. 创建LV. ...
- 利用指针突破C++编译器的防线
C++ 面向对象的一大特性就是封装,使用不同的访问控制符来控制外接对其的访问权限.比如: class A { public: A(): i(){} void print(){ cout << ...
- 在 Windows Azure 虚拟机中如何备份和还原 Windows 系统磁盘
备份和还原对于操作真实的系统来说至关重要.对于 Windows Azure 虚拟机环境中的 Windows Server,可以根据自身的需求选择多种不同的工具或将这些工具结合使用来实现备份.下面将对这 ...
- iOS6 旋转
iOS 6的rotation改变了很多.先来看看官方的描述 http://www.bgr.com/2012/08/06/ios-6-beta-4-change-log-now-available/ ...