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的更多相关文章

  1. Educational Codeforces Round 9 D. Longest Subsequence dp

    D. Longest Subsequence 题目连接: http://www.codeforces.com/contest/632/problem/D Description You are giv ...

  2. 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 ...

  3. Educational Codeforces Round 32 E. Maximum Subsequence

    题目链接 题意:给你两个数n,m,和一个大小为n的数组. 让你在数组找一些数使得这些数的和模m最大. 解法:考虑 dfs但是,数据范围不允许纯暴力,那考虑一下折半搜索,一个从头开始往中间搜,一个从后往 ...

  4. Educational Codeforces Round 9

    Educational Codeforces Round 9 Longest Subsequence 题目描述:给出一个序列,从中抽出若干个数,使它们的公倍数小于等于\(m\),问最多能抽出多少个数, ...

  5. Educational Codeforces Round 5

    616A - Comparing Two Long Integers    20171121 直接暴力莽就好了...没什么好说的 #include<stdlib.h> #include&l ...

  6. [Educational Codeforces Round 16]E. Generate a String

    [Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...

  7. [Educational Codeforces Round 16]D. Two Arithmetic Progressions

    [Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...

  8. [Educational Codeforces Round 16]C. Magic Odd Square

    [Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...

  9. [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 ...

随机推荐

  1. UITableViewCell在非Nib及Cell重用下设置CellStyle

    在UITableViewController(实现了UITableViewDataSource)下需要实现 - (UITableViewCell *)tableView:(UITableView *) ...

  2. Django 2.0.1 官方文档翻译: 快速安装向导 (Page5)

    快速安装向导 (Page 5) 在你使用 Django 前,你需要先安装它.我们有一个完整的安装向导,它包含所有涉及的内容,这个向导会指导你进行一个简单的.最小化的安装,当你通过浏览介绍内容的时候,这 ...

  3. ETL测试

    今天让我在休息之余给我的测试朋友介绍一个在我的测试沙龙上的需要和提升技能之一,例如ETL测试(Extract,Transform,and Load,中文名称为数据提取.转换和加载),这篇文章告诉你ET ...

  4. Java并发编程原理与实战四十:JDK8新增LongAdder详解

    传统的原子锁AtomicLong/AtomicInt虽然也可以处理大量并发情况下的计数器,但是由于使用了自旋等待,当存在大量竞争时,会存在大量自旋等待,而导致CPU浪费,而有效计算很少,降低了计算效率 ...

  5. 15个超级实用的jQuery插件

    jQuery是一个可订制的.轻量级的前端开发框架,它会让你的前端开发拥有无限的可能性.它会在敏捷Web开发中帮你做很多事情,比如简化HTML文档的解析.事件处理.动画效果和Ajax交互.实践上jQue ...

  6. 【leetcode 简单】 第五十七题 删除链表中的节点

    删除链表中等于给定值 val 的所有节点. 示例: 输入: 1->2->6->3->4->5->6, val = 6 输出: 1->2->3->4 ...

  7. Css之备忘录~

    1.background-size:contain/cover 两者的作用都是一样,一般用于设置小图标作为背景图,两者的区别是: Contain:不会失真     cover:会失真 2.a标签里面如 ...

  8. [转]google gflags 库完全使用

    简单介绍 gflags 是 google 开源的用于处理命令行参数的项目. 安装编译 项目主页:gflags ➜ ~ git clone https://github.com/gflags/gflag ...

  9. mac 升级10.12 php debug 环境 跑不起的解决 解决方案

    1:  mac 升级后发现 php从原来的5.5  升级为 5.6 了...   所以以前 php.ini 里面的配置全部都没有了. mac 给我们做了备份2:  没办法只能升级php对应的插件到5. ...

  10. docker stack 部署容器监控方案(cAdvisor、Prometheus、Grafana)

    =============================================== 2018/7/8_第1次修改                       ccb_warlock === ...