zoukankan      html  css  js  c++  java
  • 二分 题目 压缩打包 Special Judge? 不不不 当然不是

    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

     1 #include<iostream>
     2 #include<cstring>
     3 #include<cstdio>
     4 #include<algorithm>
     5 #include<cstdlib>
     6 #define INF 0x3f3f3f3f
     7 using namespace std;
     8 
     9 int a[100005],ans,flag,M,N;
    10 
    11 int erfen(int x){
    12     int l=1,r=N;
    13     while(r-l>1){
    14         int mid=l+(r-l)/2;
    15         if(a[mid]>=x){
    16             r=mid;
    17         }
    18         else{
    19             l=mid;
    20         }
    21     }
    22     int pos=0,cha=INF;
    23     for(int i=l-2<1?1:l-2;i<=r+2;i++){
    24         if(abs(a[i]-x)<cha){
    25             pos=i;
    26             cha=abs(a[i]-x);
    27         }
    28     }
    29     return a[pos];
    30 }
    31 
    32 int main(){
    33 //    freopen("01.in","r",stdin);
    34     
    35     memset(a,0x3f,sizeof(a));
    36     scanf("%d",&N);
    37     for(int i=1;i<=N;i++){scanf("%d",&a[i]);}
    38     scanf("%d",&M);
    39     while(M--){
    40         int x;scanf("%d",&x);
    41         printf("%d
    ",erfen(x));
    42     }
    43     fclose(stdin);fclose(stdout);return 0;
    44 }

    要恶心地多判断几次

    T2

     1 #include<iostream>
     2 #include<cstring>
     3 #include<cstdio>
     4 #include<algorithm>
     5 #include<cstdlib>
     6 #define INF 0x3f3f3f3f
     7 #define eps 1e-9
     8 using namespace std;
     9 
    10 int a[100005],N;
    11 
    12 double cal(double x){
    13     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;
    14 }
    15 
    16 double erfen(double l,double r){
    17     while(r-l>eps){
    18         double mid=(l+r)/2.0;
    19         if(cal(mid)>=0){
    20             l=mid;
    21         }
    22         else {
    23             r=mid;
    24         }
    25     }
    26     return l;
    27 }
    28 
    29 int main(){
    30 //    freopen("01.in","r",stdin);
    31     
    32     printf("%.6f",erfen(1.5,2.4));
    33     
    34     fclose(stdin);fclose(stdout);return 0;
    35 }

    l和r别弄反了

    T3

    T4

    T5

    T6

     1 #include<iostream>
     2 #include<cstring>
     3 #include<cstdio>
     4 #include<algorithm>
     5 #include<cstdlib>
     6 #define INF 0x3f3f3f3f
     7 using namespace std;
     8 
     9 int a[100005],M,N,kkk,mx;
    10 
    11 int solve(){
    12     int ans=0,flag=0;
    13     for(int i=1;i<=N+1;i++){
    14         int x=a[i];
    15         if(flag+x>M) flag=x,++ans;
    16         else flag+=x;
    17     }
    18     return ans;
    19 }
    20 
    21 void erfen(){
    22     int cnt=0;
    23     int ans=INF;
    24     int l=mx,r=INF;
    25     while(cnt++<100 && l!=r){
    26         M=(l+r)/2;
    27         int k=solve();
    28         if(k>kkk){
    29             l=M;
    30         }
    31         else{
    32             r=M;
    33         }
    34         if(k<=kkk) ans=min(ans,M);
    35 //        cout<<k<<" "<<l<<" "<<r<<endl;
    36     }
    37     cout<<ans;
    38 }
    39 
    40 int main(){
    41 //    freopen("01.in","r",stdin);
    42     
    43     memset(a,0x3f,sizeof(a));
    44     scanf("%d%d",&N,&kkk);
    45     for(int i=1;i<=N;i++){scanf("%d",&a[i]);mx=max(mx,a[i]);}
    46     
    47     erfen();
    48     
    49     fclose(stdin);fclose(stdout);return 0;
    50 }

    这件事告诉我们,一定要写随机数据

    随机数据查错非常给力

    T7

    T8

     1 #include<iostream>
     2 #include<cstring>
     3 #include<cstdio>
     4 #include<algorithm>
     5 #include<cstdlib>
     6 #define INF 0x3f3f3f3f
     7 using namespace std;
     8 
     9 int a[100005],N;
    10 
    11 int main(){
    12 //    freopen("01.in","r",stdin);
    13     
    14     scanf("%d",&N);
    15     for(int i=1;i<=N;i++) scanf("%d",&a[i]);
    16     sort(a+1,a+N+1);
    17     for(int i=1;i<=N;i++){
    18         if(a[i]!=a[i+1]) printf("%d ",a[i]);
    19     }
    20     
    21     fclose(stdin);fclose(stdout);return 0;
    22 }

    我选择偷懒,吐舌~

    T9

    T10

    噜噜噜~

  • 相关阅读:
    5.Spring高级装配(根据profile的激活状态决定使用的环境) 以及 条件化 Bean
    4.SpringJunit4ClassRunner
    3.Spring配置可选方案
    2.Spring容器bean的生命周期
    1.使用spring上下文容纳你的Bean
    maven 打包跳过 Junit test
    HTML5中meta name="viewport"
    二、JavaScript this
    VIM_插件
    VBS_DO...Loop
  • 原文地址:https://www.cnblogs.com/radiumlrb/p/6061510.html
Copyright © 2011-2022 走看看