分几种情况讨论:

(1)仅用C或D买两个

  ①买两个代价相同的(实际不同)(排个序)

  ②买两个代价不同的(因为买两个代价相同的情况已经考虑过了,所以此时对于同一个代价,只需要保存美丽度最高的喷泉即可)(预处理b[i],表示代价小于等于i的物品中,美丽度最大的是多少。为了防止重复购买,枚举其中一个,然后另一个只买代价小于其代价的物品。)

(2)用C和D各买一个

按这几种情况分类,可以比较好地避免买到同一个喷泉的情况。

#include<cstdio>
#include<algorithm>
using namespace std;
int n,c,d,b[100010],p[100010];
char op[100010][3];
struct data{
int v,c;
}a1[100010],a2[100010];
int b1[100010],b2[100010];
bool operator < (const data &a,const data &b){
return a.c!=b.c ? a.c<b.c : a.v<b.v;
}
int ans=0;
int main(){
// freopen("c.in","r",stdin);
scanf("%d%d%d",&n,&c,&d);
int m1=0,m2=0;
for(int i=1;i<=n;++i){
scanf("%d%d%s",&b[i],&p[i],op[i]);
if(op[i][0]=='C'){
a1[++m1]=(data){b[i],p[i]};
}
else{
a2[++m2]=(data){b[i],p[i]};
}
}
sort(a1+1,a1+m1+1);
for(int i=2;i<=m1;++i){
if(a1[i].c==a1[i-1].c && a1[i].c*2<=c){
ans=max(ans,a1[i].v+a1[i-1].v);
}
}
for(int i=1;i<=m1;++i){
b1[a1[i].c]=max(b1[a1[i].c],a1[i].v);
}
for(int i=1;i<=c;++i){
b1[i]=max(b1[i],b1[i-1]);
}
for(int i=1;i<=m1;++i){
if(a1[i].c<=c && b1[min(c-a1[i].c,a1[i].c)-(a1[i].c<=c-a1[i].c)]){
ans=max(ans,a1[i].v+b1[min(c-a1[i].c,a1[i].c)-(a1[i].c<=c-a1[i].c)]);
}
} sort(a2+1,a2+m2+1);
for(int i=2;i<=m2;++i){
if(a2[i].c==a2[i-1].c && a2[i].c*2<=d){
ans=max(ans,a2[i].v+a2[i-1].v);
}
}
for(int i=1;i<=m2;++i){
b2[a2[i].c]=max(b2[a2[i].c],a2[i].v);
}
for(int i=1;i<=d;++i){
b2[i]=max(b2[i],b2[i-1]);
}
for(int i=1;i<=m2;++i){
if(a2[i].c<=d && b2[min(d-a2[i].c,a2[i].c)-(a2[i].c<=d-a2[i].c)]){
ans=max(ans,a2[i].v+b2[min(d-a2[i].c,a2[i].c)-(a2[i].c<=d-a2[i].c)]);
}
} if(b1[c] && b2[d]){
ans=max(ans,b1[c]+b2[d]);
} printf("%d\n",ans);
return 0;
}

【预处理】【分类讨论】Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C. Fountains的更多相关文章

  1. Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2)(A.暴力,B.优先队列,C.dp乱搞)

    A. Carrot Cakes time limit per test:1 second memory limit per test:256 megabytes input:standard inpu ...

  2. C.Fountains(Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2)+线段树+RMQ)

    题目链接:http://codeforces.com/contest/799/problem/C 题目: 题意: 给你n种喷泉的价格和漂亮值,这n种喷泉题目指定用钻石或现金支付(分别用D和C表示),C ...

  3. Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C. Fountains 【树状数组维护区间最大值】

    题目传送门:http://codeforces.com/contest/799/problem/C C. Fountains time limit per test 2 seconds memory ...

  4. Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) 一夜回到小学生

    我从来没想过自己可以被支配的这么惨,大神讲这个场不容易掉分的啊 A. Carrot Cakes time limit per test 1 second memory limit per test 2 ...

  5. Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) E - Aquarium decoration 贪心 + 平衡树

    E - Aquarium decoration 枚举两个人都喜欢的个数,就能得到单个喜欢的个数,然后用平衡树维护前k大的和. #include<bits/stdc++.h> #define ...

  6. 【动态规划】【滚动数组】【搜索】Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) D. Field expansion

    显然将扩张按从大到小排序之后,只有不超过前34个有效. d[i][j]表示使用前i个扩张,当length为j时,所能得到的最大的width是多少. 然后用二重循环更新即可, d[i][j*A[i]]= ...

  7. 树状数组 Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C. Fountains

    C. Fountains time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  8. Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) D. Field expansion

    D. Field expansion time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  9. Codeforces Round #413, rated, Div. 1 + Div. 2 C. Fountains(贪心 or 树状数组)

    http://codeforces.com/contest/799/problem/C 题意: 有n做花园,有人有c个硬币,d个钻石 (2 ≤ n ≤ 100 000, 0 ≤ c, d ≤ 100  ...

随机推荐

  1. FileReader 与canvas结合使用显示图片

    话不多少,直接上代码 function fileChange() { var file = this.files[0]; var imageType = /^image\//; //是否是图片 if ...

  2. CSS 竖线颜色渐变

    <!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"& ...

  3. Centos 7 安装jdk1.7

    在linux中安装jdk是很平凡的事情了,刚学习linux给自己留下一笔记.刚安装centos其中可以会附带jdk,但是这并不影响,只要下载自己的jdk然后替换相对应的环境变量即可. 1.下载相对应的 ...

  4. CursorFileManager对cursor文件的读写

    public class CursorFileManager implements CursorManager{public void write(String key, LongCursor cur ...

  5. ubuntu下调整cpu频率

    环境:ubuntu15.10 查看内核支持的cpu策略 cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors 比如我 ...

  6. [Leetcode Week14]Construct Binary Tree from Inorder and Postorder Traversal

    Construct Binary Tree from Inorder and Postorder Traversal 题解 原创文章,拒绝转载 题目来源:https://leetcode.com/pr ...

  7. selenium 点击浏览器按钮

    利用以下的方法,selenium 也可以模拟点击各种浏览器按钮:browser.back()点击“返回”按钮.browser.forward()点击“前进”按钮.browser.refresh()点击 ...

  8. c++设计模式系列----factory模式

    问题: 假设我们要开发一个游戏--打怪物,首先,游戏有分等级,假设有初级,中级两个个等级(就不用flappy bird模式了,那个比较特殊,对一个玩家来说是难以具有持久吸引力的!),不同的等级怪物也是 ...

  9. 广度优先搜索--POJ迷宫问题

    Description 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, ...

  10. hadoop 安装 错误及解决方法

    1.ssh 相关问题: rm ~/.ssh/known_hosts //与ssh中的不服 //再重新生成密钥 2.ERROR namenode.NameNode: java.io.IOExceptio ...