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. 完美解决github访问速度慢

    1. 解决方法 2.解决方法 1. 修改本地hosts文件 windows系统的hosts文件的位置如下:C:\Windows\System32\drivers\etc\hosts mac/linux ...

  2. git爬坑不完全指北(一):Permission to xxx.git denied to user的解决方案

    由于对之前github账户名不太满意,又不像大神一样需要两个账号绑定.所以今天注册了新账号,想把电脑绑定到新账号上,结果就踩坑了……报错如标题. 在网上按照这个题目可以搜索出一大堆的解决方案,但都是一 ...

  3. [洛谷P3158] [CQOI2011]放棋子

    洛谷题目链接:[CQOI2011]放棋子 题目描述 在一个m行n列的棋盘里放一些彩色的棋子,使得每个格子最多放一个棋子,且不同 颜色的棋子不能在同一行或者同一列.有多少祌方法?例如,n=m=3,有两个 ...

  4. OAuth2:Authorization Flows

    Ref:http://www.dannysite.com/blog/176/ OAuth2.0协议定义了用于获得授权的四种主要授权类型. 1. Client Credentials 一种基于APP的密 ...

  5. 回调函数之基本的Promise

    在 JavaScript 中,所有的代码都是单线程的,所谓的回调函数就是为了处理一些异步的操作.而多层的回调函数嵌套是一种比较古老的处理方式,这种代码的弊端显而易见,结构混乱.代码冗余,而 Promi ...

  6. [转载]Require.js Example – Setup Time 2 Minutes

    http://www.sitepoint.com/require-js-setup-time-2-minutes/ Setup Require.js in just 2 minutes. or dow ...

  7. 05.UIDynamic

    CHENYILONG Blog 05.UIDynamic Fullscreen © chenyilong. Powered by Postach.io Blog

  8. phpcms数据结构

    v9_admin 管理员表 v9_admin_panel 快捷面板 v9_admin_role 角色表 v9_admin_role_priv 管理员权限表 v9_announce 公告表 v9_att ...

  9. DockerFile指令集

     FROM            语法:FROM <image>[:<tag>]         解释:设置要制作的镜像基于哪个镜像,FROM指令必须是整个Dockerfile ...

  10. springCloud全实战超详细代码demo+笔记

    码云: https://gitee.com/houzheng1216/springcloud