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\)头部到最 ...
随机推荐
- WebMagic 抓取图片并保存至本地
1.近期接触到java 爬虫,开源的爬虫框架有很多,其中WebMagic 是国产的,文档也是中文的,网上资料很多,便于学习,功能强大,可以在很短时间内实现一个简单的网络爬虫.具体可参考官网 http: ...
- javaSE温习一&二
这是一个简单的笔记 涉及到常量.变量:流程控制语句.数组:类与对象.封装.构造方法:Scanner类.Random类.Arraylist类: 1.pubic class static void 2. ...
- noip2013day1-货车运输
题目描述 \(A\)国有\(n\)座城市,编号从 \(1\)到\(n\),城市之间有 \(m\) 条双向道路.每一条道路对车辆都有重量限制,简称限重.现在有 \(q\) 辆货车在运输货物, 司机们想知 ...
- ubuntu18下lamp虚拟路劲配置
一.配置二级域名 修改hosts文件,模拟dns解析. 位置:/etc/hosts 添加 127.0.0.1 myweb.service.com 二.创建项目目录 apache默认目录是/var m ...
- spring boot 是如何加载jackson的?
Spring Boot 自动引入jackson: 通过:Spring-Boot-starter-web Jackson自动配置 这里的configurations是读取的这里: 通过反射加载Jacks ...
- Git小结---So far.......
基本的: 1. 在配置了SSH Key的情况下,clone项目时使用:git clone git@github.com/用户名/仓库名.git 使用这种方式而不使用https的方式的好处在于,在pu ...
- laravel 添加筛选方式
protected function grid() { return Admin::grid(Client::class, function (Grid $grid) { $grid->id(' ...
- js实现倒计时(分:秒)
上代码: //倒计时start 需要传入的参数为秒数,此方法倒计时结束后会自动刷新页面 function resetTime(timetamp){ var timer=null; var t=time ...
- [转]实际项目中如何使用Git做分支管理 (A successful Git branching model)
来自 https://nvie.com/posts/a-successful-git-branching-model/ In this post I present the development m ...
- java高并发核心要点|系列4|CPU内存指令重排序(Memory Reordering)
今天,我们来学习另一个重要的概念. CPU内存指令重排序(Memory Reordering) 什么叫重排序? 重排序的背景 我们知道现代CPU的主频越来越高,与cache的交互次数也越来越多.当CP ...