首页 > 其他分享 >The Great Mixing CF788C

The Great Mixing CF788C

时间:2023-02-24 14:57:01浏览次数:48  
标签:Great int CF788C 5e5 Mixing include

从序列中找一些数,使平均数>=m,问最少取几个数》

 

  每个数 - m , 题目即求 和>=0 最少取多少数? 背包问题

 

#include <iostream>
#include<algorithm> 
#include <cstring>
#define IOS std::ios::sync_with_stdio(0)
using namespace std;
 const int M =4e6+3;
  const int D= 2e6;
  
 
 int f[M],a[M],m,n;
 
 void solve(){
 	 memset(f,63,sizeof f);
 	int i,j;
 	cin>>m>>n;
 	for(i=1;i<=n;i++) scanf("%d",&a[i]),a[i]-=m;
 	sort(a+1,a+1+n);
 	int len=unique(a+1,a+1+n)-a-1;
   
 	for(i=1;i<=len;i++){
 		f[a[i]+D]=1;
 		if(a[i]<0){
 			for(j=5e5;j>=-5e5;j--)
		 	 	 f[j+D]=min(1+f[j-a[i]+D],f[j+D]);
 		}
	 	else{
 	 		for(j=-5e5;j<=5e5;j++)
 	 			f[j+D]=min(1+f[j-a[i]+D],f[j+D]);
		}
 	}
 	
 	if(f[D]<=1e9)
		cout<< f[D] <<endl;
 	else 
 		cout<<-1<<endl;
 }
 signed main(){
     IOS;
     solve();
 }
 
 

 

标签:Great,int,CF788C,5e5,Mixing,include
From: https://www.cnblogs.com/towboa/p/17151448.html

相关文章

  • 在统信UOS上二进制安装GreatSQL
    GreatSQL社区原创内容未经授权不得随意使用,转载请联系小编并注明来源。GreatSQL是MySQL的国产分支版本,使用上与MySQL一致。作者:vatebur文章来源:GreatSQL社区投稿UOS......
  • “采访”ChatGPT看看它对我们GreatSQL社区有什么看法
    什么是ChatGPT?ChatGPT是美国人工智能研究实验室OpenAI开发的一种全新聊天机器人模型,它能够通过学习和理解人类的语言来进行对话,还能根据聊天的上下文进行互动,并协助人类......
  • Number of Great Partitions
    NumberofGreatPartitionsYouaregivenanarray nums consistingofpositive integersandaninteger k .Partitionthearrayintotwoorderedgroups suc......
  • UVA10256 The Great Divide
    洛谷传送门UVA传送门考虑对两个点集求出凸包,显然如果这两个凸包相离就合法,然后问题就转化成了这两个凸包是否有交。设红点凸包包围的点集为\(A\),蓝点凸包包围的点集为......
  • Codeforces 1097 G Vladislav and a Great Legend 题解 (DP)
    题目链接思路首先看到这种求\(x^k\)形式的,直接无脑转下降幂:\(x^k=\sum_{i=1}^kS2(k,i)\cdotx^{\underline{i}}\),其中\(S2\)表示第二类斯特林数,\(x^{\underlinei}\)表......
  • Codeforces 1097 G Vladislav and a Great Legend 题解 (DP)
    题目链接思路首先看到这种求\(x^k\)形式的,直接无脑转下降幂:\(x^k=\sum_{i=1}^kS2(k,i)\cdotx^{\underline{i}}\),其中\(S2\)表示第二类斯特林数,\(x^{\underlinei}\)表......
  • Codeforces 1097 G Vladislav and a Great Legend 题解 (DP)
    题目链接思路首先看到这种求\(x^k\)形式的,直接无脑转下降幂:\(x^k=\sum_{i=1}^kS2(k,i)\cdotx^{\underline{i}}\),其中\(S2\)表示第二类斯特林数,\(x^{\underlinei}\)表......
  • Codeforces 1097 G Vladislav and a Great Legend 题解 (DP)
    题目链接思路首先看到这种求\(x^k\)形式的,直接无脑转下降幂:\(x^k=\sum_{i=1}^kS2(k,i)\cdotx^{\underline{i}}\),其中\(S2\)表示第二类斯特林数,\(x^{\underlinei}\)表......
  • GreatSQL MGR 使用 IPv6 连接
    GreatSQL社区原创内容未经授权不得随意使用,转载请联系小编并注明来源。GreatSQL是MySQL的国产分支版本,使用上与MySQL一致。作者:王权富贵文章来源:社区原创1.概述本......
  • 最大公约数 GCD greatest common divisor
     辗转相除法#include<stdio.h>intmain(void){intm,n,r;scanf("%d%d",&m,&n);if(m<n){m=m^n;n=m^n;......