D2. Equalizing by Division (hard version)

涉及下标运算一定要注意下标是否越界!!!

思路,暴力判断以每个数字为到达态最小花费

#include<bits/stdc++.h>
using namespace std;
#define sc(x) scanf("%I64d",&x);
#define read(A) for(int i=1;i<=n;i++)scanf("%I64d",&A[i]);
#define int long long
#define P pair<int,int>
#define fi first
#define se second
#define endl '\n'
#define ll long long
#define maxn 200000+10
int n,m,T;
int A[maxn];
int B[];
int ch(int x,int y)
{
for(int i=;i<=y;i++){
x/=;
}
return x;
}
int Ans=1e18;
int check(int x,int t)
{
int _x=x;
if(x==)
{
int ans=;
for(int i=B[]; i<n; i++)
{
int c=A[i]; while(c)
{
ans++;
c/=;
if(ans>Ans){
return 1e18;
}
}
t++;
//cout<<t<<m<<endl;
if(t==m)
{
return ans;
}
}
}
int ans=;
int k=;
int y=;
x*=;
while(x<=&&t<m)
{
for(int i=; i<k; i++)
{
if(ch(x+i,y)!=_x)break;
if(x+i>)break;
if(x+i<=&&B[x+i]>=m-t)
{
ans+=(m-t)*y;
if(ans>Ans)return 1e18;
t=m;
return ans;
}
else
{
ans+=(B[x+i])*y;
if(ans>Ans)return 1e18;
t+=B[x+i];
} }
x*=;
y++;
k*=;
}
if(m<=t)return ans;
else
return 1e18;
}
signed main()
{
sc(n);
sc(m);
for(int i=; i<n; i++)
{
sc(A[i]);
//cout<<A[i]<<endl;
B[A[i]]++;
if(B[A[i]]>=m)
{
puts("");
return ;
}
}
sort(A,A+n);
int t=; for(int i=; i<=; i++)
{
t=check(i,B[i]);
// if(t<ans)cout<<i<<endl;
Ans=min(t,Ans);
}
cout<<Ans<<'\n'; }

D2. Equalizing by Division (hard version)的更多相关文章

  1. codeforces Equalizing by Division (easy version)

    output standard output The only difference between easy and hard versions is the number of elements ...

  2. D2. Remove the Substring (hard version)(思维 )

    D2. Remove the Substring (hard version) time limit per test 2 seconds memory limit per test 256 mega ...

  3. D2. Remove the Substring (hard version)

    D2. Remove the Substring (hard version) 给字符串s,t,保证t为s的子序列,求s删掉最长多长的子串,满足t仍为s的子序列 记录t中每个字母在s中出现的最右的位置 ...

  4. CF1213D Equalizing by Division

    easy version hard version 问题分析 直接从hard version入手.不难发现从一个数\(x\)能得到的数个数是\(O(\log x)\)的.这样总共有\(O(n\log ...

  5. Codeforces 1249 D2. Too Many Segments (hard version)

    传送门 贪心 对于第一个不合法的位置,我们显然要通过删除几个覆盖了它的区间来使这个位置合法 显然删右端点更靠右的区间是更优的,所以就考虑优先删右端点靠右的,然后再考虑下一个不合法位置 用一个 $set ...

  6. codeforces 1249 D2 Too Many Segments (hard version) 贪心+树状数组

    题意 给定n个线段,线段可以相交,第\(i\)个线段覆盖的区间为\([l_i,r_i]\),问最少删除多少个线段让覆盖每个点的线段数量小于等于k. 分析 从左往右扫每个点\(x\),若覆盖点\(x\) ...

  7. Codeforces 1213D Equalizing by Division

    cf题面 中文题意 给n个数,每次可以把其中一个数字位运算右移一位(即整除以二),问要至少操作几次才能让这n个数中有至少k个相等. 解题思路 这题还有个数据范围更小的简单版本,n和k是50,\(a_i ...

  8. Equalizing by Division

    The only difference between easy and hard versions is the number of elements in the array. You are g ...

  9. Codeforces Round #579 (Div. 3) D2. Remove the Substring (hard version) (思维,贪心)

    题意:给你一个模式串\(t\),现在要在主串\(s\)中删除多个子串,使得得到的\(s\)的子序列依然包含\(t\),问能删除的最长子串长度. 题解:首先,我们不难想到,我们可以选择\(s\)头部到最 ...

随机推荐

  1. [转帖]oracle 00600 4194 4193 问题的处理

    oracle断电重启之ORA-00600[4194] https://www.cnblogs.com/xwdreamer/p/3778383.html 部门的机器出现异常 断电导致的 错误 从网上学了 ...

  2. spring + redis 实例(一)

    这一篇主要是redis操作工具类以及基本配置文本储存 首先我们需要定义一个redisUtil去操作底层redis数据库: package com.lcc.cache.redis; import jav ...

  3. POJ - 2421 Constructing Roads(最小生成树&并查集

    There are N villages, which are numbered from 1 to N, and you should build some roads such that ever ...

  4. 洛谷 P2398 GCD SUM 题解

    题面 挺有意思的. 设f[i]表示gcd(i,j)=i的个数,g[i]表示k|gcd(i,j)的个数; g[i]=(n/i)*(n/i); g[i]=f[i]+f[2i]+f[3i]+...; 所以f ...

  5. dp入门题(数塔)

    http://acm.hdu.edu.cn/showproblem.php?pid=2084 题意: 7 3  8 8 1   0 2      7 4   4 4 5 2    6     5 在上 ...

  6. RocketMQ吐血总结

    RocketMQ吐血总结 架构 概念模型 最基本的概念模型与扩展后段概念模型 存储模型 RocketMQ吐血总结 User Guide RocketMQ是一款分布式消息中间件,最初是由阿里巴巴消息中间 ...

  7. Elasticsearch入门教程(二):Elasticsearch核心概念

    原文:Elasticsearch入门教程(二):Elasticsearch核心概念 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:ht ...

  8. 企业面试题|最常问的MySQL面试题集合(二)

    MySQL的关联查询语句 六种关联查询 交叉连接(CROSS JOIN) 内连接(INNER JOIN) 外连接(LEFT JOIN/RIGHT JOIN) 联合查询(UNION与UNION ALL) ...

  9. Android中res下anim和animator文件夹区别与总结

    1.anim文件夹 anim文件夹下存放tween animation(补间动画)和frame animation(逐帧动画) 逐帧动画: ①在animation-list中使用item定义动画的全部 ...

  10. Core Graphics绘图

    首先了解一下CGContextRef: An opaque type that represents a Quartz 2D drawing environment. Graphics Context ...