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\)头部到最 ...
随机推荐
- Sqlserver限制用户访问指定数据库
USE master CREATE LOGIN test --要创建的用户名 WITH PASSWORD = '123456', --密码 DEFAULT_DATABASE = DBTest, --指 ...
- 洛谷 P1879 玉米田Corn Fields 题解
题面 一道思维难度不大的状态压缩,也并不卡常,但细节处理要格外注意: f[i][j]表示前i行最后一行状态是j的方案数 #include <bits/stdc++.h> #define p ...
- 如何输出opencv编译信息
本文链接:https://mangoroom.cn/opencv/how-to-print-compile-info-of-opencv.html opencv提供了一个函数,利用这个函数可以输出当前 ...
- MUI沉浸式代码
var ben_immer = (function() { var immersed = 0; var ms = (/Html5Plus\/.+\s\(.*(Immersed\/(\d+\.?\d*) ...
- 日语能力考试N2级核心词汇必备—副词
日语能力考试N2级核心词汇必备—副词 ABAB型的副词 あちこ ...
- 85. Maximal Rectangle (JAVA)
Given n non-negative integers representing the histogram's bar height where the width of each bar is ...
- Assets.xcassets的使用
先介绍下Asset Catalog,Asset Catalog是Xcode5引入的一个新的图片管理方式,有几个好处: 1.自动管理图片,如@1x,@2x图片,使用的时候使用Asset 名字即可 2.管 ...
- 当有多个相同的DIV时,我怎么判断我点击的是哪个
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- oracle数据库应用总结
1------->>>>>>>>>>>>>>>>>>>>>>> ...
- Codeforces 980 并查集/模拟贪心最小字典序 找规律/数去除完全平方因子 逆思维倍增预处理祖先标记点
A /*Huyyt*/ #include<bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) #define pb push_bac ...