分几种情况讨论:

(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. 大聊Python----quene队列

    当必须在多个线程之间安全地交换信息时,队列在线程编程中特别有用. class queue.Queue(maxsize=0)  # 先入先出class queue.LifoQueue(maxsize=0 ...

  2. JAVA Frame 响应窗口关闭事件

    /* * To change this license header, choose License Headers in Project Properties. * To change this t ...

  3. 3.0docker操作

    登录镜像资源 docker login daocloud.io username: password: docker login : 登陆到一个Docker镜像仓库,如果未指定镜像仓库地址,默认为官方 ...

  4. MSF爆破MSSQL

    show options: msf auxiliary(scanner/mssql/mssql_login) > show options Module options (auxiliary/s ...

  5. 【Python学习笔记】多版本python使用pip安装第三方库

    不知道是不是有人跟我一样,一直Python2与Python3混着用,然而在cmd中默认的Python版本只有一种,使用 pip install xxx(第三方库名)  只会安装到默认版本上. 而如果需 ...

  6. 为什么Windows7打开项目的方式是灰的不能修改

    http://jingyan.baidu.com/article/d3b74d64a964691f77e60900.html 进入组策略编辑器,即运行gpedit.msc,进入“用户配置”-“管理模板 ...

  7. iOS 适配/ autoLayout基本知识

    历史 iPhone3GS.iPhone4\4s:没有屏幕适配最早开发里面的程序全部都是写死的 iPad 旋转出来之后 Autoresizing问世iPhone5\5c\5s兼容各种不同的情况 系统适配 ...

  8. c#中char、string转换为十六进制byte的浅析

    问题引出: string转换为byte(十六进制) static void Main(string[] args) { "; byte[] b = Encoding.Default.GetB ...

  9. django-1366, "Incorrect string value: '\\xE6\\x88\\x9A\\xE4\\xBC\\x9F...'

    今天把之前的一些代码转移到另外一台电脑的时候, python manage.py syncdb 的时候报了 (1366, "Incorrect string value: '\\xE6\\x ...

  10. html添加新元素兼容和访问

    <!DOCTYPE html> <html> <head> <title>Creating an HTML Element</title> ...