此题用贪心求解,

首先将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. 使用Delphi对象(声明、实例化、构造、释放)

    一.声明和实例化 在使用一个对象之前,用class关键字声明一个对象.可以在一个程序或单元的type部分声明一个对象类型: type TFooObject = class; 除了声明一个对象类型,通常 ...

  2. A-B 练习【大数减法举例】

      A-B Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 题目链接:http://acm.sdut.edu.cn/sdutoj/ ...

  3. 图结构练习——最短路径(dijkstra算法(迪杰斯拉特))

      图结构练习——最短路径 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述  给定一个带权无向图,求节点1到节点n的最短路径.   ...

  4. Introduction to replication 翻译

    翻译自用,还有很多谬误之处,敬请甄别,转载请注明出处 Introduction to replication (replication介绍)   Replication is one of the m ...

  5. SPOJ220 Relevant Phrases of Annihilation(后缀数组)

    引用罗穗骞论文中的话: 先将n 个字符串连起来,中间用不相同的且没有出现在字符串中的字符隔开,求后缀数组.然后二分答案,再将后缀分组.判断的时候,要看是否有一组后缀在每个原来的字符串中至少出现两次,并 ...

  6. 解决postgresql -- ERROR: 42601: query has no destination for result data

    I am learning Npgsql and PostgreSQL. I am unable to define the output parameter correctly. What am I ...

  7. 杂物 python (一)

    python 是一门语言,有各种不同的实现.CPython 即用c语言实现Python及其解释器.

  8. JavaScript - 引用类型

    对象在JavaScript中被称为引用类型的值. 引用类型和传统面向对象设计中的类相似,但实现不同. Object是一个基础类型,其他所有类型都从Object继承了基本的行为. Array类型,Dat ...

  9. Win10 UI线程

    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => UpdateButtonOrientation());

  10. WPF之MVVM(Step3)——使用Prism(1)

    使用WPF-MVVM开发时,自己实现通知接口.DelegateCommand相对来说还是用的较少,我们更多的是使用第三方的MVVM框架,其中微软自身团队提供的就有Prism框架,此框架功能较多,本人现 ...