跳到正文

学习·文化课

贪心百题斩之黄题 1.0

Clare613约 26 分钟
原文

这是 2026年10月11日 存档的第 2 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

发布
2026年10月9日
收录
2026年10月10日
更新
2026年11月28日
篇幅
约 26 分钟
获赞
1

版本

  1. v10当前
  2. v9
  3. v8
  4. v7
更早的 6 个版本
  1. v6
  2. v5
  3. v4
  4. v3
  5. v2
  6. v1

B4071 [GESP202412 五级] 武器强化

思路:

观察到 1≤n,m≤10001\le n,m\le 1000,考虑暴力处理每一种情况。

对于情况武器 11 的数量为 kk 的,可以计算需要花的钱,显然发现其他的武器数量都是小于等于 k−1k-1 的,对于每一种情况都计算一遍,不够的就再补上。

时间复杂度 O(nm)\mathcal{O}(nm),可以接受。

code
C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int NA=1005;
vector<int> v[NA];
int s[NA];
int sum[NA][NA];
int n,m;
int k(int x){
	int res=0,cnt=s[1];
	for(int i=2;i<=n;i++){
		res+=sum[i][max(s[i]-x+1,0ll)];
		cnt+=max(s[i]-x+1,0ll);
	}
	if(cnt<x){
		priority_queue<int,vector<int>,greater<int> > q;
		for(int i=2;i<=n;i++){
			for(int j=max(s[i]-x+2,1ll);j<=s[i];j++){
				q.push(v[i][j-1]);
			}
		}
		while(!q.empty()&&cnt<x){
			cnt++;
			res+=q.top();
			q.pop();
		}
	}
	return res;
}
signed main(){
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		int p,c;
		cin>>p>>c;
		v[p].push_back(c); 
	}
	for(int i=1;i<=n;i++){
		sort(v[i].begin(),v[i].end());
		s[i]=v[i].size();
		for(int j=1;j<=s[i];j++){
			sum[i][j]=sum[i][j-1]+v[i][j-1];
		}
	}
	int ans=1e18;
	for(int i=1;i<=m;i++){
		ans=min(ans,k(i));
	}
	cout<<ans;
	return 0;
} 

B4091 [CSP-X2020 山东] 分糖果

思路:

显然不满足的情况为:

  • 前一个比当前大,但糖果数小于等于前一个。
  • 前一个比当前小,但糖果数大于等于前一个。

显然我们可以先令每一人的糖果为 11,贪心的想到如果情况不符合就令其为较大数加 11,时间复杂度为 O(100×n)\mathcal{O}(100\times n)。

code
C++
#include<bits/stdc++.h>
using namespace std;
const int NA=1e5+5;
int a[NA],b[NA];
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		b[i]=1;
	}
	while(1){
		int last=1,id=2;
		bool flag=0;
		for(int i=1;i<=n;i++){
			if(a[id]>a[last]&&b[id]<=b[last]){
				b[id]++;
				flag=1;
			}
			if(a[id]<a[last]&&b[id]>=b[last]){
				b[last]++;
				flag=1;
			}
			last=id;
			id++;
			if(id==n+1) id=1;
		}
		if(flag==0) break;
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		ans+=b[i];
	}
	cout<<ans;
	return 0;
}

B4107 [CSP-X2024 山东] 刷题

思路:

显然的发现,题目要求了要按照题目编号顺序做完所有的题目。

考虑二分答案,显然我们对于每一天:能加就加,不能加就下一天,然后每次贪心的想,问小明当然是问最难的了。

思路完了,时间复杂度大概 O(mlog⁡109)\mathcal{O}(m \log 10^9)。

code
C++
#include<bits/stdc++.h>
using namespace std;
const int NA=1e5+5;
int a[NA];
int n,m;
bool check(int k){
	int id=1;
	for(int i=1;i<=m;i++){
		int maxn=0,sum=0;
		while(id<=n&&sum+a[id]-max(maxn,a[id])<=k){
			sum+=a[id];
			maxn=max(maxn,a[id]);
			id++;
		}
		if(id>n){
			return 1;
		}
	}
	return 0;
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	int l=0,r=1e9;
	while(l<r){
		int mid=(l+r)>>1;
		if(check(mid)) r=mid;
		else l=mid+1;
	}
	cout<<l<<"\n";
	return 0;
}

B4204 [常州市赛 2021] 烧菜

思路:

code

B4220 [常州市赛 2023] 洗牌

思路:

code

B4253 [科大国创杯小学组 2024] 几何

思路:

code

B4304 [蓝桥杯青少年组省赛 2024] 通关游戏的最少能量值

思路:

code

B4391 [常州市赛 2025] 拖拉机

思路:

code

B4399 [蓝桥杯青少年组国赛 2025] 第四题

思路:

code

B4514 [四川青少年 C++ 算法设计大赛 2025] 金苹果岛

思路:

code

P10073 [GDKOI2024 普及组] 刷野 II

思路:

code

P14971 『GTOI - 2B』DDoS

思路:

code

P15009 [UOI 2019 II Stage] 随从

思路:

code

P15028 [UOI 2021 II Stage] 献给女士的礼物

思路:

code

P15256 [USACO26JAN2] Purchasing Milk B

思路:

code

P15287 「YLLOI-R3-T2」霍元甲

思路:

code

P15313 [VKOSHP 2025] Magic Ritual

思路:

code

P15338 [GCPC 2025] Karlsruhe Skyline

思路:

code

P15384 构造树的题 / tree

思路:

code

P15572 [USACO26FEB] Swap to Win B

思路:

code

P15602 [ICPC 2020 Jakarta R] Police Stations

思路:

code

P9228 原神

思路:

code

P9251 [PA 2022] Palindrom

思路:

code

P9422 [蓝桥杯 2023 国 B] 合并数列

思路:

code

P9467 [EGOI 2023] Carnival General / 狂欢节总管

思路:

code

P9540 「AWOI Round 2 C」数组操作?数组操作!

思路:

code

P9562 [SDCPC 2023] Matching

思路:

code

P9812 [CCC 2015 S3] Gates

思路:

code

P9952 [USACO20OPEN] Social Distancing I B

思路:

code

B4218 [常州市赛 2023] ABC 字符串

思路:

code

P10135 [USACO24JAN] Potion Farming S

思路:

code

P1016 [NOIP 1999 普及组/提高组] 旅行家的预算

思路:

code

P10335 [UESTCPC 2024] 取数游戏

思路:

code

P10341 [THUSC 2019] 紧急决策

思路:

code

P10464 Task

思路:

code

P10505 Dropping Test

思路:

code

P1056 [NOIP 2008 普及组] 排座椅

思路:

code

P10934 西瓜种植

思路:

code

P1095 [NOIP 2007 普及组] 守望者的逃离

思路:

code

P1158 [NOIP 2010 普及组] 导弹拦截

思路:

code

P1167 刷题

思路:

code

P1180 驾车旅游

思路:

code

P1182 数列分段 Section II

思路:

code

P12633 [UOI 2020] Skyscraper

思路:

code

P12687 [KOI 2022 Round 1] 鹅卵石

思路:

code

P12688 [KOI 2022 Round 1] 避开

思路:

code

P12712 [KOI 2021 Round 1] 超矩形

思路:

code

P13032 [GCJ 2021 #1C] Closest Pick

思路:

code

P13050 [GCJ 2020 Qualification] Parenting Partnering Returns

思路:

code

P13158 [GCJ 2017 Qualification] Oversized Pancake Flipper

思路:

code

P13159 [GCJ 2017 Qualification] Tidy Numbers

思路:

code

思路:

code

P13312 [GCJ 2012 Qualification] Dancing With the Googlers

思路:

code

P13455 [GCJ 2008 Qualification] Train Timetable

思路:

code

P1658 购物

思路:

code

P1842 [USACO05NOV] 奶牛玩杂技

思路:

code

P2920 [USACO08NOV] Time Management S

思路:

code

P3078 [USACO13MAR] Poker Hands S

思路:

code

P3536 [POI 2012] BON-Vouchers

思路:

code

P3743 小鸟的设备

思路:

code

P4144 大河的序列

思路:

code

P10911 [蓝桥杯 2024 国 B] 数位翻转

思路:

code

P10922 Happybob’s Numbers (UBC001B)

思路:

code

P11205 「Cfz Round 9」Hope

思路:

code

P11247 [GESP202409 六级] 算法学习

思路:

code

P11273 「Diligent-OI R1 C」DlgtRank

思路:

code

P11349 [NOISG 2024 Finals] Problem Setter

思路:

code

P11376 [GESP202412 六级] 运送物资

思路:

code

P11960 [GESP202503 五级] 平均分配

思路:

code

P1199 [NOIP 2010 普及组] 三国游戏

思路:

code

P12802 [AMPPZ 2019] Assimilation

思路:

code

P13186 [GCJ 2016 Qualification] Revenge of the Pancakes

思路:

code

P1324 矩形分割

思路:

code

P5119 [USACO18DEC] Convention S

思路:

code

P5199 [USACO19JAN] Mountain View S

思路:

code

P5541 [USACO19FEB] Sleepy Cow Herding S

思路:

code

P5804 [SEERC 2019] Absolute Game

思路:

code

P5961 [BalticOI 2006] coin collector钱币收藏家

思路:

code

P5963 [BalticOI 2005] Card 卡牌游戏 (Day0)

思路:

code

P6317 [COCI 2006/2007 #3] TENKICI

思路:

code

P6446 [COCI 2010/2011 #1] TABOVI

思路:

code

P6549 [COCI 2010/2011 #2] KNJIGE

思路:

code

P11396 排队

思路:

code

P11452 [USACO24DEC] Cake Game S

思路:

code

P11540 [Code+#5] 逻辑树

思路:

code

P11638 Max,Mex

思路:

code

P11854 [CSP-J 2022 山东] 宴会

思路:

code

P11868 [威海市赛2024] 抽卡

思路:

code

P11931 [CrCPC 2024] AI 的末日

思路:

code

P12161 [蓝桥杯 2025 省 Java B] 研发资源分配

思路:

code

P12168 [蓝桥杯 2025 省 C/Python A/Java A] 拼好数

思路:

code

P12836 [蓝桥杯 2025 国 B] 翻倍

思路:

code

P12881 [蓝桥杯 2025 国 C] 宗门大比

思路:

code

P13053 [GCJ 2020 #1A] Pattern Matching

思路:

code

P13145 [GCJ 2018 #2] Falling Balls

思路:

code

P13149 [GCJ 2018 #3] Field Trip

思路:

code

P1336 最佳课题选择

思路:

code

P1889 [CEOI 1998] 士兵站队

思路:

code

P1986 元旦晚会

思路:

code

P2434 [SDOI2005] 区间

思路:

code

编写不易,给个赞再走呗。

2.0 不知道什么时候会出。