Zepto Code Rush 2014-A. Feed with Candy(HACK)
2 seconds
256 megabytes
standard input
standard output
The hero of the Cut the Rope game is a little monster named Om Nom. He loves candies. And what a coincidence! He also is the hero of today's problem.

One day, Om Nom visited his friend Evan. Evan has n candies of two types (fruit drops and caramel drops), the i-th
candy hangs at the height of hi centimeters
above the floor of the house, its mass is mi.
Om Nom wants to eat as many candies as possible. At the beginning Om Nom can make at most x centimeter high jumps. When Om Nom eats a candy of mass y,
he gets stronger and the height of his jump increases by y centimeters.
What maximum number of candies can Om Nom eat if he never eats two candies of the same type in a row (Om Nom finds it too boring)?
The first line contains two integers, n and x (1 ≤ n, x ≤ 2000) —
the number of sweets Evan has and the initial height of Om Nom's jump.
Each of the following n lines contains three integers ti, hi, mi (0 ≤ ti ≤ 1; 1 ≤ hi, mi ≤ 2000) —
the type, height and the mass of the i-th candy. If number ti equals
0, then the current candy is a caramel drop, otherwise it is a fruit drop.
Print a single integer — the maximum number of candies Om Nom can eat.
5 3
0 2 4
1 3 1
0 8 3
0 20 10
1 5 5
4
这就easy漏掉一组解。
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvd2p3MDEzMA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">
3 1
0 1 1
1 1 5
0 7 1
答案 3
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
const int N = 2100;
using namespace std; struct node{
int vis,t,h,w;
}g[N];
int cmp(const void *a,const void *b)
{
struct node * X = (struct node *)a;
struct node * Y = (struct node *)b;
return Y->w - X->w;
}
int n,x;
int main()
{
int n,x;
cin>>n>>x;
int xxx = x;
for(int i = 0;i<n;i++)
{
scanf("%d%d%d",&g[i].t,&g[i].h,&g[i].w);
g[i].vis = 0;
}
qsort(g,n,sizeof(g[0]),cmp);
int sum1 = 0,st=0,flag;
for(int ll = 0;ll<n;ll++)
{
for (int k = 0;k < n;k++)
{
if (g[k].vis == 0 && x >= g[k].h)
{
if (st != g[k].t)
{
x += g[k].w;
st = g[k].t;
g[k].vis = 1;
sum1++;
break;
}
}
}
flag = 0;
for(int i = 0;i<n;i++)
{
if(g[i].vis==0 && x>=g[i].h && g[i].t!=st)
flag++;
}
if(flag==0)
break;
}
for(int i = 0;i<n;i++)
g[i].vis = 0;
int sum2 = 0;
st = 1;
for(int ll = 0;ll<n;ll++)
{
for (int k = 0;k < n;k++)
{
if (g[k].vis == 0 && xxx >= g[k].h)
{
if (st != g[k].t)
{
xxx += g[k].w;
st = g[k].t;
g[k].vis = 1;
sum2++;
break;
}
}
}
flag = 0;
for(int i = 0;i<n;i++)
{
if(g[i].vis==0 && xxx>=g[i].h && g[i].t!=st)
flag++;
}
if(flag==0)
break;
}
if(sum1>sum2)
cout<<sum1<<endl;
else
cout<<sum2<<endl;
return 0;
}
Zepto Code Rush 2014-A. Feed with Candy(HACK)的更多相关文章
- Zepto Code Rush 2014 A. Feed with Candy
此题用贪心求解, 首先将caramel drop类别的糖果按照高度从小到大排序,如果高度相同,按照重量从小到大排序 将fruit drop类别的糖果按照高度从小到大排序,如果高度相同,按照重量从小到大 ...
- 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.找到一个序列,使得全部点的权值和最小 ...
- 试试SQLServer 2014的内存优化表(转载)
SQL Server2014存储引擎:行存储引擎,列存储引擎,内存引擎 SQL Server 2014中的内存引擎(代号为Hekaton)将OLTP提升到了新的高度. 现在,存储引擎已整合进当前的数据 ...
- you are not allowed to push code to protected branches on this project(转)
.. 图 1-1 报错:failed to push some refs to 'http://*******.git'. 一痛瞎踅摸之后,远程控制电脑,在H电脑上,重新建立了一个test项目,之后走 ...
- Google Code Pretiffy 代码 着色 高亮 开源 javascript(JS)库
1.简介 introduction Google Code Pretiffy 是 Google 的一个用来对代码进行语法着色的 JavaScript 库,支持 C/C++, Java, Python, ...
- 【leetcode】Candy(python)
题目要求的比它的邻居比自己奖励,因此,我们有最少一个多的.所有我们可以找到所有的坑,凹坑例如,存在以下三种情况. 找到全部的凹点后,我们就能够从凹点处開始向左右两个方向依次查找递增序列.当中每一个高的 ...
随机推荐
- SharePoint通过IP地址访问
问题:SP站点通过计算机名称可以访问,但不能通过IP地址访问 解决方案:打开SharePoint2010管理中心>应用程序管理>配置备用访问映射>编辑公用 URL 备用访问映射集:选 ...
- Data URI scheme:data:image/jpeg;
今天在用一个croppic的jQuery裁剪图片的插件的时候,发现在后台获取图片时,无法通过Request.File获取了,但是通过Request.Form[]可以.用firebug跟了一下发现,图片 ...
- 9.Hierarchy Editor
Hierarchy Editor(层次编辑器) 用于定义3D图层的结构,向Ventuz渲染引擎发出“命令”,并指定命令的发生顺序.通常,每个层次节点都会导致对GPU的一个或多个调用,例如设置材质或渲染 ...
- win32之bitmap篇
先讲一下LoadBitmap的用法,代码如下: PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd,&ps); HDC hMemDC = CreateCompa ...
- win32绘图基础
获取设备环境句柄: (1)WM_PAINT消息中: PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd,&ps); EndPaint(hwnd,&ps ...
- 影响ERP成功实施的因素及实施方法
一.影响ERP实施的因素 1.企业自身管理和认识上的问题.在ERP实施过程中没有用变革管理的理念和方法来策划和管理ERP的实施是导致ERP失败的主要原因. ERP作为一种管理工具他的实施本身就是操作手 ...
- 关于类似vue-cli 脚手架
#!/usr/bin/env node const download = require('download-git-repo') const program = require('commander ...
- dotnetnuke 添加用户属性 Profile
if (DotNetNuke.Entities.Profile.ProfileController.GetPropertyDefinitionByName(this.PortalId, "Q ...
- Lazarus Coolbar and AnchroDocking
在lazarus1.6里加载了AnchroDocking后,Coolbar突然不见了,找了好久没找到,原来在这里! 在AnchroDocking中可能是为了界面的最大化,默认是开始Toolbar 而关 ...
- sql日期提取
--插入数据修改不行:必须提供学号 insert into Student(生日类型) values('阳历') --把月份提取出来 显示两位数 select DATENAME(month,getda ...