2 条题解
-
0
题内话
同 P1696,又是一道简单的暴力水题。
第一层循环枚举被解雇的奶牛的编号,第二层循环枚举除了被解雇的奶牛,其他奶牛的工作时间,第三重循环从从工作时间的左端点枚举到右端点,打个标记,再把所有打上了标记的时间点的个数都统计一下,答案就是统计出的结果里面的最大值。
详见代码:
#include<iostream> using namespace std; int n, ans = -1e7; struct node{ int x, y; }a[105]; bool vis[10005]; int main(){ cin >> n; for (int i = 1; i <= n; i++){ cin >> a[i].x >> a[i].y; } for (int i = 1; i <= n; i++){ int cnt = 0; for (int j = 0; j <= 1000; j++) vis[j] = 0; for (int j = 1; j <= n; j++){ if (j == i) continue; for (int k = a[j].x; k < a[j].y; k++){ vis[k] = 1; } } for (int j = 0; j <= 1000; j++) if (vis[j]) cnt++; ans = max(ans, cnt); } cout << ans; return 0; } -
0
#include <bits/stdc++.h> using namespace std; int n, a[101], b[101], t[1001], s[1001]; int main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> n; int mi=1001,mx=0; memset(t, 0, sizeof(t)); for (int i = 1; i <= n; i++){ cin >> a[i] >> b[i];a[i]++; mi = min(mi, a[i]); mx = max(mx, b[i]); for (int j = a[i]; j <= b[i]; j++)t[j]++; } int S = 0;for (int i = 1; i <= 1000; i++)S += (t[i] > 0); s[0] = 0; for (int i = 1; i <= 1000; i++)s[i] = s[i - 1] + (t[i]==1); int ans=1001; for (int i = 1; i <= n; i++)ans = min(ans, s[b[i]] - s[a[i]-1]); cout << S - ans << endl; return 0; }
- 1
信息
- ID
- 6812
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 5
- 标签
- 递交数
- 44
- 已通过
- 18
- 上传者