Codeforces Round #629 (Div. 3) F. Make k Equal(思维题-枚举+尺取+贪心)

HPE磁盘阵列管理04——MSA事件 本文介绍了HPE MSA存储系统的事件处理机制,重点分析了常见磁盘故障事件及其解决方案。文章首先定义了MSA事件的五个严重级别(严重、错误、警告、信息和解决),然后详细列举了多个典型事件案例(如事件1、3、6、8、172等),包括每种事件的触发条件、对系统的影响以及具体修复步骤。针对磁盘故障场景,文章提供了更换磁盘、重建磁盘组、取消隔离等操作建议,并强调应及时配置备用磁盘以降低数据风险。最后指出更详细的事件说明可参考《MSA事件描述参考指南》,并提供了HPE官方手册下载链接。全文为技术人员处理MSA存储故障 阅读详情

题目

给一个长度为n(n<=2e5)的数组a[](ai<=1e9)和一个数k(k<=n),

一次移动中,你可以选择以下两个操作中的一个,

①选择当前数组中最小的元素x,令x=x+1

②选择当前数组中最大的元素y,令y=y-1

求最小次数,使得a[]中有至少k个元素相等

思路来源

PinkRabbit兔队的讲解 

https://www.bilibili.com/video/BV1Nz411b7ii

题解

此题的样例比较具有提示性,提示该值既可能是从两边凑的,也可能只是从一边凑的

思路还算比较清晰,主要是贪心的思想,分几种情况讨论,得到最优解

 

首先特判出现次数已经>=k的情形,否则把值按出现次数归一下类

如果最终解可以是一个没出现过的值,说明有一段值的操作次数均为最小,总可以移动使之与某个端点重合

 

枚举最终值ai的位置i,最优解必是以下情况中的其一

①把小于ai的所有值先升到ai-1,然后取ai还需的个数

②把大于ai的所有值先降到ai+1,然后取ai还需的个数

③把小于ai的所有值先升到ai-1,把大于ai的所有值先降到ai+1,然后取ai还需的个数

代码

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef double db; 
#define fi first
#define se second 
#define pb push_back
#define vi vector<int>
#define SZ(x) (int)(x.size())
#define sci(x) scanf("%d",&(x))
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
ll modpow(ll x,ll n,ll mod){ll res=1;for(;n;n>>=1,x=x*x%mod)if(n&1)res=res*x%mod;return res;} 
const db eps=1e-8,PI=acos(-1.0);
const int N=2e5+10,M=1e6+10,INF=0x3f3f3f3f,mod=1e9+7;//998244353
int n,k,a[N],id;
ll ans[N],v[N],c[N];
int main(){
	int T=1;
//	sci(T); 
	rep(ca,1,T){
		sci(n),sci(k);
		rep(i,1,n){
			sci(a[i]);
		}
		sort(a+1,a+n+1);
		map<int,int>mp;
		rep(i,1,n){
			mp[a[i]]++;
			if(mp[a[i]]>=k)return 0*puts("0");
		}
		for(auto &x:mp){
			id++;
			v[id]=x.fi;
			c[id]=x.se;
		}
		ll now=0,sum=0;//now个数 和为sum 
		rep(i,1,id){
			ans[i]+=(v[i]-1)*now-sum;//左侧都升到v-1 
			sum+=v[i]*c[i];
			now+=c[i];
		}
		now=0;sum=0; 
		per(i,id,1){
			ans[i]+=sum-(v[i]+1)*now;//右侧都降到v+1 
			sum+=v[i]*c[i];
			now+=c[i];
		} 
		rep(i,1,id){//最后k-c[i]个数从两边都取 
			ans[i]+=k-c[i];
		}
		ll ans1=0,ans2=0;
		int pos=k;
		while(pos+1<=n&&a[pos+1]==a[pos])pos++; 
		rep(i,1,pos){//必加到v-1 先都加到v 再退回去一部分 
			ans1+=a[pos]-a[i];
		}
		ans1-=pos-k;
		pos=n+1-k;
		while(pos-1>=1&&a[pos-1]==a[pos])pos--;
		per(i,n,pos){
			ans2+=a[i]-a[pos];
		}
		ans2-=(n+1-pos)-k;
//		printf("ans1:%lld ans2:%lld\n",ans1,ans2);
		printf("%lld\n",min(*min_element(ans+1,ans+id+1),min(ans1,ans2)));
	}
	return 0;
}

 

Vue集成飞书前端JSSDK 文章目录前言<1>飞书前端JSSDK<2>使用步骤1.将JSSDK引入到VUE2.读入数据总结 前言 公司需要使用飞书软件,所以转战飞书开发,也是对新知识的探索与研究,飞书SDK也一直都在更新,路虽远,行必达。 <1>飞书前端JSSDK 1、官网地址:https://open.feishu.cn/document/uYjL24iN/uITO4IjLykDOy4iM5gjM 2、当前使用的飞书前端JSSDk的版本:1.5.4 <!-- 在html文档中 --&gt 阅读详情

相关推荐

微纳加工技术中的自对准硅化物(Silicide)工艺:关键步骤与应用场景解析

本文深入解析了微纳加工技术中的自对准硅化物(Silicide)工艺,详细介绍了其关键步骤与应用场景。从表面清洁、金属沉积到两步退火法,全面拆解工艺全流程,并探讨了不同技术节点下的工艺演进。文章还提供了实际应用中的问题排查方法和新兴技术对Silicide工艺的挑战,为芯片制造领域的工程师提供了实用参考。

weixin_30613727的博客 439

2018/8/10 部分枚举(类似尺取)

I - Distant Galaxy UVALive - 3695 题意:n个点,找出一个矩形,使其边界上包含尽量多的点。 思路:1.部分枚举 -> 枚举上下界(将n个点的纵坐标单独排序)。 2.枚举n个点 -> 枚举k条竖线(按照横坐标排序)。 3.ans = max{ lef[ i ] - lef[ j ] + on...

weixin_33736048的博客 141

【数据结构】面试题整理 共36题

链表是一种常见的数据结构,它由一系列节点组成,每个节点包含数据和一个指向下一个节点的指针。与数组不同,链表中的元素在内存中不必是连续存储的,这使得链表在插入和删除操作时非常高效。单向链表(Singly Linked List):每个节点只包含一个指向下一个节点的指针。双向链表(Doubly Linked List):每个节点包含两个指针,一个指向下一个节点,一个指向前一个节点。循环链表(Circular Linked List):链表的最后一个节点指向第一个节点,形成一个环。

weixin_44329069的博客 7216

CodeForces - 1328F Make k Equal(模拟)

题目链接:点击查看 题目大意:给出一个数列 a ,现在有两种操作: 找到一个最小值,使其值加一 找到一个最大值,使其值减一 注意这里找到一个最值进行的操作,是针对最值不唯一的情况,题目问至少需要进行多少次操作,可以使得某个数字出现的次数大于等于 k 次 题目分析:一道不知道为什么放在F题的F题。。因为E题卡了半个小时最后还没解决掉,还剩十分钟结束比赛的时候看到群友说F题是模拟,抓紧时间去读...

Falcon的博客 749

PotPlayer播放4K HDR电影时,如何正确设置LAV解码器与MadVR渲染器避免色彩失真?

本文详细介绍了如何在PotPlayer中正确配置LAV解码器与MadVR渲染器,以解决播放4K HDR电影时的色彩失真问题。从组件安装、参数设置到显卡协同配置,提供了一套完整的端到端解决方案,帮助影音爱好者获得最佳的视觉体验。

weixin_28732953的博客 453

AI 技术新手入门与实战指南

仅仅能对话还不够,实际应用中,我们往往需要让 AI 处理特定的业务数据。比如,从日志文件中提取错误码,或者将非结构化的用户反馈整理成 JSON 格式。这时候,自定义输入和严格的结果验证就显得尤为重要。假设我们需要让 AI 分析一段服务器日志,并只返回错误的级别和简述。请分析以下日志片段,提取所有 ERROR 级别的信息。要求输出格式为 JSON 列表,包含 'timestamp' 和 'message' 两个字段。不要输出任何多余的解释文字。日志内容: {

2600_94936330的博客 2682

Make k Equal CodeForces - 1328F(贪心+思维)

You are given the array a consisting of n elements and the integer k≤n. You want to obtain at least k equal elements in the array a. In one move, you can make one of the following two operations: Take...

starlet_kiss的博客 563

Vitis HLS 学习指南与实践教程

Vitis HLS 学习指南与实践教程摘要:本文系统介绍了AMD Vitis HLS工具及其应用。HLS技术将C/C++代码自动转换为硬件描述语言,显著提升FPGA开发效率(5-10倍)。文章对比了HLS与传统RTL设计的优势,包括抽象级别高、开发周期短、代码重用性强等特点。详细讲解了Vitis HLS工具链的核心功能,包括支持的C/C++特性(如任意精度数据类型)、开发流程(项目创建-代码编写-仿真-综合)以及关键优化技术(流水线、循环展开、数组分割等编译指示)。通过具体代码示例展示了HLS设计方法,为F

weixin_44707118的博客 1407

Codeforces Round #629 (Div. 3) F. Make k Equal(思维/前后缀处理)

题目链接 1.参考了此dl的博客,首先证明选择的数一定在序列内:现在有两个数a,b(a<b),a的数量是x个,b的数量是y个,现在在a-b之间选取一个数c,假定最后答案就是c,那么花费为(c-a)*x + (b-c)*y,选取c=a或者c=b时花费为(b-a)*min(x,y),显然(b-a)*min(x,y)≤(c-a)*x + (b-c)*y。那么最终答案一定是原数组存在的数 2.那...

Happig的博客 230

开发具有情感分析能力的AI Agent

本文将深入探讨开发具有情感分析能力的AI Agent的各个方面。我们将首先介绍情感分析的基础知识,包括定义、背景和应用领域。接着,我们将详细讲解情感分析的核心概念、数据处理方法和算法原理。随后,文章将展示如何设计情感分析系统架构,并进行项目实战,包括环境安装、源代码实现和案例分析。最后,我们将总结最佳实践和注意事项,为读者提供进一步学习的资源。情感分析(Sentiment Analysis),也称为意见挖掘,是自然语言处理(NLP)的一个分支。

SuperAGI2025 1149

AI驱动的材料科学:从分子设计到性能预测

AI驱动的材料科学:从分子设计到性能预测 关键词: 材料科学 人工智能 分子设计 性能预测 机器学习 深度学习 摘要:

AI天才研究院 2190

Codeforces Round #629 (Div. 3) F. Make k Equal (技巧暴力,类前缀和,思维,数学)

F. Make k Equal time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given the arrayaaconsisting ofnnelements and the inte...

菱形继承 557

重回童年的经典系列☀️|【炸弹人小游戏】制作过程+解析 | 收藏起来跟曾经的小伙伴一起梦回童年!

Unity,小游戏开发。 本篇文章对童年经典小游戏——炸弹超人进行制作和解析。不知道有没有勾起你童年的回忆呢!快来和我一起制作这个童年经典的小游戏吧! 敬请品尝!

努力前行,总会成为自己心中的那道光 13万+

Codeforces Round #629 (Div. 3) F. Make k Equal (n个数中找k个相同的数)

前言 这道题让我做了一天,其实也不是太难,就是写代码的时候特别的绕,而且状态也不太好,先是坐着写,其次躺着写,后来趴着写…代码写的乱七八糟,重写了好几次,又是“溢出”又是“答案错误”,就这样一道题干了一天。 链接 https://codeforces.com/problemset/problem/1328/F 题意 n个数,每次只能操作一个数,操作方案有两种,“最大值-1”或者“最小值+1”,最...

AIRBOYONE的博客 489

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain&#39;s apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath(&#39;DeepLearnToolbox&#39;));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand(&#39;state&#39;,0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = &#39;sigm&#39;;%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, &#39;Too big error&#39;);```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, &#39;Too big error&#39;);```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

【杭电OJ】4007 - Dave(枚举,尺取)

题目链接 给出n的点,和一个边长L,求在一个边长为L的正方形内最多能出现多少个点。 枚举所有点,在xi-xi+L通过尺取法求出最大值。 AC代码: #include&lt;bits/stdc++.h&gt; using namespace std; int n,L; struct node{ int x,y; friend bool operator &lt;(con...

Dicer_的博客 221

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

Codeforces Round #629 (Div. 3) F. Make k Equal

讲解:https://www.cnblogs.com/YangKun-/p/12618922.html #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #define ll long long using namespace std; const ll...

weixin_45113721的博客 168

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

Codeforces Round #629 (Div. 3) F. Make k Equal 思维

题目链接:https://codeforces.com/contest/1328/problem/F 题意:给你n个数字的序列,每次你可以将最大的数减一,最小的数加一,问最少多少次操作后有k个相等的数 思路:例如对于a[i], 我们需要将前面的改成a[i] - 1, 将后面的改成a[i] + 1, 所以我们将数组排序后 用map分别记录一下某个值第一次出现和最后一次出现的位置,然后On 遍历对于每...

独钓门前月 650

Codeforces Round #629 (Div. 3)F. Make k Equal

F. Make k Equal time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given the arrayaaconsisting ofnnelements and the inte...

微微风簇浪,散作满河星 791

2018 Benelux Algorithm Programming Contest (BAPC 18) G-Game Night(滚动)

题意 给一个只含ABC的字符串, 要求把字符串的A放在一起B放在一起C放在一起, 问最少有多少个字母需要被移动位置。 思路来源 翼神 题解 就是一波暴力啊,和秦皇岛那个字符串暴力题很像。 全排列ABC、ACB、BCA、BAC、CAB、CBA六种, 考虑是圆串,所以可简化为ABC、ACB两种, 预处理两个串,然后与原串暴力匹配即可, 原串也是圆串,所以将其重复一遍展成线...

小衣同学的博客 1317

Codeforces Round 948 (Div. 2) E. Tensor(思维题-交互)

(6)否则,记las的两个父亲为f1、f2(也就是上图的点6、点7),如果能往f1后面续,就往f1后面续,否则往f2后面续。新来的点3,可以接在点4后,也可以接在点5后,也可以接在点6后,也可以接在点7后,因为在链中间的点后面续新的点,都可以看成是在交点后面续新的点,不影响两条链的性质。而此时应该是10->9->6->3->2,另一条链8->7->5->4->1。而这种情况的出现,说明前面有一个只询问了1次的点,也就是在点5下面的点4,可以发现,在点5形成Y字型,后接点4之后,新来的点3并没有续到点4上,

小衣同学的博客 1226

AtCoder Beginner Contest 278 G.Generalized Subtraction Game(思维题/博弈 multi-sg)

AtCoder Beginner Contest 278 G.Generalized Subtraction Game(思维题/博弈 multi-sg)

小衣同学的博客 1174

Codeforces Round 975 (Div. 1) D. Max Plus Min Plus Size(思维题 并查集/动态dp 线段树维护状态合并)

f[x][i][j][k]表示线段树的x节点,最大值有没有取到,左端点有没有选,右端点有没有选,如果最大值被包含在1 3 5里显然取1 3 5,否则换成2 4一定能取到最大值,是不劣的,对于最小值固定的话,对于1 2 3 4 5的连续段,要么贪心地取1 3 5,要么取2 4。如果存在一个连续段,使得选这个连续段中较多的那一半(奇数唯一,偶数均可)能取到最大值。则答案不需要减1,否则为了取到最大值需要反选,将答案减1。hhoppitree代码 + 官方题解。注意到最大值一定会被取到,

小衣同学的博客 1129

The 2024 ICPC Kunming Invitational Contest K. Permutation(交互 期望)

维护两个vector L、R,代表下一步要在[l,mid]和[mid+1,r]分治的vector。这样del里的元素,在并查集上找到其祖先时,可以用to数组确定其应该被放进L还是R。每次将x random_shuffle后,取出vector尾部的两个u、v,和已经被询问出来的元素再一起询问一次,就能确定出这个元素该放进L还是R。分治,假设当前解决到[l,r],要递归的vector是x,期望次数是6000的,实际跑得飞快,也没被卡掉。只剩一个元素时,L或R一定已经有元素,首先特判n=1的情况,其实也不用问。

小衣同学的博客 1065

Codeforces Round 973 (Div. 2) F1. Game in Tree (Easy Version)(思维题 博弈)

如果能走旁边的链(也就是当前点,刨去标记链以外的子树中最长的链),使得对面走剩余的连通块无法比你大,就走旁边的链,并宣告获胜。维护实际是一个区间最值,可以用set或者st表。两个人的策略是一样的,把1到u的路径标记,否则沿着标记链,朝对面的方向走一步。

小衣同学的博客 1041

Codeforces Round 803 (Div. 2) E. PermutationForces II(思维题 位置序列)

类似地,posb[6]和posb[7]都可以用到[1,7]里的可用位置,分别对应ans*=2和ans*=1。posb[3]可以用到[1,7]里的可用位置,即[1 4 2 6 7 3 5]里的[4 7 3 5],posb[1]只能用到[1,5]里的可用位置,即[1 4 2 6 7]里的[4 7],ans*=2。所以,合法的条件是,对于b[i]不为-1的位置,要求a[i]的值不能超过b[i]+s。比如,在为posb[1]=-1这个未确定的位置赋值的时候,posb[1]的值,

小衣同学的博客 1034

Gym - 101291L Three Square(模拟)

题意 给你三个矩形,问是否能拼成一个正方形 题解 首先,面积和得是一个完全平方数q(不是就说明不能),记q=r*r 把边长为r的那个矩形挑出来(不存在就说明不能),然后把剩下两个暴力合并 合并之后,再把合并出来的和挑出来的暴力合并, 如果能合并成一个正方形就能,否则就不能…… 心得 这种没什么算法没什么套路的题最讨厌了…… 之前一直wa在12,CF的gym也看不了样例,很迷…...

小衣同学的博客 998
上一篇: poj1390 Blocks(经典区间dp/消除问题)
下一篇: hdu4283 You Are the One(区间DP/2012 ACM/ICPC Asia Regional Tianjin Online)
小衣同学
博客等级 码龄9年 1444粉丝 995原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小衣同学

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值