华农专业课拯救计划:csf202303

#哪个编程工具让你的工作效率翻倍?#

作者是只菜狗,第三个没搞出来,大家先复制前两个吧

田地丈量,先复制代码

#include<iostream>
#include<vector>
using namespace std;
int main()
{
	int m,x,y;
	cin >> m>>x>>y;
	int arr[100][4];
	for (int i = 0; i < m; i++)
	{
		for (int j = 0; j < 4; j++)
		{
			cin >> arr[i][j];
			if (arr[i][j] < 0)
			{
				arr[i][j] = 0;
			}
		}
	}
	int count = 0;
	for (int i = 0; i < m; i++)
	{
		if (arr[i][1] > arr[i][3])
		{
			int a = arr[i][3];
			arr[i][3] = arr[i][1];
			arr[i][1] = a;
		}
	}

	for (int i = 0; i < m; i++)
	{
		if ((arr[i][1] > y && arr[i][3] > y)||(arr[i][0]>x&&arr[i][2]>x))
		{
			continue;
		}
			else if (arr[i][2] <= x && arr[i][3] <= y)
			{
				count += (arr[i][2]-arr[i][0]) * (arr[i][3]-arr[i][1]);
			}
			else if (arr[i][2] > x && arr[i][3] <= y)
			{
				count += (x - arr[i][0]) * (arr[i][3] - arr[i][1]);
			}
			else if (arr[i][2] <= x && arr[i][3] > y)
			{
				count += (y - arr[i][1]) * (arr[i][2] - arr[i][0]);
			}
			else
			{
				count += (x - arr[i][0]) * (y - arr[i][1]);
			}
	}
	cout << count;
	return 0;
}

 聊聊我的心路历程:首先我把田地的情况分为四种,全在范围里面,x出来一截,y出来一截,都出来一截,但是我在长时间与用例的博弈发现了另一种情况,全在外面,而又在长时间的纠错后,发现了描述田地的两个坐标不一定是左下右上,还有左上右下一种,所以在写代码的时候要随时打印纠错

垦田计划,先复制代码

#include<iostream>
#include<map>
#include<vector>
using namespace std;
int main()
{
	int n, m, k;
	cin >> n>>m>> k;
	map<int, int, greater<int>>land;
	for (int i = 0; i < n; i++)
	{
		int day, need;
		cin >> day >> need;
		land[day] += need;
	}
	land[k] += 0;
	auto it = land.begin();
	int count = -10086;
	while(m>=it->second&&it->first>k)
	{
		auto it1 = it;
		it1++;
		int cost = ((it->first - it1->first) * it->second);
		if (m - cost < 0)
		{
			count = it->first;
			while (m >= it->second)
			{
				m -= it->second;
				count--;
			}
			cout << count;
			break;
		}
		else
		{
			m -= cost;
			it1->second += it->second;
			land.erase(it->first);
		}
		it = land.begin();
	}
	if (count == -10086)
	{
		cout << it->first;
	}
	return 0;
}

聊聊心路历程:这道题首先看见一堆公式就头大了,但是看到题干就想当一个贪心的男人,首先选择贪心策略(也没啥选的):把资源给天数的最多的,再选择map作为存储器,也可以用vector<pair>加迭代器排序,但是我想用map因为懒得写迭代器排序,首先这是一个降序排序,原因是根据贪心策略要开始从天数多的开始,在有资源且最低天数大于k的时候进行,首先看一看能不能给天数多的降一个档,能就更新一下各种变量,头删一下,不能降档就算一下能减几天,如果一开始就满足要求,就打印最多的天数

第三题(我不会,我不会......)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值