2020-09-16 数列分段 Section II

https://www.luogu.com.cn/problem/P1182

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;

//template
//DataType qmi(DataType m, int k)
//{
//    DataType res = 1, t = m;
//    while (k)
//    {
//        if (k&1) res = res * t;
//        t = t * t;
//        k >>= 1;
//    }
//    return res;
//}


int qmi(int m, int k)
{
    int res = 1, t = m;
    while (k)
    {
        if (k&1) res = res * t;
        t = t * t;
        k >>= 1;
    }
    return res;
}

int read(){
    int x = 0,f = 1;
    char c = getchar();
    while (c<'0'||c>'9') {
        if (c=='-') {
            f = -1;
        }
        c = getchar();
    }
    while (c>='0'&&c<='9') {
        x = x*10+c-'0';
        c = getchar();
    }
    return x*f;
}

#define fi(a,b) for(int i = a; i < b; i++)
#define fie(a,b) for(int i = a; i <= b; i++)
#define fj(a,b) for(int j = a; j >= b; j--)

struct priceAndCnt{
    int price,cnt;
};

void quickSort(priceAndCnt *a,int left,int right){
    int i,j;
    
    priceAndCnt temp,t;
    
    temp = a[(left+right)/2];//基准值
    
    i = left;
    j = right;
    
    while(i<=j){
        while (a[j].price > temp.price) {
            j--;
        }
        
        while (a[i].price < temp.price) {
            i++;
        }
        
        if (i<=j) {
            t = a[i];
            a[i] = a[j];
            a[j] = t;
            //继续下一步
            i++;
            j--;
        }
    }
    
    if(left=m;//返回结果}
}

int main()
{
    n = read();
    m = read();
    int a[n];//这个要慎用,c99里面才可以的
    fi(0, n){
        a[i] = read();
        rig += a[i];//每次都把right累积起来,变成所有数之和
        lef = lef>a[i] ? lef : a[i];//left就是所有数中最大的那个
        //似乎left和right之前解释过了哦
    }
    
    while (lef <= rig){//非递归式二分正常向写法,可理解为一般框架
        int mid = (lef + rig) / 2;//这再看不出是啥意思可以退群了
        total = 0;
        tim = 0;
        if (Judge(mid,a)){//带入judge函数判断当前解是不是可行解
            lef = mid + 1;
        } else {
            rig = mid - 1;
        }
    }
    cout<

你可能感兴趣的:(2020-09-16 数列分段 Section II)