# 2023CSP-CCF第一二题（田地丈量，垦田计划）解题分析

## 一.田地丈量

### 4.完整代码

#include<iostream>
using namespace std;
int main() {
int n, a, b;
int x1, y1, x2, y2;
long long int sum = 0;
scanf("%d%d%d", &n, &a, &b);
for (int i = 1; i <= n; i++) {
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
if(x1>=0&&y1>=0&&x2<=a&&y2<=b)
sum+=(y2-y1)*(x2-x1);
else if(x1<0&&x2>0&&y1<0&&y2>0)
sum+=y2*x2;
else if(x1>=0&&x2<=a&&y1<0&&y2>0)
sum+=y2*(x2-x1);
else if(x1<a&&x2>a&&y1<0&&y2>0)
sum+=(a-x1)*y2;
else if(x1<a&&x2>a&&y1>=0&&y2<=b)
sum+=(y2-y1)*(a-x1);
else if(x1<a&&x2>a&&y1<b&&y2>b)
sum+=(b-y1)*(a-x1);
else if(x1>=0&&x2<=a&&y1<b&&y2>b)
sum+=(b-y1)*(x2-x1);
else if(x1<0&&x2>0&&y1<b&&y2>b)
sum+=x2*(b-y1);
else if(x1<0&&x2>0&&y1>=0&&y2<=b)
sum+=x2*(y2-y1);

}
printf("%lld",sum);
return 0;

}


#include<iostream>
#include<algorithm>

using namespace std;
int x1, y1, x2, y2;
int main() {
int n, a, b, x, y;
long long sum = 0;
scanf("%d%d%d", &n, &a, &b);
for (int i = 1; i <= n; i++) {
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
x = min(a, x2) - max(0, x1);
y = min(b, y2) - max(0, y1);
if (x >= 0 && y >= 0)
sum += x * y;

}
printf("%lld", sum);
return 0;

}


## 二.垦田计划

### 4.完整代码

#include<iostream>
#include<algorithm>
using namespace std;
const int N = 100100;
typedef long long ll;
ll t[N], c[N];
ll cc[N];
int main() {
ll n, m, k, maxn = 0;
cin >> n >> m >> k;
for (int i = 0; i < n; i++) {
cin >> t[i] >> c[i];
cc[t[i]] += c[i];
maxn = max(maxn, t[i]);
}
for (int i = maxn; i >= k; i--) {

if (m > cc[i]) {
if (i == k) {
cout << k << endl;
break;
}
m = m - cc[i];
cc[i - 1] = cc[i - 1] + cc[i];
}

else

{
cout << i << endl;
break;

}

}

}


• 3
点赞
• 9
收藏
觉得还不错? 一键收藏
• 1
评论
03-17
03-28 226
03-20 1163
04-04 9418
03-23 8180
04-15 3688
07-26 448
03-31 1561
08-02
03-23 974
03-26 808

### “相关推荐”对你有帮助么？

• 非常没帮助
• 没帮助
• 一般
• 有帮助
• 非常有帮助

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