CodeForces 632D Longest Subsequence
暴力。
虽然$a[i]$最大有${10^9}$,但是$m$最大只有${10^6}$,因此可以考虑暴力。
记$cnt[i]$表示数字$i$有$cnt[i]$个,记$p[i]$表示以$i$为倍数的情况下,最多能选出多少个数字。
$p[i]$可以暴力计算出来,最后就是找到$p[i]$最大的$i$,然后输出答案。
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c=getchar(); x=;
while(!isdigit(c)) c=getchar();
while(isdigit(c)) {x=x*+c-''; c=getchar();}
} const int maxn=;
int n,m,a[maxn],cnt[maxn],p[maxn];
vector<int>v; int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++) scanf("%d",&a[i]);
for(int i=;i<=n;i++)
{
if(a[i]>m) continue;
cnt[a[i]]++;
} for(int i=;i<=;i++)
for(int j=i;j<=m;j=j+i)
p[j]=p[j]+cnt[i]; int mx=; for(int i=;i<=m;i++) mx=max(mx,p[i]);
int ans; for(int i=m;i>=;i--) if(p[i]==mx) ans=i;
if(mx==) ans=;
for(int i=;i<=n;i++) if(ans%a[i]==) v.push_back(i);
printf("%d %d\n",ans,v.size());
for(int i=;i<v.size();i++) printf("%d ",v[i]);
printf("\n"); 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 筛法
题目链接 记录小于等于m的数出现的次数, 然后从后往前筛, 具体看代码. #include <iostream> #include <vector> #include < ...
- 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 ...
- D. Longest Subsequence
D. Longest Subsequence time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- CF632D 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 ...
随机推荐
- 实例学习SSIS(四)--使用日志记录和错误流重定向
原文:实例学习SSIS(四)--使用日志记录和错误流重定向 导读: 实例学习SSIS(一)--制作一个简单的ETL包 实例学习SSIS(二)--使用迭代 实例学习SSIS(三)--使用包配置 实例学习 ...
- C#如何将Build成功的程序集Copy到上一层目录
C#Build成功后,会把Build好的程序集放到bin\Debug的目录下,如何将目录放到特定目录 例如放到bin目录下,copy "$(TargetFileName)" &qu ...
- centOS6 php 编 imap 模
php 编 c-client imap 客户.下载 http://www.washington.edu/imap/mirrors.html 第一步,编 c-client 官方文档说究竟有点坑,编译报错 ...
- .net图片快速去底(去除白色背景)
public System.Drawing.Bitmap KnockOutGzf(String path) { System.Drawing.Image image = System.Drawing. ...
- 利用sqlclr实现数据库服务器端数据加密解密
在公司中一同事用sqlclr写数据迁移自动化执行脚本,发现他在执行脚本时对数据进行了加密. 个人觉得利用sqlclr对数据进行加密是一个解决数据网络安全传输的不错的方案. 以下是一个小的案例: --- ...
- Effective C++(15) 在资源管理类中提供对原始资源的访问
问题聚焦: 资源管理类是为了对抗资源泄露. 如果一些函数需要访问原始资源,资源管理类应该怎么做呢? 关于资源管理的概念总是显得那么的高大上,其实只是抽象一点. 下面用 ...
- 重构 ORM 中的 Sql 生成
Rafy 领域实体框架设计 - 重构 ORM 中的 Sql 生成 前言 Rafy 领域实体框架作为一个使用领域驱动设计作为指导思想的开发框架,必然要处理领域实体到数据库表之间的映射,即包含了 OR ...
- Setting up Ubuntu in CoLinux–changing local/keyboard to be English
Today i installed the CoLinux with Ubuntu package, but the default locale setting of the system is G ...
- android 4.2 源码在64位Ubuntu编译
1.获取Android源代码 Android官网给出了从网上下载源代码的方法,具体流程如下网址所示:http://source.android.com/source/downloading.html ...
- Spring Data Rest 支持Put请求
最近在用 Spring Data Rest 写WebApi 遇到Put请求后报415 Mieda Type 的错误,GG了下 找到个解决办法,下面是针对Put请求的过滤. 1 public class ...