美文网首页
2020-09-15 [TJOI2007]路标设置

2020-09-15 [TJOI2007]路标设置

作者: JalorOo | 来源:发表于2020-09-15 23:08 被阅读0次

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

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <sstream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
using namespace std;

//template<typename DataType>
//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 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<j)quickSort(a,left, j);//继续分治
    if(i<right)quickSort(a,i, right);//继续分治
}


int L,N,K;
int arr[100005];

int Judge(int mid)
{
    int m = 0;
    fi(2,N){
        if(arr[i]-arr[i-1]>=mid)
        {
            m+=(arr[i]-arr[i-1])/mid;
            if((arr[i]-arr[i-1])%mid==0)
                m--;
        }
    }
    if(m > K)
        return 0;
    return 1;
}

int main()
{
    L = read();
    N = read();
    K = read();
    
    fi(1, N){
        arr[i] = read();
    }
    
    int l = 0;//l和r分别代表二分的左边界和右边界
    int r = L;
    while (l < r){//非递归式二分正常向写法,可理解为一般框架
        int mid = (l + r) / 2;//这再看不出是啥意思可以退群了
        if (Judge(mid) == 0){//带入judge函数判断当前解是不是可行解
            l = mid + 1;
        } else {
            r = mid;
        }
    }
    cout << l << endl;//最后的ans绝对是最优解
    return 0;
}
/*
101 2 1
0 101
============
51
*/

相关文章

  • 2020-09-15 [TJOI2007]路标设置

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

  • 交通标志的养护

    交通标志的检查公路标志设置后应认真养护,使其经常保持完整、齐全和鲜明的良好状况。为此,对公路标志除要求进行日常巡视...

  • 道路标线的设置原则

    为了统一的标准要求与大家的共同认知,国家对道路标线做了统一的规定,规定包括道路标线的形式与定义;标线的位置;标线的...

  • 魏城《加纳》

    加纳 作者:魏城 写于2020-09-15 15:00 伦敦 .............................

  • 风格感觉_史蒂芬平克

    写作要点 一节约使用元话语。指标志语言结构的标记性语言,相当于给读者设置路标,比如说第一第二第三。在满是路标的路口...

  • 路标💪

    DO MORE DO BETTER DO EXERCISE I HEAR AND I FORGET I SEE A...

  • 路标Дорожные знаки🚦

    Если вы собираетесь поехать в Китай и управлять автомобил...

  • 路标

    可爱的小牛,咧着嘴微笑 它不会知道,永远都不会知道 明天它会走到哪里 也不会知道明天会吃多少草 它知道的,只有在夜...

  • 路标

    有很多的道路,再走一次才能想起才想起来自己曾经在刻骨铭心的时候经常走着这条路。重新路过此地给自己带来的心里冲击感是...

  • 路标

    你把大地切块, 装进行囊, 行走在时间之海, 岸边响起了沧浪之歌; 你用森林架柴, 燃起篝火, 铺展的大地上有你,...

网友评论

      本文标题:2020-09-15 [TJOI2007]路标设置

      本文链接:https://www.haomeiwen.com/subject/bovqyktx.html