[HIHO1051]补提交卡(枚举,贪心)
2016-06-09 12:08
357 查看
题目链接:http://hihocoder.com/problemset/problem/1051
思路:先排序,然后枚举连续的长度为m的子段,用这个段之后的第一个天数减去这个段之前的第一个天数再-1就是把这个区间全填上后的连续提交天数。
思路:先排序,然后枚举连续的长度为m的子段,用这个段之后的第一个天数减去这个段之前的第一个天数再-1就是把这个区间全填上后的连续提交天数。
/* ━━━━━┒ギリギリ♂ eye! ┓┏┓┏┓┃キリキリ♂ mind! ┛┗┛┗┛┃\○/ ┓┏┓┏┓┃ / ┛┗┛┗┛┃ノ) ┓┏┓┏┓┃ ┛┗┛┗┛┃ ┓┏┓┏┓┃ ┛┗┛┗┛┃ ┓┏┓┏┓┃ ┛┗┛┗┛┃ ┓┏┓┏┓┃ ┃┃┃┃┃┃ ┻┻┻┻┻┻ */ #include <algorithm> #include <iostream> #include <iomanip> #include <cstring> #include <climits> #include <complex> #include <fstream> #include <cassert> #include <cstdio> #include <bitset> #include <vector> #include <deque> #include <queue> #include <stack> #include <ctime> #include <set> #include <map> #include <cmath> using namespace std; #define fr first #define sc second #define cl clear #define BUG puts("here!!!") #define W(a) while(a--) #define pb(a) push_back(a) #define Rint(a) scanf("%d", &a) #define Rll(a) scanf("%I64d", &a) #define Rs(a) scanf("%s", a) #define Cin(a) cin >> a #define FRead() freopen("in", "r", stdin) #define FWrite() freopen("out", "w", stdout) #define Rep(i, len) for(LL i = 0; i < (len); i++) #define For(i, a, len) for(LL i = (a); i < (len); i++) #define Cls(a) memset((a), 0, sizeof(a)) #define Clr(a, x) memset((a), (x), sizeof(a)) #define Fuint(a) memset((a), 0x7f7f, sizeof(a)) #define lrt rt << 1 #define rrt rt << 1 | 1 #define pi 3.14159265359 #define RT return #define lowbit(x) x & (-x) #define onenum(x) __builtin_popcount(x) typedef long long LL; typedef long double LD; typedef unsigned long long Uint; typedef pair<LL, LL> pii; typedef pair<string, LL> psi; typedef map<string, LL> msi; typedef vector<LL> vi; typedef vector<LL> vl; typedef vector<vl> vvl; typedef vector<bool> vb; const int maxn = 110; int n, m; int a[maxn]; int G[maxn][maxn]; int main() { // FRead(); int T; Rint(T); W(T) { Cls(G); Cls(a); Rint(n); Rint(m); For(i, 1, n+1) Rint(a[i]); if(m >= n) { printf("100\n"); continue; } sort(a+1, a+n+1); int ret = 0; for(int i = 1; i <= n - m + 1; i++) { int j = i + m - 1; int tmp = a[j+1] - a[i-1] - 1; ret = max(ret, tmp); } printf("%d\n", ret); } RT 0; }
相关文章推荐
- 位运算
- 大话数据结构—栈与队列
- Document.body.scrollTop的值总为零的快速解决办法
- C#中图片、二进制与字符串的相互转换方法
- Java设计模式之命令模式
- asp.net基础-http运行期执行概述
- Style actionbar background 3.0
- 二叉树中找两个结点的最近的公共祖先结点
- NetOS 及 NetOS 企业版/教育版正式发布
- javascript常用互动方法
- foreach的原理
- L3-007. 天梯地图
- 使用hadoop mapreduce分析mongodb数据:(1)
- Python 各种测试框架简介(一):doctest
- mysql下优化表和修复表命令使用说明(REPAIR TABLE和OPTIMIZE TABLE)
- matlab 可视化 —— axis
- 一个32岁入门的70后程序员给我的启示
- iOS应用发布篇一(开发者账号申请)
- 函数popen()
- 服务器nginx+nodejs配置