【Codeforces 632D】 Longest Subsequence
【题目链接】
【算法】
设取的所有数都是k的约数,则这些数的lcm必然不大于k。
对于[1, m]中的每个数,统计a中有多少个数是它的约数即可。
【代码】
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- const ll MAXN = 1e6;
- ll i,j,tmp,num,maxx,n,m,res;
- ll a[MAXN+],sum[MAXN+],h[MAXN+];
- vector<ll> ans;
- template <typename T> inline void read(T &x) {
- ll f = ; x = ;
- char c = getchar();
- for (; !isdigit(c); c = getchar()) { if (c == '-') f = -f; }
- for (; isdigit(c); c = getchar()) x = x * + c - '';
- x *= f;
- }
- template <typename T> inline void write(T x) {
- if (x < ) { putchar('-'); x = -x; }
- if (x > ) write(x/);
- putchar(x%+'');
- }
- template <typename T> inline void writeln(T x) {
- write(x);
- puts("");
- }
- inline ll gcd(ll x,ll y) { return y == ? x : gcd(y,x%y); }
- int main() {
- read(n); read(m);
- for (i = ; i <= n; i++) {
- read(a[i]);
- if (a[i] <= m)
- ++h[a[i]];
- }
- for (i = ; i <= m; i++) {
- tmp = i;
- if (!h[i]) continue;
- for (j = tmp; j <= m; j += tmp) {
- sum[j] += h[i];
- }
- }
- for (i = ; i <= m; i++) {
- if (sum[i] > maxx) {
- maxx = sum[i];
- num = i;
- }
- }
- if (!num) {
- printf("1 0\n");
- return ;
- }
- for (i = ; i <= n; i++) {
- if (!(num % a[i]))
- ans.push_back(i);
- }
- res = a[ans[]];
- for (i = ; i < ans.size(); i++) res = res * a[ans[i]] / gcd(res,a[ans[i]]);
- write(res); putchar(' '); write(ans.size()); puts("");
- for (i = ; i < ans.size(); i++) {
- write(ans[i]);
- if (i < ans.size() - ) putchar(' ');
- }
- return ;
- }
【Codeforces 632D】 Longest Subsequence的更多相关文章
- 【29.41%】【codeforces 724D】Dense Subsequence
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【Codeforces 977F】Consecutive Subsequence
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 设f[i]表示i作为序列的最后一个数字,最长的连续序列的长度. 用f[i]和f[i-1]+1来转移即可 [代码] import java.io ...
- 【CodeForces 616D】Longest k-Good Segment
题意 n个数里,找到最长的一个连续序列使里面最多k个不同的数. 分析 尺取法,每次R++,如果第R个数未出现过,那么不同的数+1,然后这个数的出现次数+1,如果不同的数大于k了,那就要去掉第L个数,直 ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 766A】Mahmoud and Longest Uncommon Subsequence
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 750E】New Year and Old Subsequence
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【33.10%】【codeforces 604C】Alternative Thinking
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【17.07%】【codeforces 583D】Once Again...
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【32.22%】【codeforces 602B】Approximating a Constant Range
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
随机推荐
- Netty构建游戏服务器(二)--Hello World
一,准备工作 1,netty-all-4.1.5.Final.jar(官网下载) 2,eclipse 二,步骤概要 1,服务器开发 (1),创建Server类 该类是程序的主入口,有main方法,服务 ...
- HDU 5893 List wants to travel(树链剖分+线段树)
题目链接 HDU5893 $2016$年$ICPC$沈阳网络赛的$B$题.这道题其和 BZOJ2243 基本一样 那道题我也写了题解 点这里 两道题的区别就是$BZOJ$这题是点的权值,这道题是边权. ...
- @OneToMany
实体关系之@OneToMany 博客分类: hibernate & ejb SQL Order.java package com.entity; import java.io.Seriali ...
- Vue1.x 迁移 Vue2.x(项目进行不断修改)
一.$dispatch 和 $broadcast 已经被弃用. 请使用更多简明清晰的组件间通信和更好的状态管理方案,如:Vuex 这些方法的最常见用途之一是父子组件的相互通信.在这些情况下,你可以使用 ...
- Linux线上系统程序debug思路及方法
http://blog.csdn.net/wangzuxi/article/details/44766221
- 实现uitable cell中点击button设置当前cell为选中状态
- (void)buttonClick:(id)senser{ NSInteger tag = [senser tag]; NSLog(@"the button tag is % ...
- 伙伴算法与slab算法
伙伴算法: 1.将空闲页面分为m个组,第1组存储2^0个单位的内存块,,第2组存储2^1个单位的内存块,第3组存储2^2个单位的内存块,第4组存储2^3个单位的内存块,以此类推.直到m组. 2.每个组 ...
- [Adobe Analytics] Segments types
There are three types of Segmentation Hit-based Visit-based Visitor-based There are four segment con ...
- VS2013 update4+Cocos2d-x 3.7 Win8下安装方法及配置
1.安装VS 2013 update4 7个G.自己就去网上找吧,一大堆,密钥问度娘. 2.安装及配置python 2.x 这里注意,一定要下载python 3.0下面的版本号. 配置:进行环境变量配 ...
- SpringBoot学习之快速入门创建
maven构建项目 1.访问http://start.spring.io/,进入快速创建工程的主页 可参考下图所示: 2.选择构建工具Maven Project.Spring Boot版本1.3.6以 ...