8 条题解

  • 2
    @ 2024-12-17 17:32:05
    #include<bits/stdc++.h>
    using namespace std;
    const int N=1e5+10;
    int L,n,m;
    int a[N],l,r,ans;
    bool check(int mid){
    	int last=0;
    	int sum=0;
    	for(int i=1;i<=n;i++){
    		if(a[i]-last<mid){
    			sum++;
    		}
    		else{
    			last=a[i];
    		}
    	}
    	return sum<=m;
    }
    int main(){
    	cin>>L>>n>>m;
    	for(int i=1;i<=n;i++)
    		cin>>a[i];
    	a[++n]=L;
    	r=L;
    	while(l<=r){
    		int mid=l+r>>1;
    		if(check(mid)){
    			ans=mid;
    			l=mid+1;
    		}
    		else
    			r=mid-1;
    	}
    	cout<<ans;
    
    }
    小鸟
    
    • 2
      @ 2021-12-5 18:04:48
      /*****************************************
      备注:
      ******************************************/
      #include <queue>
      #include <math.h>
      #include <stack>
      #include <stdio.h>
      #include <iostream>
      #include <vector>
      #include <iomanip>
      #include <string.h>
      #include <algorithm>
      using namespace std;
      #define LL long long
      const int N = 1e5 + 10;
      const int INF = 0x3f3f3f3f;
      int main()
      {
      	while(l < r) // 最小值的最大值
      	{
      		int mid = l + r + 1 >> 1;
      		if(cheak(mid))
      			l = mid;
      		else 
      			r = mid -1 ;
      	}
      	cout << l << endl;
      
      
      	while(l < r) // 最大值的最小值
      	{
      		int mid = l + r >> 1;
      		if(cheak(mid))
      			r = mid;
      		else 
      			l = mid + 1;
      	}
      	cout << r << endl;
      
      
      	while(l <= r) // 二分搜索
      	{
      		int mid = l + r >> 1;
      		if(a[mid] == k)
      		{
      			cout << mid ;
      			break;
      		}
      		else if(a[mid] > k) 
      		{
      			r = mid - 1;
      		}
      		else 
      		{
      			l = mid + 1;
      		}
      	}
      	return 0;
      }
      
      • 1
        @ 2022-5-14 11:25:07
        #include <queue>
        #include <math.h>
        #include <stack>
        #include <stdio.h>
        #include <iostream>
        #include <vector>
        #include <iomanip>
        #include <string.h>
        #include <algorithm>
        using namespace std;
        #define LL long long
        const int N = 1e6 + 10;
        const int INF = 0x3f3f3f3f;
        LL a[N];
        LL k, n,m;
        bool cheak(int x)
        {
        	int pre=0;
        	int sum = 0;
        	for(int i=1;i<=n;i++)
        	{
        		if(a[i]-pre<x)
        			sum++;
        		else
        			pre=a[i];
        		if(sum>m)
        			return false; 
        	}
        	return true;
        }
        int find()
        {
        	int l,r;
        	l=1,r=k;
        	while(l<r)
        	{
        		int mid=l+r+1>>1;
        		if(cheak(mid))
        			l=mid;
        		else
        			r=mid-1;
        	}
        	return l;
        }
        int main()
        {
        	cin >>k>>n>>m;
        	for(int i=1;i<=n;i++)
        		scanf("%lld",&a[i]);
        	a[0]=0;
        	a[++n]=k;
        	cout << find()<<endl;
        	return 0; 
        }
        
        
        • 0
          @ 2024-11-3 16:24:56
          /*
          int      %o/%lo 8 %d/%i/%ld/%li 10 %x/%lx 16
          longlong %lld
          float    %f/%e
          double   %lf/%le
          char     %c
          char[]   %s
          'a'=97
          'z'=122
          'A'=65
          'Z'=90
          '0'=48
          '9'=57
          */
          #include <iostream>
          #include <iomanip>
          #include <cmath>
          #include <cstdio>
          #include <cstring>
          #include <algorithm>
          #include <ctime>
          #include <limits>
          #include <assert.h>
          #include <stdlib.h>
          using namespace std;
          #define LL long long
          #define ull unsigned long long
          const int N=1e5+10;
          const int INF=0x3f3f3f3f;
          const double pi=3.1416;
          int L,n,m,a[N],ans,l,r;
          bool check(int mid){
          	int last=0,sum=0;
          	for(int i=1;i<=n;i++){
          		if(a[i]-last<mid){
          			sum++;
          		}else{
          			last=a[i];
          		}
          	}
          	return sum<=m;
          }
          int main(){
          	cin>>L>>n>>m;
          	for(int i=1;i<=n;i++){
          		cin>>a[i];
          	}
          	a[++n]=L;
          	l=1,r=L;
          	while(l<=r){
          		int mid=(l+r)>>1;
          		if(check(mid)){
          			ans=mid;
          			l=mid+1;
          		}else{
          			r=mid-1;
          		}
          	}
          	cout<<ans;
          return 0;
          }
          
          • 0
            @ 2024-7-30 11:17:25

            #include

            #include

            #include

            #include

            #include

            #include

            using namespace std;

            const int N = 5e4 +10;

            const int INF=0x3f3f3f;

            int n,mid,m,a[N],l,r,ans,L;

            bool check(int k){

            int last = 0;

            int sum = 0;

            for(int i = 1;i<=n;i++){

            if(a[i] - last < k)

            sum++;

            else

            last = a[i];

            }

            return sum <= m;

            }

            int main(){

            cin>>L>>n>>m;

            for(int i = 1;i<=n;i++)

            cin>>a[i];

            a[++n] = L;

            r = L;

            while(l<=r){

            int mid = l + r >>1;

            if(check(mid)){

            ans = mid;

            l = mid + 1;

            }

            else

            r = mid - 1;

            }

            cout<<ans;

            }

            • 0
              @ 2024-7-30 11:14:57

              #include <bits/stdc++.h> using namespace std; int L,n,m; const int N=1e5+10; int a[N],l,r,ans; bool check(int mid){ int last = 0; int sum=0; for(int i=1;i<=n;i++) if(a[i]-last<mid){ sum++; } else{ last=a[i]; }

              return sum<=m;
              

              } int main(){ cin>>L>>n>>m; for(int i=1;i<=n;i++){ cin>>a[i]; } a[++n]=L; r=L; while(l<=r){ int mid=l+r>>1; if(check(mid)){ ans=mid; l=mid+1; } else{ r=mid-1; } } cout<<ans; return 0;

              }

              • 0
                @ 2023-5-14 19:31:13
                #include<bits/stdc++.h>
                using namespace std;
                int L,n,m,a[100000];
                int p(int x){
                    int p=0,q=0;
                    for(int i=1;i<=n;i++)
                    if(a[i]-p<x)q++;
                    else p=a[i];
                    return q;
                }
                int main(){
                    cin>>L>>n>>m;
                    for(int i=1;i<=n;i++)
                    cin>>a[i];
                    a[++n]=L;
                    int l=0,r=L;
                    int ans=-111;
                    while(l<=r){
                        int mid=(l+r)/2;
                        int x=p(mid);
                        if(x<=m)l=mid+1,ans=mid;
                        else r=mid-1;
                    }
                    cout<<ans;
                }
                
                • 0
                  @ 2021-12-25 19:46:23
                  /*****************************************
                  备注:
                  ******************************************/
                  #include <queue>
                  #include <math.h>
                  #include <stack>
                  #include <stdio.h>
                  #include <iostream>
                  #include <vector>
                  #include <iomanip>
                  #include <string.h>
                  #include <algorithm>
                  using namespace std;
                  #define LL long long
                  const int N = 1e5 + 10;
                  const int INF = 0x3f3f3f3f;
                  LL n,m,k;
                  LL a[N];
                  bool cheak(int mid)
                  {
                  	int pre=0;
                  	int cnt=0;
                  	for(int i=1;i<=m+1;i++)
                  	{
                  		if(a[i]-pre<mid)
                  		{
                  			cnt++;
                  			if(cnt>k)
                  				return false;
                  		}
                  		else
                  			pre=a[i];
                  	}
                  	return true;
                  }
                  int main()
                  {
                  	cin>>n>>m>>k;
                  	for(int i=1;i<=m;i++)
                  		cin>>a[i];
                  	a[0]=0;
                  	a[m+1]=n;
                  	LL l=1,r=n;
                  	while(l<r)
                  	{
                  		LL mid=l+r+1>>1;
                  		if(cheak(mid))
                  		{
                  			l=mid;
                  		}
                  		else
                  			r=mid-1;	
                  	}
                  	cout<<l<<endl;
                  	return 0;
                  }
                  
                  • 1

                  信息

                  ID
                  755
                  时间
                  1000ms
                  内存
                  128MiB
                  难度
                  6
                  标签
                  递交数
                  596
                  已通过
                  179
                  上传者