作业介绍
Best Cow Fences G
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const double eps = 1e-6;
int n, m;
double a[N];
double b[N], sum[N];
// 看能否凑出长度大于等于m 的字段平均数是 x
bool check(double x) {
for (int i = 1; i <= n; i++) {
b[i] = a[i] - x;
sum[i] = sum[i - 1] + b[i];
}
double minn = 1e9;
for (int i = m; i <= n; i++) {
minn = min(minn, sum[i - m]);
if (sum[i] - minn >= 0)
return 1;
}
return 0;
}
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++)
cin >> a[i];
double l = 0, r = 2000;
while (l + eps < r) {
double mid = (l + r) / 2;
if (check(mid))
l = mid;
else
r = mid;
}
cout << int(r * 1000);
return 0;
}
防线
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
#define int long long
struct node {
int s, e, d;
};
node a[N];
int T, n;
// 到x 位置结束的防具和
int check(int x) {
int tot = 0;
for (int i = 1; i <= n; i++) {
if (a[i].s > x)
continue;
// tot += (min(x, a[i].e) - a[i].s) / a[i].d + 1;
tot += (min(x, a[i].e) + a[i].d - a[i].s ) / a[i].d;
}
return tot;
}
signed main() {
cin >> T;
while (T--) {
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i].s >> a[i].e >> a[i].d;
int l = 0, r = 2147483647, mid, ans = -1;
while (l <= r) {
//mid = (l + r) / 2;
mid = l + (r-l)/2;
if (check(mid) % 2 == 1)
ans = mid, r = mid - 1;
else
l = mid + 1;
}
if (ans == - 1)
cout << "There's no weakness.\n";
else {
int tot = check(ans) - check(ans - 1);
printf("%lld %lld\n", ans, tot);
}
}
return 0;
}
一元三次方程
#include <bits/stdc++.h>
using namespace std;
double a, b, c, d;
const double eps = 1e-3;
double f(double x) {
return a * x * x * x + b * x * x + c * x + d;
}
int main() {
cin >> a >> b >> c >> d;
for (double i = -100 ; i <= 100; i++) {
double l = i, r = i + 1;
if (f(l) == 0) {
printf("%.2lf ", l);
} else if (f(l)*f(r) < 0) { // 意味着 (l,r) 之间有跟
while (l + eps < r) {
double mid = (l + r) / 2;
if (f(l)*f(mid) <= 0)
r = mid;
else
l = mid;
}
printf("%.2lf ", l);
}
}
return 0;
}
数列分段
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
#define int long long
int n, m, a[N];
int l, r, mid, ans = -1;
// 检查在当前的段落和为 x 的情况下是否能凑出不超过m段
bool check(int x) {
int cnt = 1;
int sum = a[1];
for (int i = 2; i <= n; i++) {
if (a[i] + sum <= x)
sum += a[i];
else
sum = a[i], cnt++;
}
return cnt <= m;
}
signed main() {
cin >> n >> m;
for (int i = 1; i <= n; i++)
cin >> a[i], l = max(l, a[i]);
r = 1e9;
// 最大值最小
while (l <= r) {
mid = (l + r) / 2;
if (check(mid))
ans = mid, r = mid - 1;
else
l = mid + 1;
}
cout << ans;
return 0;
}
进击的奶牛
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, m, a[N];
// 检查在距离 为 x 的时候是否能满足放置 m 头牛
bool check(int x) {
int cnt = 1;
int last = a[1]; // 第一个位置肯定放牛
for (int i = 2; i <= n; i++)
if (a[i] - last >= x)
last = a[i], cnt++;
return cnt >= m;
}
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++)
cin >> a[i];
sort(a + 1, a + 1 + n);
int l = 1, r = 1e9, mid, ans = -1;
// 最小值最大模板
while (l <= r) {
mid = (l + r) / 2;
if (check(mid))
ans = mid, l = mid + 1;
else
r = mid - 1;
}
cout << ans;
return 0;
}
汽车拉力赛
// 最大值最小
int cnt;
void f(int x, int y, int mid) {
vis[x][y] = 1;
if (a[x][y] == 1)
cnt++;
for (四个方向) {
if ()
}
}
bool check(int mid) {
cnt = 0; // 标记走了几个路标
memset(vis, 0, sizeof vis);
dfs(x1, y1, mid);
if (cnt == tot)
return 1;
else
return 0;
}
题目
认领作业后才可以查看作业内容。
- 状态
- 正在进行…
- 题目
- 21
- 开始时间
- 2026-7-1 0:00
- 截止时间
- 2026-8-31 23:59
- 可延期
- 24 小时