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 ...
随机推荐
- 解决Pyqt打包后运行报错:应用程序无法启动 因为程序的并行配置不正确
做了一个生成二维码的小程序:http://www.cnblogs.com/dcb3688/p/4241048.html 直接运行脚本没问题,用pyinstaller打包后再运行就直接报错了: 应用程序 ...
- C#在excel中添加超链接
1.新建一个项目 2.给项目添加引用:Microsoft Excel 12.0 Object Library (2007版本) using Excel = Microsoft.Office.Inter ...
- HTTPCLIENT 学习 (1) 入门
早就如雷贯耳它的大名,却一直不曾相见,昨天下载下来,今天终于测试了一把,用的官网的QUICK START例子,来访问我自己以前开发过的WEB程序,因为这个网站恰好有一个写好的通过POST请求验证用户名 ...
- PHP+Nginx环境搭配
一.Nginx安装 nginx可以使用各平台的默认包来安装,本文是介绍使用源码编译安装,包括具体的编译参数信息. 正式开始前,编译环境gcc g++ 开发库之类的需要提前装好,这里默认你已经装好. u ...
- NPOI 通用导出数据到Excel 分类: C# Helper 2014-11-04 16:06 246人阅读 评论(0) 收藏
应用场景: 在项目中,经常遇到将数据库数据导出到Excel,针对这种情况做了个程序封装.工作原理:利用NPOI将SQL语句查询出的DataTable数据导出到Excel,所见即所得. 程序界面: ...
- WPF ItemsControl ListBox ListView比较
在进行列表信息展示时,WPF中提供多种列表可供选择.这篇博客将对WPF ItemsControl, ListBox, ListView进行比较. 相同点: 1. 这三个控件都是列表型控件,可以进行列表 ...
- php随机生成验证码
我们经常需要服务器向前端发送验证码,验证码需要随机产生,下面的用简单的代码实现了这一过程: <?php $pool='0123456789abcdefghijklmnopqrstuvwxyzAB ...
- C语言判断文件是否存在(转)
int access(const char *filename, int amode); amode参数为0时表示检查文件的存在性,如果文件存在,返回0,不存在,返回-1. 这个函 ...
- Codeforces Round #103 (Div. 2) D. Missile Silos(spfa + 枚举边)
题目链接:http://codeforces.com/problemset/problem/144/D 思路:首先spfa求出中心点S到其余每个顶点的距离,统计各顶点到中心点的距离为L的点,然后就是要 ...
- loj 1271
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=26981 思路:题目的意思是求给定的起点到终点的最短路径序列,并且这 ...