Educational Codeforces Round 9 D - Longest Subsequence
思路:枚举lcm, 每个lcm的答案只能由他的因子获得,类似素数筛搞一下。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define pii pair<int,int>
#define piii pair<int, pair<int,int> > using namespace std; const int N = 1e6 + ;
const int M = + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-; int n, m, tot, a[N], cnt[N], id[N]; vector<int> v[N]; void init() {
for(int i = ; i <= m; i++) {
for(int j = i; j <= m; j+= i) {
v[j].push_back(i);
}
}
} int main() {
scanf("%d%d", &n, &m);
for(int i = ; i <= n; i++) {
int x; scanf("%d", &x);
if(x <= m) {
id[tot] = i;
a[tot++] = x;
}
} if(tot == ) {
printf("1 0\n");
} else {
init();
for(int i = ; i < tot; i++) {
cnt[a[i]]++;
} int mx = , ans = ;
for(int i = m; i >= ; i--) {
int ret = ;
for(int t : v[i]) {
ret += cnt[t];
}
if(ret >= mx) {
mx = ret;
ans = i;
}
} printf("%d %d\n", ans, mx);
for(int i = ; i < tot; i++) {
if(ans % a[i] == ) {
printf("%d ", id[i]);
}
}
puts("");
}
return ;
}
/*
*/
Educational Codeforces Round 9 D - Longest Subsequence的更多相关文章
- Educational Codeforces Round 9 D. Longest Subsequence dp
D. Longest Subsequence 题目连接: http://www.codeforces.com/contest/632/problem/D Description You are giv ...
- Codeforces Educational Codeforces Round 5 D. Longest k-Good Segment 尺取法
D. Longest k-Good Segment 题目连接: http://www.codeforces.com/contest/616/problem/D Description The arra ...
- Educational Codeforces Round 32 E. Maximum Subsequence
题目链接 题意:给你两个数n,m,和一个大小为n的数组. 让你在数组找一些数使得这些数的和模m最大. 解法:考虑 dfs但是,数据范围不允许纯暴力,那考虑一下折半搜索,一个从头开始往中间搜,一个从后往 ...
- Educational Codeforces Round 9
Educational Codeforces Round 9 Longest Subsequence 题目描述:给出一个序列,从中抽出若干个数,使它们的公倍数小于等于\(m\),问最多能抽出多少个数, ...
- Educational Codeforces Round 5
616A - Comparing Two Long Integers 20171121 直接暴力莽就好了...没什么好说的 #include<stdlib.h> #include&l ...
- [Educational Codeforces Round 16]E. Generate a String
[Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...
- [Educational Codeforces Round 16]D. Two Arithmetic Progressions
[Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...
- [Educational Codeforces Round 16]C. Magic Odd Square
[Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...
- [Educational Codeforces Round 16]B. Optimal Point on a Line
[Educational Codeforces Round 16]B. Optimal Point on a Line 试题描述 You are given n points on a line wi ...
随机推荐
- RAC转换传统的通信
///////////////////各种机制转信号/////////////////////////////// 1.UI事件 [self.logInButton rac_signalForCont ...
- bzoj千题计划118:bzoj1028: [JSOI2007]麻将
http://www.lydsy.com/JudgeOnline/problem.php?id=1028 枚举等待牌 枚举对是哪个 判断 #include<cstdio> #include ...
- 【js学习笔记】去除省、市、区、特别行政区、自治区
不是很懂js,以前去除这些省.市.区的时候都是用的分支判断indexOf,如果!=-1则replace一次,今天看同事的代码,发现还有更简单的办法... var areaName = str.repl ...
- 【经验分享】URL链接地址最长是多少?
近期在做一个Hot Fix,其中有个界面在IE6下超链接无法打开,经查是链接地址太长,2161个字节,已经超出ie6,7的长度限制,现把发现此问题的过程分享给大家. ===过程===== 1.万恶的i ...
- 洛谷P3960 [NOIP2017] 列队
数据结构题还是挺好玩的 注意到每次只变动三个点:(x,y),(x,m),(n,m),其他地方都是整块移动. 可以开n+1个线段树,前n个存每行前m-1个人,最后一个存第m列的人. (x,y)位置的人出 ...
- msfpayload反弹shell
1.前期-- 情景就是当我们获得webshell时,我们想留下我们的后门,这个时候我们可以用到msfpayload与msfconsole结合使用 启动PostgreSQL服务:service post ...
- Java高性能并发编程——线程池
在通常情况下,我们使用线程的时候就去创建一个线程,这样实现起来非常简便,但是就会有一个问题: 如果并发的线程数量很多,并且每个线程都是执行一个时间很短的任务就结束了,这样频繁创建线程就会大大降低系统的 ...
- ETL利器Kettle实战应用解析系列二
本系列文章主要索引如下: 一.ETL利器Kettle实战应用解析系列一[Kettle使用介绍] 二.ETL利器Kettle实战应用解析系列二 [应用场景和实战DEMO下载] 三.ETL利器Kettle ...
- 2018Java开发面经(持续更新)
不要给自己挖坑!!!不要给自己挖坑!!!不要给自己挖坑!!!如果面试官只是问你了解xxx吗,如果不是很了解,就直接说不知道,不要说知道,不然面试官深问再不知道就印象很不好! 处女面送给了头条(北京)日 ...
- 001_Mac键盘图标与对应快捷按键标志汇总
Mac键盘图标与对应快捷按键 ⌘——Command () win键 ⌃ ——Control ctrl键 ⌥——Option (alt) ⇧——Shift ⇪——Caps Lock fn——功能键就是 ...