http://noi.openjudge.cn/ch0111/
No | 题目 | 分数 | |
01 | 查找最接近的元素 | 10 | 3176 |
02 | 二分法求函数的零点 | 10 | 2181 |
03 | 矩形分割 | 10 | 1420 |
04 | 网线主管 | 10 | 1648 |
05 | 派 | 10 | 1581 |
06 | 月度开销 | 10 | 1449 |
07 | 和为给定数 | 10 | 1906 |
08 | 不重复地输出数 | 10 | 1790 |
09 | 膨胀的木棍 | 10 | 768 |
10 | 河中跳房子 | 10 | 2027 |
------------------------------萌萌的分割线------------------------------
T1
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#define INF 0x3f3f3f3f
using namespace std; int a[],ans,flag,M,N; int erfen(int x){
int l=,r=N;
while(r-l>){
int mid=l+(r-l)/;
if(a[mid]>=x){
r=mid;
}
else{
l=mid;
}
}
int pos=,cha=INF;
for(int i=l-<?:l-;i<=r+;i++){
if(abs(a[i]-x)<cha){
pos=i;
cha=abs(a[i]-x);
}
}
return a[pos];
} int main(){
// freopen("01.in","r",stdin); memset(a,0x3f,sizeof(a));
scanf("%d",&N);
for(int i=;i<=N;i++){scanf("%d",&a[i]);}
scanf("%d",&M);
while(M--){
int x;scanf("%d",&x);
printf("%d\n",erfen(x));
}
fclose(stdin);fclose(stdout);return ;
}要恶心地多判断几次
T2
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#define INF 0x3f3f3f3f
#define eps 1e-9
using namespace std; int a[],N; double cal(double x){
return x*x*x*x*x-15.0*x*x*x*x+85.0*x*x*x-225.0*x*x+274.0*x-121.0;
} double erfen(double l,double r){
while(r-l>eps){
double mid=(l+r)/2.0;
if(cal(mid)>=){
l=mid;
}
else {
r=mid;
}
}
return l;
} int main(){
// freopen("01.in","r",stdin); printf("%.6f",erfen(1.5,2.4)); fclose(stdin);fclose(stdout);return ;
}l和r别弄反了
T3
T4
T5
T6
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#define INF 0x3f3f3f3f
using namespace std; int a[],M,N,kkk,mx; int solve(){
int ans=,flag=;
for(int i=;i<=N+;i++){
int x=a[i];
if(flag+x>M) flag=x,++ans;
else flag+=x;
}
return ans;
} void erfen(){
int cnt=;
int ans=INF;
int l=mx,r=INF;
while(cnt++< && l!=r){
M=(l+r)/;
int k=solve();
if(k>kkk){
l=M;
}
else{
r=M;
}
if(k<=kkk) ans=min(ans,M);
// cout<<k<<" "<<l<<" "<<r<<endl;
}
cout<<ans;
} int main(){
// freopen("01.in","r",stdin); memset(a,0x3f,sizeof(a));
scanf("%d%d",&N,&kkk);
for(int i=;i<=N;i++){scanf("%d",&a[i]);mx=max(mx,a[i]);} erfen(); fclose(stdin);fclose(stdout);return ;
}这件事告诉我们,一定要写随机数据
随机数据查错非常给力
T7
T8
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#define INF 0x3f3f3f3f
using namespace std; int a[],N; int main(){
// freopen("01.in","r",stdin); scanf("%d",&N);
for(int i=;i<=N;i++) scanf("%d",&a[i]);
sort(a+,a+N+);
for(int i=;i<=N;i++){
if(a[i]!=a[i+]) printf("%d ",a[i]);
} fclose(stdin);fclose(stdout);return ;
}我选择偷懒,吐舌~
T9
T10
噜噜噜~