北京公司建一个网站需要多少钱,wordpress删除分类目录,校园网页设计代码,app制作与推广传送门 文章目录题意#xff1a;思路#xff1a;题意#xff1a;
给你一个010101序列#xff0c;假设有一段长为lll连续的全111子串#xff0c;定义这段字串不高兴值为l∗(l1)2\frac{l*(l1)}{2}2l∗(l1)#xff0c;整个串的所有不高兴值相加为总的不高兴值。现在你可以…传送门
文章目录题意思路题意
给你一个010101序列假设有一段长为lll连续的全111子串定义这段字串不高兴值为l∗(l1)2\frac{l*(l1)}{2}2l∗(l1)整个串的所有不高兴值相加为总的不高兴值。现在你可以将某个111变成000问最少多少次操作可以使得总不高兴值≤k\le k≤k。
思路
由于比赛的时候被好几个题卡着导致分析复杂度分析错了错过接近正解的机会。 首先一上来就写了个贪心每次找最大的那个让后从中间断开。这个其实挺容易就hackhackhack掉了比如111111111111111这个序列如果按照上面的操作两次之后变成100111001110011显然比101011010110101大所以这个贪心策略是错误的但是我们还是可以从中发现一些东西。 假设我们要将lll分成xxx段那么一定是均分这一段这个东西是可以O(1)O(1)O(1)算出来的这个时候我们可以枚举每段让后再枚举将其分割成xxx段向优先队列里面加入与分割成x−1x-1x−1段差的绝对值明显这个值是递减的。之后就从优先队列中不断的拿出来将总值减去一直到sum≤ksum\le ksum≤k即可这样一定是最优的。
上面枚举分割段的复杂度是O(n)O(n)O(n)的脑子抽了一度以为能卡成O(n2)O(n^2)O(n2)的。
// Problem: Identical Day
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/17574/I
// Memory Limit: 524288 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)//#pragma GCC optimize(Ofast,no-stack-protector,unroll-loops,fast-math)
//#pragma GCC target(sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tunenative)
//#pragma GCC optimize(2)
#includecstdio
#includeiostream
#includestring
#includecstring
#includemap
#includecmath
#includecctype
#includevector
#includeset
#includequeue
#includealgorithm
#includesstream
#includectime
#includecstdlib
#includerandom
#includecassert
#define X first
#define Y second
#define L (u1)
#define R (u1|1)
#define pb push_back
#define mk make_pair
#define Mid ((tr[u].ltr[u].r)1)
#define Len(u) (tr[u].r-tr[u].l1)
#define random(a,b) ((a)rand()%((b)-(a)1))
#define db puts(---)
using namespace std;//void rd_cre() { freopen(d://dp//data.txt,w,stdout); srand(time(NULL)); }
//void rd_ac() { freopen(d://dp//data.txt,r,stdin); freopen(d://dp//AC.txt,w,stdout); }
//void rd_wa() { freopen(d://dp//data.txt,r,stdin); freopen(d://dp//WA.txt,w,stdout); }typedef long long LL;
typedef unsigned long long ULL;
typedef pairint,int PII;const int N1000010,mod1e97,INF0x3f3f3f3f;
const double eps1e-6;int n;
LL k;
int a[N];
vectorintv;LL get(int len,int x) {int restlen-x;x;LL onerest/x,rerest%x;return one*(one1)/2*(x-re)(one1)*(one2)/2*re;
}int main()
{
// ios::sync_with_stdio(false);
// cin.tie(0);cinnk;for(int i1;in;i) scanf(%1d,a[i]);LL sum0;priority_queueLLq;for(int i1;in;i) {if(a[i]0) continue;LL cnt0;while(a[i]1in) i,cnt;i--;sum1ll*cnt*(cnt1)/2;v.pb(cnt);}for(auto x:v) {LL pre1ll*x*(x1)/2;for(int i1;ix;i) {LL nowget(x,i);//coutx i nowendl;q.push(pre-now);prenow;}}int ans0;while(sumk) {sum-q.top(); q.pop();ans;}coutansendl;return 0;
}
/**/