此题用贪心求解,

首先将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的更多相关文章

  1. Zepto Code Rush 2014 B - Om Nom and Spiders

    注意题目给的是一个nxm的park,设元素为aij,元素aij 有4种可能U(上移),D(下移),L(左移),R(右移) 假设第i行第j列元素aij(注意元素的索引是从0开始的) 当aij为D时,此时 ...

  2. Codeforces Zepto Code Rush 2014 -C - Dungeons and Candies

    这题给的一个教训:Codeforces没有超时这个概念.本来以为1000*(1000+1)/2*10*10要超时的.结果我想多了. 这题由于k层都可能有关系,所以建一个图,每两个点之间连边,边权为n* ...

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

  4. Zepto Code Rush 2014——Dungeons and Candies

    题目链接 题意: k个点,每一个点都是一个n * m的char型矩阵.对与每一个点,权值为n * m或者找到一个之前的点,取两个矩阵相应位置不同的字符个数乘以w.找到一个序列,使得全部点的权值和最小 ...

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

  6. Code Rush插件

    code rush 是微软推出的一款VS2008上的插件.他有强大的文件和代码导航功能,易于访问的重构和代码创建功能.一组编辑器.选择.剪贴板工具等. 教程链接 http://www.devexpre ...

  7. Google Code Jam 2014 Qualification 题解

    拿下 ABD, 顺利晋级, 预赛的时候C没有仔细想,推荐C题,一个非常不错的构造题目! A Magic Trick 简单的题目来取得集合的交并 1: #include <iostream> ...

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

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

随机推荐

  1. drozer unknown module处理办法

    将目录切换到drozer安装目录,然后在执行:

  2. MVC缓存02,使用数据层缓存,添加或修改时让缓存失效

    在"MVC缓存01,使用控制器缓存或数据层缓存"中,在数据层中可以设置缓存的有效时间.但这个还不够"智能",常常希望在编辑或创建的时候使缓存失效,加载新的数据. ...

  3. 与你相遇好幸运,Sail.js其他字段查询

    query: function (req, res) {    var par = req.query;    for(var key in par){      var options = {};  ...

  4. Logcat打印调试信息

    Android Logcat调试中的V.D.I.W.E的分别代表什么? Log.v -- 黑色 -- verbose infoLog.d -- 蓝色 -- debug infoLog.i -- 绿色 ...

  5. Java代码实现excel数据导入到Oracle

    1.首先需要两个jar包jxl.jar,ojdbc.jar(注意版本,版本不合适会报版本错误)2.代码: Java代码   import java.io.File; import java.io.Fi ...

  6. Linux进程状态 ( Linux Process State Codes)

    进程状态代码及说明: STATE代码 说明 D 不可中断的睡眠. 通常是处于I/O之中. R 运行中/可运行. 正处于运行队列中. S 可中断的睡眠. 等待某事件发生. T 已停止. 可能是因为she ...

  7. 新浪微博的账号登录及api操作

    .sina.php <?php /** * PHP Library for weibo.com * * @author */ class sinaPHP { function __constru ...

  8. hibernate base

    第一个类:Person.java package org.crazyit.app.domain; import java.io.Serializable;import java.util.ArrayL ...

  9. "Project facet Java version 1.7 is not supported"的问题解决的办法

    问题描述 在eclipse中,从SVN中检出project代码,拖拽式部署到local server中的时候,报出以下错误: 问题分析 问题产生的原因是,SVN中的代码是采用java 1.7开发编译的 ...

  10. JS自定义属性兼容

    var obj={}; if(obj.dataset){ obj.dataset.original="11"; }else{ obj.getAttribute("data ...