P3853 [TJOI2007]路标设置 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)

输入
101 2 1 0 101
输出
51

#include <iostream>
#include <bits/stdc++.h>
#include <cstring>
#include <vector>
#include <unordered_map>
#include <queue>
#include <set>
//#define int long long
#include <algorithm>
#define x first
#define y second
#define pb emplace_back
#define fu(i,a,b) for(int i=a;i<=b; ++ i)
#define fd(i,a,b) for(int i=a;i>=b; -- i)
#define endl '\n'
#define ms(x,y) memset(x,y,sizeof x)
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<vector<LL>> VVL;
typedef vector<vector<int>> VVI;
typedef vector<LL> VL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef vector<PII> VPII;
typedef pair<PII,int> PIII;
typedef pair<double,double> PDD;
typedef pair<double,int> PDI;
typedef pair<char,int> PCI;
typedef pair<string,int> PSI;
typedef pair<int,string> PIS;
typedef pair<int,char> PIC;
typedef pair<LL,LL> PLL;
typedef __int128 i128;
typedef unsigned long long ULL;
const int N =2e5+ 10,M = N *25,base =400 ,INF = 0x3f3f3f3f,P = 131;
const double eps = 1e-8;
const int mod = 1e9+7;
const LL LNF=(LL) INF * INF;
int a[N],ans[N],s[N];
int n,m,k;
bool check(int x)
{
int cnt=0;
fu(i,1,m)
{
if(a[i]-a[i-1] > x ) // 每隔x放一个
cnt+=(a[i]-a[i-1]-1)/x;
// 不-1 就是 [l,r]的个数为x,l和r之间的距离为x-1 有数据过不了
}
return cnt <= k;
}
inline void solve()
{
cin >> n >> m >> k;
fu(i,1,m) cin >> a[i],a[i] ++;
if(k+m>= n) // 距离最小是 1
{
cout << 1 << endl;return;
}
int l= 1,r = n ;
while(l < r)
{
int mid = l + r >> 1 ;
if(check(mid)) r =mid ;
else l = mid + 1;
}
cout << l << endl;
}
signed main()
{
// freopen("1.txt","r",stdin);
// #define int long long
// init(N-1);
ios
// cout << fixed<<setprecision(2);
int t=1;
// cin>>t;
int now = 1;
while(t -- )
{
// cout<<"Case ";
// cout<<"Case #";
// cout<<"Scenario #";
// cout<< now ++ <<": ";
// cout<< now ++ <<": \n";
solve();
}
return 0;
}
161


&spm=1001.2101.3001.11974&articleId=129871983&d=1&t=3&u=fc183947844a41bda7f26b3eafd65ab2)

被折叠的 条评论
为什么被折叠?



