F-Groundhog Looking Dowdy2020牛客暑期多校训练营(第九场)(尺取法)

F-Groundhog Looking Dowdy2020牛客暑期多校训练营(第九场)
链接:https://ac.nowcoder.com/acm/contest/5674/F
来源:牛客网

Groundhog finds that Apple seems to be less intimate than before.

He is very distressed for this.After pondering for a long time, Groundhog finds that he looks too dowdy.So, Groundhog decided to improve a little.

Because Groundhog is lazy, he only lists the clothes that can be worn for the next {n}n days. On the i-th day, the j-th
clothes have a dowdiness a(i,j).On each day,he will choose one of the clothes and wear it.

And Groundhog should choose {m}m days from {n}n days to go out with Apple.

Groundhog wants to know the minimum difference between the maximum dowdiness and the minimum dowdiness in {m}m days when Groundhog’s choice is optimal.

Simplified: You should choose n clothes for each day and then choose m clothes from those n clothes, and the problem is to calculate the minimum difference between the maximum dowdiness and the minimum dowdiness.
F-Groundhog Looking Dowdy2020牛客暑期多校训练营(第九场)(尺取法)_第1张图片

输入

4 3
1 3
2 8 6
1 2
3 1 7 5

输出

2

说明

Apple will pay attention to Groundhog’s clothes on day 1, 3, and 4
,Groundhog will wear clothes with dowdiness of 3, 2, and 1 on day 1,
3, and 4,and the difference is 2.

题意:
有n天,每天土拨鼠有一些衣服可以穿。
其中mm天他要出去见Apple,因此他希望穿一些更特别的衣服。每件衣服都有一个dowdiness不时髦度。
现在土拨鼠希望对于任意的m天每天找到一件衣服使得选出的这些衣服中dowdiness的最大值和最小值的差的最小值。
题解:
知识点:尺取法
用滑动模块去做,把全部衣服的dowdiness值从小到大排序,然后用尺取法从小到大去找最小的模块,条件是要满足m天。
Code:

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define ll __int128
using namespace std;
const int INF=0x3f3f3f3f;
const double pi=acos(-1.0),eps=1e-8;
struct node
{
    int id;
    int val;
} num[2000005];
bool cmp(node a,node b)
{
    return a.val

你可能感兴趣的:(2020牛客多校训练)