http://codeforces.com/contest/799/problem/C

题意:

有n做花园,有人有c个硬币,d个钻石 (2 ≤ n ≤ 100 000, 0 ≤ c, d ≤ 100 000) ,每一个花园用三个维度描述(a,b,c),分别是美丽度,所花钱币个数,钱币种类,当然,钱币之间不能兑换,该人必须要建筑两座花园,如果可以,输出两座花园总的美丽度,否则输出0;

思路:

首先想到分三种情况讨论,两个花园都用硬币,两个花园都用钻石,一个用钻石一个用硬币。

大神的代码真的是很厉害,首先买不起直接省去,接下来先按照价格对花园排序,接下来这个for_max写得很强,记录了第i个之前最大的漂亮度。,接下来进行循环,i从0开始++,然后判断是否满足i<j,然后两座花园所需钱币数量小于目前有的钱币数量,如果满足不断使i++,这样做是满足贪心要求,你目前求得必然是在当前j的条件下最大的,最终求出答案。

 #include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
using namespace std; const int maxn=+;
typedef pair<int,int> pll; int n,c,d;
vector<pll> CC,DD;
int for_max[maxn]; int solve(vector<pll> z,int money)
{
int len=z.size();
if(len<) return ;
int ans=;
sort(z.begin(),z.end()); //先按照价格排序
for_max[]=;
for(int i=;i<len;i++) for_max[i+]=max(for_max[i],z[i].second); //预处理,计算出前i个当中最大的漂亮度
int i=;
for(int j=len-;j>=;j--)
{
while(i<j && z[i].first+z[j].first<=money) i++; //因为for_max[i]记录了前i-1个的最大漂亮度,所以只要没超过总价格,就可以一直加上去
i=min(i,j);
if(i>)
ans=max(ans,for_max[i]+z[j].second);
}
return ans;
} int main()
{
//freopen("D:\\input.txt","r",stdin);
while(~scanf("%d%d%d",&n,&c,&d))
{
CC.clear(); DD.clear();
int cc_max=,dd_max=;
int ans=;
int b,p; char s[];
for(int i=;i<n;i++)
{
scanf("%d%d%s",&b,&p,&s);
if(s[]=='C')
{
if(p>c) continue; //买不起的直接省去
CC.push_back(make_pair(p,b));
cc_max=max(cc_max,b);
}
else
{
if(p>d) continue;
DD.push_back(make_pair(p,b));
dd_max=max(dd_max,b);
}
}
if(cc_max!= && dd_max!=) ans=cc_max+dd_max; //第一种情况
ans=max(ans,solve(CC,c)); //两个都是硬币
ans=max(ans,solve(DD,d)); //两个都是钻石
printf("%d\n",ans);
}
return ;
}

另外,树状数组也是可以做的,可以参考http://blog.csdn.net/ssimple_y/article/details/71702915

Codeforces Round #413, rated, Div. 1 + Div. 2 C. Fountains(贪心 or 树状数组)的更多相关文章

  1. 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 ...

  2. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) E. DNA Evolution 树状数组

    E. DNA Evolution 题目连接: http://codeforces.com/contest/828/problem/E Description Everyone knows that D ...

  3. Codeforces Round #365 (Div. 2) D. Mishka and Interesting sum (离线树状数组+前缀xor)

    题目链接:http://codeforces.com/contest/703/problem/D 给你n个数,m次查询,每次查询问你l到r之间出现偶数次的数字xor和是多少. 我们可以先预处理前缀和X ...

  4. Codeforces Round #510 (Div. 2) D. Petya and Array(离散化+反向树状数组)

    http://codeforces.com/contest/1042/problem/D 题意 给一个数组n个元素,求有多少个连续的子序列的和<t (1<=n<=200000,abs ...

  5. VK Cup 2016 - Round 1 (Div. 2 Edition) B. Bear and Displayed Friends 树状数组

    B. Bear and Displayed Friends 题目连接: http://www.codeforces.com/contest/658/problem/B Description Lima ...

  6. CF #365 (Div. 2) D - Mishka and Interesting sum 离线树状数组

    题目链接:CF #365 (Div. 2) D - Mishka and Interesting sum 题意:给出n个数和m个询问,(1 ≤ n, m ≤ 1 000 000) ,问在每个区间里所有 ...

  7. CF #365 (Div. 2) D - Mishka and Interesting sum 离线树状数组(转)

    转载自:http://www.cnblogs.com/icode-girl/p/5744409.html 题目链接:CF #365 (Div. 2) D - Mishka and Interestin ...

  8. Testing Round #12 A,B,C 讨论,贪心,树状数组优化dp

    题目链接:http://codeforces.com/contest/597 A. Divisibility time limit per test 1 second memory limit per ...

  9. 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 ...

随机推荐

  1. .net asp 在1.asp页面嵌入另一个页面2.asp

    <iframe src="http://www.baidu.com" width="100%" height="100%" onloa ...

  2. HDCMS导航高亮显示!解决办法

    第一种方法:(传递class) <channel type='top' row='8' class='cur' > <li class='{$field.class}'> &l ...

  3. rest_framework之频率详解 03

    访问频率(节流) 1.某个用户一分钟之内访问的次数不能超过3次,超过3次则不能访问了,需要等待,过段时间才能再访问. 2.自定义访问频率.两个方法都必须写上. 登入页面的视图加上访问频率 3.返回值F ...

  4. shell 文件备份脚本

    #!/bin/bash #输入参数:文件名 filename=$ #源文件目录 directory=/opt/docker/cloud-driver-training/apps #备份文件目录 bac ...

  5. Powerdesigner逆向工程从sql server数据库生成pdm【转】

    Powerdesigner逆向工程从sql server数据库生成pdm 第一步:打开"控制面板"中的"管理工具" 第二步:点击"管理工具" ...

  6. tensorflow和python操作中的笔记

    前一段时间做了一些项目,把一些笔记放在了txt中,现分享出来,自己也能够时长预习. 1) 读取文件时,将固定的文件地址,采用数组或者字符串的形式,提前表示出来,后期使用时候采用拼接操作 2) # 得到 ...

  7. scrapy爬虫系列之一--scrapy的基本用法

    功能点:scrapy基本使用 爬取网站:传智播客老师 完整代码:https://files.cnblogs.com/files/bookwed/first.zip 主要代码: ff.py # -*- ...

  8. modelform动态显示select标签的对象范围

    既根据当前登录人,动态显示对象相关的的select的选项,例如 A登录,只显示A的客户,B登录,只显示B自己的客户 先了解form的ModelChoiceField字段(这个表格没意义,就是引出参数q ...

  9. python笔记9-多线程Threading之阻塞(join)和守护线程(setDaemon)

    python笔记9-多线程Threading之阻塞(join)和守护线程(setDaemon) 前言 今天小编YOYO请xiaoming和xiaowang吃火锅,吃完火锅的时候会有以下三种场景: - ...

  10. Oracle数据库的经典问题 snapshot too old是什么原因引起的

    Oracle数据库的经典问题 snapshot too old是什么原因引起的 ORACLE经典错误求解:ORA-1555错误(Snapshot too old ) - ... 书上说是因为the r ...