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\)头部到最 ...
随机推荐
- Forsaken喜欢数论
链接:https://ac.nowcoder.com/acm/contest/1221/A来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 524288K,其他语言1048 ...
- jquery html select 清空保留第一项
<select id="a"> <option>1</option> <option>2</option> <op ...
- numpy-数据格式之 int 与 uint
概念 整型分为 有符号整型 和 无符号整型,其区别在于 无符号整型 可以存放的正数范围 比 有符号整型 大一倍,因为 有符号整型 将最高位存储符号,而 无符号整型 全部存储数字 # 1 111000 ...
- unittest装饰器:只执行一次方法
@classmethod def setUpClass(cls): print "start!" @classmethod def tearDownCla ...
- EF部分字段修改 自动忽略为null字段
传入一个实体 student(){id = 1,name = "测试" age = null,sex = null} 下面 是修改的方法 public async Task Edi ...
- 2019-11-29-dotnet-core-输出调试信息到-DebugView-软件
title author date CreateTime categories dotnet core 输出调试信息到 DebugView 软件 lindexi 2019-11-29 10:14:3 ...
- VMware虚拟机中CentOS/redhat设置固定IP
你的笔记本中的VMware中redhat或centOS系统,如果想在上面建站,而又如果你需要在家里和公司都能访问该站(至少希望你自己的笔记本能访问),那么就需要将虚拟机IP设置为固定IP了.以下介绍两 ...
- docker 安装与使用的相关问题
Error response from daemon: i/o timeout $ sudo docker search centos Error response from daemon: Get ...
- 010-监控windows主机
1)下载windows的zabbix_agent下载地址:https://www.zabbix.com/download 下载客户端并解压到指定目录D:\zabbix,解压后有两个目录:bin和con ...
- PHP 优化之php -fpm 进程
一,php-fpm的启动参数 1 2 3 4 5 6 7 8 9 10 11 12 13 #测试php-fpm配置 /usr/local/php/sbin/php-fpm -t /usr/local/ ...