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

买二赠一--蓝桥

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;
}

相关文章:

  • 一次现网问题定位-线程池设置不当,导致流量上去后接口变慢
  • 【网络安全 | 渗透工具】小程序反编译分析源码 | 图文教程
  • GPT-4.5震撼登场,AI世界再掀波澜!(3)
  • 【MySQL】 数据类型
  • ESP32+Mixly+LED闪烁
  • getline的使用(L1-059敲笨钟)
  • 02Java基础概念
  • ISP 常见流程
  • Python----Python爬虫(多线程,多进程,协程爬虫)
  • Apifox 2月更新|调试 AI 接口时展示思考过程,团队内支持共享数据库连接
  • 【MySQL】表操作
  • SOLID Principle基础入门
  • Vue3响应式原理解析
  • 八、数据库设计与优化详解
  • 深入探索 STM32 微控制器:从基础到实践
  • Python:字符串常见操作
  • Java 并发编程之synchronized
  • 2024年中国城市统计年鉴(PDF+excel)
  • Python 高精度计算利器:decimal 模块详解
  • Java日志
  • 有了域名之后如何做网站/头条发布视频成功显示404
  • 个人网站开论坛/百度做推广一般要多少钱
  • 快速建网站软件/优化网站搜索排名
  • 怎样建设网站卖农产品/引流推广效果好的app
  • 网站悬浮窗口/怎么推广软件让别人下载
  • 淘宝有做钓鱼网站的吗/百度官网地址