【hihocoder1051】补提交卡——贪心

该博客探讨了如何使用贪心策略解决一个数学问题:在1到100的数列中,有n个断点,给定m个位置可以连续,目标是找到能形成的最长连续区间。博主通过枚举m个位置的左端点来实现解决方案。
摘要由CSDN通过智能技术生成

题目:点击进入

描述:

一个1到100的数列有n个地方是断开的,现给出这n个位置以及一个数m,表示可以使m个位置连续,求可以得到的最长的连续区间的长度,n个位置按照升序给出。

题解:

将起点和终点补充进去之后,必须使这m个位置连续地消除才能使最终长度最长,所以直接枚举这m个位置的左端点即可。

代码:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <ctime>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <climits>
#include <cassert>
#include <cctype>
#include <complex>
#include <algorithm>
#include <string>
#include <iostream>
#include <bitset>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#include <set>
using namespace std;
#define fi first
#define se second
#define MP(A, B) make_pair(A, B)
#define pb push_back
#define gcd __gcd
#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)
typedef long long ll;
typedef unsigned long long ulls;
typedef unsigned int uint;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值