水题 1293: [SCOI2009]生日礼物
来源:互联网 发布:mac压缩软件哪个好 编辑:程序博客网 时间:2024/04/28 21:23
本来想找点单调队列做做。。。。然而这个题并不用。。只要双指针就行了。
#include <bits/stdc++.h>using namespace std;typedef long long LL;const int maxn = 1000000;#define mp(x, y) make_pair(x, y)pair<LL, int> p[maxn];int cnt[105];int n, kk;bool check(int pos){cnt[p[pos].second]--;int ok = 1;for(int i = 1; i <= kk && ok; i++) if(!cnt[i]) ok = 0;if(ok) return true;cnt[p[pos].second]++;return false;}void work(){memset(cnt, 0, sizeof cnt);LL x;int m, a = 0, pos, pos2;for(int i = 1; i <= kk; i++) {scanf("%d", &m);for(int j = 1; j <= m; j++) {scanf("%lld", &x);p[a++] = mp(x, i);}}sort(p, p+a);for(pos = 0; pos < a; pos++) {cnt[p[pos].second]++;int ok = 1;for(int j = 1; j <= kk && ok; j++) if(!cnt[j]) ok = 0;if(ok) break;}LL ans = p[pos].first - p[0].first;for(pos++, pos2 = 0; pos < a; pos++) {cnt[p[pos].second]++;while(check(pos2)) pos2++;ans = min(ans, p[pos].first - p[pos2].first);}printf("%lld\n", ans);}int main(){while(scanf("%d%d", &n, &kk) != EOF) {work();}return 0;}
0 0
- 水题 1293: [SCOI2009]生日礼物
- 【bzoj 1293】[SCOI2009]生日礼物
- bzoj 1293: [SCOI2009]生日礼物
- BZOJ 1293 [SCOI2009] 生日礼物
- 1293: [SCOI2009]生日礼物
- bzoj 1293: [SCOI2009]生日礼物
- BZOJ 1293: [SCOI2009]生日礼物
- BZOJ 1293 SCOI2009 生日礼物 堆
- bzoj 1293: [SCOI2009]生日礼物 暴力
- bzoj 1293: [SCOI2009]生日礼物 STL
- [bzoj-1293][SCOI2009]生日礼物 题解
- [SCOI2009]生日礼物
- [SCOI2009]生日礼物
- 【SCOI2009】生日礼物
- BZOJ 1293 [SCOI2009] 生日礼物 题解与分析
- BZOJ系列1293《[SCOI2009]生日礼物》题解
- 【bzoj 1293】[SCOI2009] 生日礼物 指针维护队列
- bzoj 1293: [SCOI2009]生日礼物 (单调队列)
- 记一次golang 问题的处理
- 通过运行时添加属性小例
- ulua
- C/C++关键字中的extern 和 static
- 6款最新的 jQuery 图片裁剪插件
- 水题 1293: [SCOI2009]生日礼物
- IO流之字节流
- 【UBI】ubi结构与工具参数
- QT事件(1)
- 22. 栈的压入、弹出序列
- php分页原理
- 九度oj 1454
- iOS文本框处理方式的不同
- tomcat配置文件serve.xml的元素及属性详解