2794: [Poi2012]Cloakroom
来源:互联网 发布:音频剪辑软件下载 编辑:程序博客网 时间:2024/05/29 02:20
2794: [Poi2012]Cloakroom
Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 231 Solved: 155
[Submit][Status][Discuss]
Description
有n件物品,每件物品有三个属性a[i], b[i], c[i] (a[i]<b[i])。
再给出q个询问,每个询问由非负整数m, k, s组成,问是否能够选出某些物品使得:
1. 对于每个选的物品i,满足a[i]<=m且b[i]>m+s。
2. 所有选出物品的c[i]的和正好是k。
Input
第一行一个正整数n (n<=1,000),接下来n行每行三个正整数,分别表示c[i], a[i], b[i] (c[i]<=1,000, 1<=a[i]<b[i]<=10^9)。
下面一行一个正整数q (q<=1,000,000),接下来q行每行三个非负整数m, k, s (1<=m<=10^9, 1<=k<=100,000, 0<=s<=10^9)。
Output
输出q行,每行为TAK (yes)或NIE (no),第i行对应第i此询问的答案。
Sample Input
5
6 2 7
5 4 9
1 2 4
2 5 8
1 3 9
5
2 7 1
2 7 2
3 2 0
5 7 2
4 1 5
6 2 7
5 4 9
1 2 4
2 5 8
1 3 9
5
2 7 1
2 7 2
3 2 0
5 7 2
4 1 5
Sample Output
TAK
NIE
TAK
TAK
NIE
NIE
TAK
TAK
NIE
HINT
Source
鸣谢Oimaster
#include<iostream>#include<cstdio>#include<algorithm>#include<cmath>#include<cstring>#include<vector>#include<queue>#include<set>#include<map>#include<stack>#include<bitset>#include<ext/pb_ds/priority_queue.hpp>using namespace std;const int maxn = 1E3 + 10;const int maxm = 1E6 + 10;const int N = 100001;struct data{int a,b,c; data(){}data(int a,int b,int c): a(a),b(b),c(c){}bool operator < (const data &B) const {return a < B.a;}}D[maxn];struct Query{int m,k,s,Num; Query(){}Query(int m,int k,int s,int Num): m(m),k(k),s(s),Num(Num){}bool operator < (const Query &B) const {return m < B.m;}}Q[maxm];int n,m,Max,f[N];bool Ans[maxm];void Insert(int g){for (int i = Max; i >= D[g].c; i--)if (f[i - D[g].c]) f[i] = max(f[i],min(f[i - D[g].c],D[g].b));}int getint(){char ch = getchar(); int ret = 0;while (ch < '0' || '9' < ch) ch = getchar();while ('0' <= ch && ch <= '9')ret = ret*10 + ch - '0',ch = getchar();return ret;}int main(){#ifdef DMCfreopen("DMC.txt","r",stdin);#endifn = getint();for (int i = 1; i <= n; i++){int c = getint(),a,b;a = getint(); b = getint();D[i] = data(a,b,c);}sort(D + 1,D + n + 1);m = getint();for (int i = 1; i <= m; i++){int m = getint(),k,s;k = getint(); s = getint();Q[i] = Query(m,k,s,i);Max = max(Max,k);}sort(Q + 1,Q + m + 1);int now = 1; f[0] = ~0U>>1;for (int i = 1; i <= m; i++){while (now <= n && Q[i].m >= D[now].a) Insert(now++);Ans[Q[i].Num] = f[Q[i].k] > Q[i].m + Q[i].s ? 1 : 0;}for (int i = 1; i <= m; i++)if (Ans[i]) puts("TAK"); else puts("NIE");return 0;}
0 0
- 2794: [Poi2012]Cloakroom
- bzoj 2794 [Poi2012]Cloakroom dp
- BZOJ 2794: [Poi2012]Cloakroom 背包DP
- BZOJ2794: [Poi2012]Cloakroom
- BZOJ2794 [Poi2012]Cloakroom
- BZOJ2794/POI2012 Cloakroom
- BZOJ2794: [Poi2012]Cloakroom
- BZOJ 2794: [Poi2012]Cloakroom 询问离线 背包dp
- bzoj2794 [Poi2012]Cloakroom ( 背包DP+离线 )
- [POI 2012]Cloakroom(DP)
- POI2012题解
- [Poi2012]Festival
- BZOJ 2789: [Poi2012]Letters
- BZOJ2793 [Poi2012]Vouchers 调和级数
- [BZOJ 2790]POI2012 Distance
- [BZOJ 2789]POI2012 Letters
- [BZOJ 2791]POI2012 Rendezvous
- [BZOJ 2803]Poi2012 Prefixuffix
- 七牛 直播的延迟与优化
- akka学习教程(六) 路由器Router
- 设计模式深入学习--Template Method模板方法模式(行为型模式)
- MySQL 在线开启/关闭GTID
- hibernate的一次简单执行过程
- 2794: [Poi2012]Cloakroom
- 修改Android签名证书keystore作为eclipse默认debug签名证书
- vSphere Client 不能编译版本为10 或更高版本 的虚拟机
- WebGL 3D 数百个 HTML5 例子学习 HT 图形组件
- 百度富文本框ueditor使用教程
- [RK3288][Android6.0] 调试笔记 --- 普通串口的添加
- Qt获取打开,保存文件路径
- 交换排序—快速排序(Quick Sort)
- Java中无参带返回值的使用