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 ...
随机推荐
- linux网卡的开启
一:文件配置网卡在开机时,自动启用 首先我们使用 ip addr查看IP信息 [root@redhat2 network-scripts]# ip addr : lo: <LOOPBACK,UP ...
- StringBuffer类和String 类的 equals 和 ==
注意: equals(Object obj)equals方法的参数是任意对象 Object类的equals方法就是用==判断的,即判断两个对象是否为同一个对象 StringBuffer类没有重写equ ...
- NOI2006 最大获利(最大权闭合子图)
codevs 1789 最大获利 2006年NOI全国竞赛 时间限制: 2 s 空间限制: 128000 KB 题目描述 Description 新的技术正冲击着手机通讯市场,对于各大运营商来 ...
- Java并发编程原理与实战十九:AQS 剖析
一.引言在JDK1.5之前,一般是靠synchronized关键字来实现线程对共享变量的互斥访问.synchronized是在字节码上加指令,依赖于底层操作系统的Mutex Lock实现.而从JDK1 ...
- 视差插件parallarx
github上的demo,自己拿来改了改. <!DOCTYPE html> <html> <head> <meta charset="UTF-8&q ...
- Spyder简述
导言 想打造轮子, 就必须要有一套完善的造轮子的工具. 我在jupyter+sciTE的组合里转来转去, 最后还是打算放弃这个组合, 因为离开了自动完成/调用提示/随时随地的访问文档帮助, 前行之路太 ...
- 动态改变swiper的属性
<script> var mySwiper = new Swiper('.swiper-container',{ autoplay : 1000, autoplayDisableOnInt ...
- 《编写高质量代码:改善JavaScript程序的188个建议》学习小记(二)
建议3:减少全局变量污染 1.把多个全局变量都追加在一个名称空间下,将显著降低与其他应用程序产生冲突的概率,应用程序也会变得更容易阅读. var My = {}; My.name = { " ...
- 【leetcode 简单】 第七十七题 单词模式
给定一种 pattern(模式) 和一个字符串 str ,判断 str 是否遵循相同的模式. 这里的遵循指完全匹配,例如, pattern 里的每个字母和字符串 str 中的每个非空单词之间存在着双向 ...
- webrtc前景如何
首先WebRTC是什么? WebRTC --- Web browsers with Real-Time Communications (RTC). WebRTC是一个免费.开放的项目.使web浏览器通 ...