A. Feed with Candy
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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)?

Input

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.

Output

Print a single integer — the maximum number of candies Om Nom can eat.

Sample test(s)
input
5 3
0 2 4
1 3 1
0 8 3
0 20 10
1 5 5
output
4
Note
连续第三次被黑,尽管是一道贪心题目可是。更加注重的是,分类讨论的思想!考察思维的全面性
被黑的地方是,第一次没有依照顺序来,当前状态能吃哪就吃哪个。

这就easy漏掉一组解。

由于本题吃糖的方式仅仅能有两种:01010101... 或 10101010...分类讨论就好啊。。。SB

另外,我试了一下,究竟是不是贪心,于是删掉了。快排函数,WA在第37组,所以不用贪心能够PASS。
以后PASS了,淡定点
据本人连续三次被黑的经验,我弄明确了CFHACK数据的处理方式,每一个人不一样,HACK数据怎么增加后台数据库的?在比赛期间,HACK数据会放在你本人PASS数据库的第一组,在比赛之后,HACK数据后放在你本人数据库的最后一组数据

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

分类讨论:先吃0 那么答案是3,先吃1仅仅能是2
#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)的更多相关文章

  1. Zepto Code Rush 2014 A. Feed with Candy

    此题用贪心求解, 首先将caramel drop类别的糖果按照高度从小到大排序,如果高度相同,按照重量从小到大排序 将fruit drop类别的糖果按照高度从小到大排序,如果高度相同,按照重量从小到大 ...

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

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

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

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

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

  5. Zepto Code Rush 2014——Dungeons and Candies

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

  6. 试试SQLServer 2014的内存优化表(转载)

    SQL Server2014存储引擎:行存储引擎,列存储引擎,内存引擎 SQL Server 2014中的内存引擎(代号为Hekaton)将OLTP提升到了新的高度. 现在,存储引擎已整合进当前的数据 ...

  7. 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项目,之后走 ...

  8. Google Code Pretiffy 代码 着色 高亮 开源 javascript(JS)库

    1.简介 introduction Google Code Pretiffy 是 Google 的一个用来对代码进行语法着色的 JavaScript 库,支持 C/C++, Java, Python, ...

  9. 【leetcode】Candy(python)

    题目要求的比它的邻居比自己奖励,因此,我们有最少一个多的.所有我们可以找到所有的坑,凹坑例如,存在以下三种情况. 找到全部的凹点后,我们就能够从凹点处開始向左右两个方向依次查找递增序列.当中每一个高的 ...

随机推荐

  1. JS中的面相对象

    1.使用Object或对象字面量创建对象 JS中最基本创建对象的方式: var student = new Object(); student.name = "easy"; stu ...

  2. [转]Oracle Client 11g安裝經驗

    本文转自:http://www.dotblogs.com.tw/shadow/archive/2011/11/08/54759.aspx 開發環境:本機(Win XP)的ASP.net 4 WebSi ...

  3. Android 升级安装APK兼容Android7.0,解决FileUriExposedException

    我们在开发app时避免不了需要添加应用内升级功能.当app启动时,如果检测到最新版本,将apk安装包从服务器下载下来,执行安装.安装apk的代码一般写法如下,网上随处可以搜到 public stati ...

  4. 使用WindowBuilder设计Swing程序

    Swing程序表示Java的客户端窗体程序,除了通过手动编写代码的方式设计Swing程序之外,Eclipse中还提供了一种WindowBuilder工具,该工具是一种非常好用的Swing可视化开发工具 ...

  5. 15个最受欢迎的Python开源框架(转)

    原文地址:http://blog.jobbole.com/72306/ Django: Python Web应用开发框架 Django 应该是最出名的Python框架,GAE甚至Erlang都有框架受 ...

  6. 1.CentOS安装Redis

    首要条件:安装VMware,在虚拟机中安装CentOS. 第一次接触CentOS的开发者最好是在虚拟机手动一步步进行安装,并且系统环境选择开发环境,这样可以避免后期自己要安装诸多运行库. 安装步骤: ...

  7. SetACL 使用方法详细参数中文解析

    示例: SetACL.exe c:\nihao /dir /deny everyone /read_ex 设置E:\wxDesktop 文件夹 everyone 用户为读取和运行权限 SetACL M ...

  8. C# 获得Properties下的定义的资源

    var str1 = Properties.Resources.ResourceManager.GetObject("String1", null); string url = S ...

  9. VBA/VBScript提取Word(*.doc)文件中包含的图片(照片)

    VBA/VBScript提取Word(*.doc)文件中包含的图片(照片)   要处理的人事简历表是典型的Word文档,其中一人一份doc,里面包含有个人的照片,如果要把里面的照片复制出来就比较麻烦了 ...

  10. Chromium CEF 2623 -- 支持 xp 的最后一个版本源码下载和编译步骤

    背景 因为项目需要在客户端中内嵌浏览器,需要支持 xp 操作系统和播放视频,但 CEF 2623 以后的版本已经不支持 xp 操作系统,也不再提供 2623 版本的二进制发布包下载,只好自己手动编译. ...