Zepto Code Rush 2014 A. Feed with Candy
此题用贪心求解,
首先将caramel drop类别的糖果按照高度从小到大排序,如果高度相同,按照重量从小到大排序
将fruit drop类别的糖果按照高度从小到大排序,如果高度相同,按照重量从小到大排序
现在有两种可能
第一种可能是第一个获得的糖果是caramel drop,
则先搜索caramel drop类别的,然后找到高度小于x的最大高度的index,则在0~index索引之间的高度都小于x,则搜索0~index之间的mass最大的,这样之后高度变得最大,计数值加1,更新x
在搜索fruit drop类别的,然后找到高度小于x的最大高度的index,则在0~index索引之间的高度都小于x,则搜索0~index之间的mass最大的,这样之后高度变得最大,计数值加1,更新x(跟caramel drop类别搜索的一样)
第二种可能是第一个获得的糖果是fruit drop,其搜索过程是上面的两个过程反过来
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring> using namespace std; struct Fruit{
int height;
int mass;
Fruit(int height_ = , int mass_ = ):height(height_),mass(mass_){}
bool operator <(const Fruit& a) const {
if(height != a.height) return height < a.height;
else return mass < a.mass;
}
}; int main(){
int n,x;
cin >> n>>x;
vector<Fruit> fruit[];
for(int i = ; i < n; ++ i){
int t,h,m;
cin >> t >> h >> m;
fruit[t].push_back(Fruit(h,m));
} sort(fruit[].begin(),fruit[].end());
sort(fruit[].begin(),fruit[].end()); int ans = ;
for(int type = ; type < ; ++ type ){
vector<vector<bool> > visit();
for(int i = ; i < fruit[].size(); ++ i) visit[].push_back(false);
for(int i = ; i < fruit[].size(); ++ i) visit[].push_back(false);
int res = ,new_x = x;
bool flag = true;
while(flag){
for(int k = ; k < ; ++ k){
int new_type = (type+k)%, index = fruit[new_type].size()-;
//搜索高度小于new_x的最大高度
for(;index>=; --index){
if(!visit[new_type][index] && fruit[new_type][index].height <= new_x) break;
}
if(index < ) {flag = false;break;}
//在满足条件的高度中搜索质量最大的
int maxMassIndex = index,maxMass = fruit[new_type][index].mass;
for(int i = index -; i >=; -- i){
if(!visit[new_type][i] && fruit[new_type][i].mass > maxMass){
maxMass = fruit[new_type][i].mass ;
maxMassIndex = i;
}
}
index = maxMassIndex;
visit[new_type][index] = true; //标识该糖果已被访问
new_x +=fruit[new_type][index].mass; //更新x
res ++;
}
}
ans = max(ans,res);
}
cout<<ans<<endl;
}
Zepto Code Rush 2014 A. Feed with Candy的更多相关文章
- Zepto Code Rush 2014 B - Om Nom and Spiders
注意题目给的是一个nxm的park,设元素为aij,元素aij 有4种可能U(上移),D(下移),L(左移),R(右移) 假设第i行第j列元素aij(注意元素的索引是从0开始的) 当aij为D时,此时 ...
- Codeforces Zepto Code Rush 2014 -C - Dungeons and Candies
这题给的一个教训:Codeforces没有超时这个概念.本来以为1000*(1000+1)/2*10*10要超时的.结果我想多了. 这题由于k层都可能有关系,所以建一个图,每两个点之间连边,边权为n* ...
- CF Zepto Code Rush 2014 B. Om Nom and Spiders
Om Nom and Spiders time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- Zepto Code Rush 2014——Dungeons and Candies
题目链接 题意: k个点,每一个点都是一个n * m的char型矩阵.对与每一个点,权值为n * m或者找到一个之前的点,取两个矩阵相应位置不同的字符个数乘以w.找到一个序列,使得全部点的权值和最小 ...
- Zepto Code Rush 2014-A. Feed with Candy(HACK)
A. Feed with Candy time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Code Rush插件
code rush 是微软推出的一款VS2008上的插件.他有强大的文件和代码导航功能,易于访问的重构和代码创建功能.一组编辑器.选择.剪贴板工具等. 教程链接 http://www.devexpre ...
- Google Code Jam 2014 Qualification 题解
拿下 ABD, 顺利晋级, 预赛的时候C没有仔细想,推荐C题,一个非常不错的构造题目! A Magic Trick 简单的题目来取得集合的交并 1: #include <iostream> ...
- ZeptoLab Code Rush 2015 C. Om Nom and Candies 暴力
C. Om Nom and Candies Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/526 ...
- Google Code Jam 2014 Round 1 A:Problem C. Proper Shuffle
Problem A permutation of size N is a sequence of N numbers, each between 0 and N-1, where each numbe ...
随机推荐
- Tomcat的Session管理机制
>>Session和Cookie请求的过程 Http连接本身是无状态的,即前一次发起的连接跟后一次没有任何关系,是属于两次独立的连接请求,但是互联网访问基本上都是需要有状态的,即服务器需要 ...
- 【翻译十八】java-并发之锁对象
Lock Objects Synchronized code relies on a simple kind of reentrant lock. This kind of lock is easy ...
- Could not link against boost_system 解决办法
Could not link against boost_system 解决办法: 先安装 libboost-all-dev ./configure --with-incompatible-bdb - ...
- hdu 4035 2011成都赛区网络赛E 概率dp ****
太吊了,反正我不会 /* HDU 4035 dp求期望的题. 题意: 有n个房间,由n-1条隧道连通起来,实际上就形成了一棵树, 从结点1出发,开始走,在每个结点i都有3种可能: 1.被杀死,回到结点 ...
- 初识RPC协议
什么是rpc框架 先回答第一个问题:什么是RPC框架? 如果用一句话概括RPC就是:远程调用框架(Remote Procedure Call) 那什么是远程调用? 通常我们调用一个php中的方法,比如 ...
- C专家编程cdecl
理解所有分析过程的代码段 Page71(中文版) 你可以轻松地编写一个能够分析C语言的声明并把他们翻译成通俗语言的程序.事实上,为什么不?C语言声明的基本形式已经描述清楚.我们所需要的只是编写一段能够 ...
- Java中引用类 strong reference .SoftReference 、 WeakReference 和 PhantomReference的区别
当在 Java 2 平台中首次引入 java.lang.ref 包,其中包含 SoftReference . WeakReference 和 PhantomReference 三个引用类,引用类的 ...
- eclipse文本域内只能输入繁体中文
背景:在文本编辑器下写纯文本时不知怎么回事儿,原来能输入简体字,但过了之后只能输入繁体中文了!我用的是sogou拼音输入法,我检查过,输入法设置的是简体中文,eclipse默认的编码方式是utf-8. ...
- 金融左侧js错误
- windows下cmd操作
进入文件夹:cd 文件夹名 列出文件列表:dir 清屏:cls