A28 贪心算法 P1843 奶牛晒衣服
视频链接:78 贪心算法 P1843 奶牛晒衣服_哔哩哔哩_bilibili
#include <iostream> #include <cstring> #include <algorithm> #include <queue> using namespace std; priority_queue<int> q; //大根堆 int n,a,b; int tim,mx; int main(){ scanf("%d%d%d",&n,&a,&b); for(int i=1;i<=n;i++){ int x; scanf("%d",&x); q.push(x); } //每次找出剩余的湿度最大的衣服,使用烘干机 mx=q.top(); q.pop(); while(mx>tim*a){ tim++; mx-=b; q.push(mx); mx=q.top(); q.pop(); } printf("%d",tim); }
// 二分答案 nlogn #include<iostream> using namespace std; int n,a,b,w[500005]; bool check(int t){ int s=0; for(int i=1;i<=n;i++){ if(w[i]<=t*a) continue; s+=(w[i]-t*a+b-1)/b; //上取整 } return s<=t; } int main(){ ios::sync_with_stdio(0); cin>>n>>a>>b; for(int i=1;i<=n;i++) cin>>w[i]; int l=0,r=1e6,mid; while(l+1<r){ mid=l+r>>1; check(mid)?r=mid:l=mid; } cout<<r<<endl; }
分类:
A 基础算法
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
2022-09-02 A01 高精度加法