30pts求调 玄关

P1676 [USACO05FEB] Aggressive cows G

@[I_Love_Kobe](/user/1155991) 把 `y++` 放到 for 里面,最后输出 `l-1`,就 AC 了。
by ljk8886 @ 2024-08-29 10:01:12


@[ljk8886](/user/809979) 还是A不了唉巨佬
by I_Love_Kobe @ 2024-08-29 10:12:15


@[ljk8886](/user/809979) tle了
by hanxiaofensheng @ 2024-08-29 10:12:21


@[xiaokeai1234](/user/1400181) 我是只有20pts,其他的WA了
by I_Love_Kobe @ 2024-08-29 10:15:52


啊?我再试试
by ljk8886 @ 2024-08-29 10:16:30


```cpp #include<bits/stdc++.h> #define int long long using namespace std; int n,m,a[100015],l=1,r=1000000001; bool check(int mid){ int sum=1; for(int x=1,y=2;y<=n;y++){ if(a[y]-a[x]>=mid){ sum++,x=y; } } return sum>=m; } signed main(){ cin>>n>>m; for(int i=1;i<=n;i++){ cin>>a[i]; } sort(a+1,a+1+n); while(l<r){ int mid=(l+r)>>1; if(check(mid)){ l=mid+1; } else{ r=mid; } } cout<<l-1; return 0; } ``` 这样就 AC 了啊
by ljk8886 @ 2024-08-29 10:17:50


@[I_Love_Kobe](/user/1155991) @[xiaokeai1234](/user/1400181)
by ljk8886 @ 2024-08-29 10:18:26


啊?y++: 我在哪? @[ljk8886](/user/809979)
by hanxiaofensheng @ 2024-08-29 10:20:42


@[xiaokeai1234](/user/1400181) 我看了你代码,要把 `y++` 放到 for 那一行里,而不是 if 里
by ljk8886 @ 2024-08-29 10:21:24


@[ljk8886](/user/809979) 已关,谢谢巨佬
by I_Love_Kobe @ 2024-08-29 10:22:19


| 下一页