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 ...
随机推荐
- 如何在elasticsearch中查看Logstash打到elasticsearch的数据
# cat syslog02.conf #filename:syslog02.conf #注意这个是要用#号注释掉 input{ file{ path => ["/var/log/*. ...
- 《CLR via C#》读书笔记(5)基元类型、引用类型和值类型
5.1 基元类型 编译器直接支持的数据类型称为基元类型(primitive type). 以下4行到吗生成完全相同的IL int a = 0; //最方便的语法 System.Int32 b = 0; ...
- AIX性能监控
http://www.ibm.com/developerworks/cn/aix/library/au-aix7memoryoptimize2/ http://www.aixchina.net/Art ...
- C#关键字params
using System; using System.Threading; namespace Test { /// <summary> /// params用法: 1.用来修饰方法的参数 ...
- Android Matrix
转自 :http://www.cnblogs.com/qiengo/archive/2012/06/30/2570874.html#code Matrix的数学原理 平移变换 旋转变换 缩放变换 错切 ...
- 重温WCF之流与文件传输(七)
WCF开启流模式,主要是设置一个叫TransferMode的属性,所以,你看看哪些Binding的派生类有这个属性就可以了. TransferMode其实是一个举枚,看看它的几个有效值: Buffer ...
- ODATA WEB API(一)---扩展使用
一.概述 时间也算充足,抽点时间总结下OData的常用的使用方式,开放数据协议(OData)是一个查询和更新数据的Web协议.OData应用了web技术如HTTP.Atom发布协议(AtomPub)和 ...
- 针对较大基数的排列组合算法Java实现类(n选m)
package com.utils; import java.math.BigDecimal; import java.math.RoundingMode; public class PLZUUtil ...
- Linux下修改默认字符集--->解决Linux下Java程序种中文文件夹file.isDirectory()判断失败的问题
一.问题描述: 一个项目中为了生成树状目录,调用了file.listFiles()方法,然后利用file.isDirectory()方法判断是否为目录,该程序在windows下运行无问题,在Linux ...
- Oracle优化 -- 关于Database Buffer Cache相关参数DB_CACHE_SIZE的优化设置
select size_for_estimate, buffers_for_estimate ,ESTD_PHYSICAL_READ_factor,ESTD_PHYSICAL_READS from v ...