【Day4】C++竞赛每日练习

P1046 NOIP 2005 普及组 陶陶摘苹果https://www.luogu.com.cn/problem/P1046#ide

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;

int a[11];
int n,ret;

int main() {
	for(int i = 1;i<=10;i++)
	{
		cin>>a[i];
	}
	cin>>n;
	for(int i = 1;i<=10;i++)
	{
		if(a[i]>(n+30))continue;
		else
		ret++;
	}
	cout<<ret;
	return 0;
}

P1478 陶陶摘苹果(升级版)https://www.luogu.com.cn/problem/P1478#ide

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;
const int N = 5010;
int s,n,ret,a,b;

struct node
{
	int x,y;
}h[N];

bool cmp(node a,node b)
{
	return a.y<b.y;
}

int main() {
	cin>>n>>s>>a>>b;
	//苹果数a,力气s,椅子高度a,手长b
	for(int i = 1;i<=n;i++)
	{
		cin>>h[i].x>>h[i].y;
	} 
	sort(h+1,h+1+n,cmp);
	for(int i = 1;i<=n;i++)
	{
		if(h[i].x <=a+b && s >= h[i].y )
		{
			ret++;
			s -= h[i].y;
		}
		else continue;
	}
	cout<<ret;
	return 0;
}

P2969 USACO09DEC Music Notes Shttps://www.luogu.com.cn/problem/P2969#ide

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const  ll N = 50008;
int n,q,b[N],t[N],f[N];


int main()
{
	cin>>n>>q;
	for(int i = 1;i<=n;i++)
	{
		int x;cin>>x;
		b[i] = b[i-1]+x;//输入音符一次持续几个节拍
		
	}
	while(q--)
	{
		int t;cin>>t;
		int l = 1,r = n;
		while(l<r)
		{
			int mid = (l+r)/2;
			if(b[mid]>t)r = mid;
			else
			l = mid+1;
		}
		cout<<l<<endl;
	}
	return 0 ;
}
相关推荐
JieE21220 小时前
LeetCode 101. 对称二叉树|JS 递归 + 迭代双解法,彻底搞懂镜像判断
javascript·算法
JieE2122 天前
LeetCode 56. 合并区间|超清晰 JS 图解思路,面试高频区间题
javascript·算法·面试
Jack202 天前
HarmonyOS开发中错误处理策略:网络异常统一处理
算法
小小杨树2 天前
读懂色彩:拍照调色不再难
算法·计算机视觉·配色
JieE2123 天前
LeetCode 226. 翻转二叉树|JS 递归超详细拆解,二叉树入门经典题
javascript·算法
JieE2123 天前
LeetCode 104. 二叉树的最大深度|递归思路超详细拆解
javascript·算法
vivo互联网技术3 天前
CVPR 2026 | 全新强化学习框架 BeautyGRPO:重塑真实人像
算法·大模型·cvpr·影像
Darling噜啦啦3 天前
列表转树算法深度解析:从 Map 到 Reduce 的两种实现,面试高频考点
数据结构·算法·面试
clint4563 天前
C++进阶(1)——前景提要
c++