当前位置: 首页 > article >正文

买二赠一--蓝桥

80%版本

我认为买的越大越好--贪心然后标记赠的

#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
const long long INF = 1e18;
const int MOD = 1e9 + 9; // 定义模数
ll n,m,k,t;
//不开long long 见祖宗
bool bo[500111];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    vector<int> a;
    for(int i=0;i<n;i++)
    {
    	int x;cin>>x;a.push_back(x);
	}
	sort(a.begin(),a.end());
	ll c=0;
	for(int i=n-1;i>=0;i--)
	{
		if(!bo[i])
		{
		c+=a[i];
		//cout<<a[i]<<endl;
		int s;int f=0;
		for(int j=i-1;j>=0;j--)
		{
			if(!bo[j])
		{
		c+=a[j];
		bo[j]=true;
		s=a[j];
		//cout<<s<<endl;
		
		for(int w=j-1;w>=0;w--)
		{
			if(bo[w]==false&&a[w]<=(double)s/2)
			{
				bo[w]=true;
				//cout<<a[w]<<endl;
				f=1;
				break;
			}
		}
		if(f) break;	
		}
		if(f) break;
		}
		}
	}
cout<<c;
    return 0;
}

100%版本---加了个二分就行了

#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
const long long INF = 1e18;
const int MOD = 1e9 + 9; // 定义模数
ll n,m,k,t;
//不开long long 见祖宗
bool bo[500111];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    vector<int> a;
    for(int i=0;i<n;i++)
    {
    	int x;cin>>x;a.push_back(x);
	}
	sort(a.begin(),a.end());
	ll c=0;
	for(int i=n-1;i>=0;i--)
	{
		if(!bo[i])
		{
		c+=a[i];
		//cout<<a[i]<<endl;
		int s;int f=0;
		for(int j=i-1;j>=0;j--)
		{
			if(!bo[j])
		{
		c+=a[j];
		bo[j]=true;
		s=(double)a[j]/2;
		//cout<<a[j]<<endl;
		int l=0,r=j-1;
		while(l<=r)
		{
			int mid=(l+r)>>1;
			if(a[mid]<=s&&bo[mid]==false)
			{
				l=mid+1;
			}else r=mid-1;
		}
		//cout<<"**"<<a[r]<<"**"<<endl;
		bo[r]=true;
		f=1;
		if(f) break;	
		}
		if(f) break;
		}
		}
	}
cout<<c;
    return 0;
}


http://www.kler.cn/a/567294.html

相关文章:

  • 版图自动化连接算法开发 00003 ------ 添加两个中间点实现 Manhattan 方式连接两个给定的坐标点
  • 升级Office软件后,Windows 系统右键里没有新建Word、Excel、PowerPoint文件的解决办法
  • 网络原理--TCP/IP(2)
  • SERPENTINE Tools
  • OAK相机的抗震性测试
  • redis repl_backlog_first_byte_offset 这个字段的作用
  • Linux网络 TCP全连接队列与tcpdump抓包
  • 【SWAT模型应用】AI辅助下基于ArcGIS Pro的SWAT模型全流程高效建模实践与深度进阶应用
  • 51单片机编程学习笔记——管脚输出
  • 高频面试题(含笔试高频算法整理)基本总结回顾16
  • 性能调优篇——索引优化与执行计划解析
  • Vue3响应式原理解析
  • docker使用代理的简单配置
  • 在 Vim 中查找一个单词的命令
  • JAVA面试_进阶部分_23种设计模式总结
  • Vue.js 组件开发全面详解及应用案例
  • 云创智城YunCharge 新能源二轮、四轮充电解决方案(云快充、万马爱充、中电联、OCPP1.6J等多个私有单车、汽车充电协议)之充电占位解决方案
  • 【时序预测】在线学习:算法选择(从线性模型到深度学习解析)
  • 2015 - 2024年国外与中国博士招生毕业人数趋势现状分析2025.2.26
  • Python基于Django的音乐推荐系统的设计与实现(附源码,文档说明)