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\)头部到最 ...
随机推荐
- Websocket --(3)实现
今天介绍另外一种websocket实现方式,结合了spring MVC,并完善了第二节所提到做一个简单的登录认证用来识别用户的名称.界面继续沿用第二节的布局样式,同时增加上线和下线功能. 参考了 ht ...
- HDU 6175 算术
题目大意 求 $\sum_{i = 1}^{n} \sum_{j = 1}^{m} \mu(\lcm(i, j))$ . $ 1 \le n, m \le 10^6 $ . 分析 不妨设 $ n \l ...
- java方法形参是引用类型
public void 方法名(Student s) 这里形参需要的是该类的对象或者子类对象(父类引用子类对象). 1.若为普通类:则可传入该类的实例对象即可,方法名(new Student()): ...
- python 3.x报错:No module named 'cookielib'或No module named 'urllib2'
1. ModuleNotFoundError: No module named 'cookielib' Python3中,import cookielib改成 import http.coo ...
- 解决 SQLPlus无法登陆oracle,PLSql可以登陆,报错ORA-12560
使用Oracle 11g 64位服务器,安装64位.32位客户端,出现SQLPlus无法连接数据库,PLSql可以连接问题. 网上查了很多,都不能解决问题,在下面提供一种. 环境变量 右击计算机属性- ...
- 多层 iframe 嵌套 js 方法调用
一下午一个这破问题,浪费了不少时间,怎么也实现不了我的上上级iframe 刷新.NND. 实现了,记录一下下吧: window.parent.parent.document.getElementByI ...
- varchar nvarchar 设计长度时 设计成 (2^n)-1 的好处
这个问题想说已久就是博没共享出来 首先提出个问题 CREATE TABLE `test` ( `a` ) DEFAULT NULL, ) ENGINE=InnoDB DEFAULT CHARSET=u ...
- com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value 'PDT' is.......
SpringBoot连接数据库的时候报错 java.sql.SQLException: The server time zone value 'PDT' is unrecognized or repr ...
- Linux查看及设置系统时区
一.什么是时区呢? 关于时区的概念,其实初中地理课已经涉及,很多人都多少了解一些,可能只是细节搞不太清楚.为什么会将地球分为不同时区呢?因为地球总是自西向东自转,东边总比西边先看到太阳,东边的时间也总 ...
- nodejs fs copy本地文件src dst
1. // fs.writeFileSync(pathNewFile, fs.readFileSync(fileName)); 2. fs.createReadStream(fileName).p ...