【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 ;
}
相关推荐
迷途之人不知返39 分钟前
lambda表达式
c++
jarvisuni41 分钟前
DeepSeekFlash前端依旧拉垮,而且变慢了很多!
前端·javascript·算法
@三十一Y44 分钟前
C++:红黑树的实现
开发语言·c++
kobesdu1 小时前
流形上的优化:SO(3)与SE(3)的广义加减法在FAST-LIO中如何简化状态估计
人工智能·算法·fastlio
_wyt0011 小时前
拓扑排序:有向无环图的排队艺术
c++·拓扑排序·队列
皓月斯语1 小时前
B2118 验证子串
c++·题解
白狐_7981 小时前
408 数据结构算法题 01:线性表暴力求解保分指南
java·数据结构·算法
乐观勇敢坚强的老彭1 小时前
C++信奥:开关门、开关灯问题
开发语言·c++·算法
冻柠檬飞冰走茶1 小时前
PTA基础编程题目集 7-31 字符串循环左移(C语言实现)
c语言·开发语言·数据结构·算法
Hi李耶2 小时前
【LeetCode】4-寻找两个正序数组的中位数
算法·leetcode·职场和发展