Skip to content

Commit 790e053

Browse files
committed
feat: 优化田地丈量算法,改用C风格输入输出并调整数据类型
1 parent c935b4c commit 790e053

3 files changed

Lines changed: 75 additions & 13 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* @Author: tkzzzzzz6
3+
* @Date: 2026-05-28 18:07:24
4+
* @LastEditors: tkzzzzzz6
5+
* @LastEditTime: 2026-05-28 18:12:42
6+
*/
7+
#include <iostream>
8+
9+
using namespace std;
10+
11+
int main() {
12+
ios::sync_with_stdio(0);
13+
cin.tie(0);
14+
cout.tie(0);
15+
16+
int n;
17+
cin >> n;
18+
int a = -1, b = -1;
19+
int res = 0;
20+
for (int i = 0; i < n; ++i) {
21+
cin >> b;
22+
if (b != a) ++res;
23+
a = b;
24+
}
25+
26+
cout << res << '\n';
27+
28+
return 0;
29+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* @Author: tkzzzzzz6
3+
* @Date: 2026-05-28 18:36:54
4+
* @LastEditors: tkzzzzzz6
5+
* @LastEditTime: 2026-05-28 18:44:04
6+
*/
7+
#include <iostream>
8+
9+
using namespace std;
10+
11+
int main() {
12+
ios::sync_with_stdio(0);
13+
cin.tie(0);
14+
cout.tie(0);
15+
16+
int y, m, d;
17+
cin >> y;
18+
cin >> d;
19+
m = 1;
20+
21+
bool isLeap = (y % 4 == 0 && y % 100 != 0) || (y % 400 == 0);
22+
23+
int month[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
24+
if (isLeap) month[2] = 29;
25+
while (d > month[m]) { // when d == month[m] still in month m
26+
d -= month[m];
27+
++m;
28+
}
29+
30+
cout << m << '\n';
31+
cout << d;
32+
33+
return 0;
34+
}

CCF-CSP/CSP2023-田地丈量.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,30 @@
22
* @Author: tkzzzzzz6
33
* @Date: 2026-05-28 08:06:15
44
* @LastEditors: tkzzzzzz6
5-
* @LastEditTime: 2026-05-28 13:10:13
5+
* @LastEditTime: 2026-05-28 17:53:50
66
*/
7-
#include <iostream>
7+
#include <cstdio>
88
#include <algorithm>
99

1010
using namespace std;
1111

1212
int main() {
13-
ios::sync_with_stdio(0);
14-
cin.tie(0);
15-
16-
long long n, a, b;
17-
long long ans = 0;
18-
cin >> n >> a >> b;
13+
int n;
14+
int a, b;
15+
scanf("%d%d%d", &n, &a, &b);
1916

17+
int ans = 0;
2018
for (int i = 0; i < n; ++i) {
21-
long long x1, y1, x2, y2;
22-
cin >> x1 >> y1 >> x2 >> y2;
23-
long long xl = max(0LL, x1), yl = max(0LL, y1);
24-
long long xr = min(a, x2), yr = min(b, y2);
19+
int x1, y1, x2, y2;
20+
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
21+
22+
int xl = max(0, x1), yl = max(0, y1);
23+
int xr = min(a, x2), yr = min(b, y2);
2524

2625
if (xl < xr && yl < yr)
2726
ans += (xr - xl) * (yr - yl);
2827
}
2928

30-
cout << ans << '\n';
29+
printf("%d\n", ans);
3130
return 0;
3231
}

0 commit comments

Comments
 (0)