周二 木材加工
P2440 木材加工 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
基本思路:二分查找能够符合条件的最大长度
#include<bits/stdc++.h>
using namespace std;
#define INF 1000000000
int ans[100007];
bool T(int n, int k, int mid)
{
int sum = 0;
for (int i = 0; i < n; i++)
{
sum += ans[i] / mid;
}
if (sum >= k)return 1; //等于等于就错
return 0;
}
int main()
{
int n, k;
cin >> n >> k;
for (int i = 0; i < n; i++)
{
cin >> ans[i];
}
int l = 0; int r = INF;
while (l + 1 < r)
{
int mid = (l + r) >> 1;
if (T(n, k, mid))
{
l = mid; //cout <<"l为" << l << endl;
}
else
{
r = mid; //cout << "r为" << r << endl;
}
}
if (!l)
cout << 0 << endl;
else
cout << l << endl;
return 0;
}
周三 CF1304C Air Conditioner
CF1304C Air Conditioner - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int num;
cin >> num;
while (num--)
{
int n, m;
cin >> n >> m;
int l = m, r = m;
int flag = 1;
int temp = 0;
while (n--)
{
int i, j, k;
cin >> i >> j >> k;
int d = i - temp;
temp = i;
l -= d; r += d;
l= max(j, l);
r = min(k, r);
if (l > r)
{
flag = 0;
}
}
if (flag)cout << "YES" << endl;
else cout << "NO" << endl;
}
return 0;
}