D2. Equalizing by Division (hard version)
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)的更多相关文章
- codeforces Equalizing by Division (easy version)
output standard output The only difference between easy and hard versions is the number of elements ...
- D2. Remove the Substring (hard version)(思维 )
D2. Remove the Substring (hard version) time limit per test 2 seconds memory limit per test 256 mega ...
- D2. Remove the Substring (hard version)
D2. Remove the Substring (hard version) 给字符串s,t,保证t为s的子序列,求s删掉最长多长的子串,满足t仍为s的子序列 记录t中每个字母在s中出现的最右的位置 ...
- CF1213D Equalizing by Division
easy version hard version 问题分析 直接从hard version入手.不难发现从一个数\(x\)能得到的数个数是\(O(\log x)\)的.这样总共有\(O(n\log ...
- Codeforces 1249 D2. Too Many Segments (hard version)
传送门 贪心 对于第一个不合法的位置,我们显然要通过删除几个覆盖了它的区间来使这个位置合法 显然删右端点更靠右的区间是更优的,所以就考虑优先删右端点靠右的,然后再考虑下一个不合法位置 用一个 $set ...
- codeforces 1249 D2 Too Many Segments (hard version) 贪心+树状数组
题意 给定n个线段,线段可以相交,第\(i\)个线段覆盖的区间为\([l_i,r_i]\),问最少删除多少个线段让覆盖每个点的线段数量小于等于k. 分析 从左往右扫每个点\(x\),若覆盖点\(x\) ...
- Codeforces 1213D Equalizing by Division
cf题面 中文题意 给n个数,每次可以把其中一个数字位运算右移一位(即整除以二),问要至少操作几次才能让这n个数中有至少k个相等. 解题思路 这题还有个数据范围更小的简单版本,n和k是50,\(a_i ...
- Equalizing by Division
The only difference between easy and hard versions is the number of elements in the array. You are g ...
- Codeforces Round #579 (Div. 3) D2. Remove the Substring (hard version) (思维,贪心)
题意:给你一个模式串\(t\),现在要在主串\(s\)中删除多个子串,使得得到的\(s\)的子序列依然包含\(t\),问能删除的最长子串长度. 题解:首先,我们不难想到,我们可以选择\(s\)头部到最 ...
随机推荐
- DIY兼容机装苹果系统
遇到问题: 无法用变色龙引导:删除原WIN系统前隐藏分区 变色龙引导画面无法进安装界面:a,wowpc.iso版本低,换新版;b,复制EXTRA进MAC安装盘 MAC OS安装完成后重新启动卡在苹果图 ...
- mysql for update 高并发 死锁研究
mysql for update语句 https://www.cnblogs.com/jtlgb/p/8359266.html For update带来的思考 http://www.cnblo ...
- [POI2011]SMI-Garbage 题解
题面 想必各位大佬一定想到了把现在和目标值不一致的边加入到一个新建的图上: 问题就变为了在新的图上寻找有多少个欧拉回路,并输出这些路径: 我们可以用栈来记录情况,然后对于会回答稍微处理处理就好了: # ...
- C语言---程序的一般形式、数据类型、常量变量、运算符、表达式、格式化输入输出
1. 程序的一般形式 (1)注释 ① 分类:单行注释( // ): 注释一行.多行注释( /**/ ): 在这个区间内,都属于多行注释,可以换行. ② 作用:提示代码的作用,提示思路 不写注释的后 ...
- 打印输出opencv的版本信息
本文链接: https://mangoroom.cn/opencv/print-opencv-version-info.html 序 查看自己安装的opencv的版本信息的方法有两种. 方法一-查看l ...
- Layui数据表格模型
视图模型 package com.meiyou.model; import org.springframework.context.annotation.Bean; import java.io.Se ...
- sql server 符号函数sign
--SIGN(x)返回参数的符号,x的值为负.零或正时,返回结果依次为-1.0或1 示例:select SIGN(-21), SIGN(0), SIGN(21) 结果:-1 0 1
- [转载]Jupyter Notebook中自动补全代码
原文地址:https://yq.aliyun.com/articles/667928 在公众号之前的文章中,已经介绍了在Jupyter Notebook中设置主题以及输出代码文件到pdf文件中,本文来 ...
- 《一头扎进》系列之Python+Selenium自动化测试框架实战篇6 - 价值好几K的框架,呦!这个框架还真牛叉哦!!!
1. 简介 本文开始介绍如何通过unittest来管理和执行测试用例,这一篇主要是介绍unittest下addTest()方法来加载测试用例到测试套件中去.用addTest()方法来加载我们测试用例到 ...
- jsp页面中JSTL如何处理日期格式
引入fmt标签 <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%> 格 ...