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. 【转】Linux下使用locale命令设置语言环境

    转自:http://www.cnblogs.com/dolphi/p/3622570.html locale命令设置语言环境 在Linux中通过locale来设置程序运行的不同语言环境,locale由 ...

  2. C#——数据库的访问

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  3. 转载:使用FileReader对象的readAsDataURL方法来读取图像文件

    文章转载自:http://blog.okbase.net/jquery2000/archive/1296.html: FileReader对象的readAsDataURL方法可以将读取到的文件编码成D ...

  4. [Windows Server 2012] 杰奇CMS安全设置

    ★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com ★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频. ★ 本节我们将带领大家:JIEQI ...

  5. VS2013支持多字节

    使用插件 下载地址:https://www.microsoft.com/zh-cn/search/DownloadResults.aspx?rf=sp&q=mbcs

  6. UICollectionView(一)基本概念

    整体预览 高等级的包含和管理(Top-level containment and management) UICollectionView UICollectionViewController UIC ...

  7. linux中集群的免秘钥SSH直接登录

    这里以三台mysql的主从服务器为例:manage.master.slave1.slave2   给4个机器生成秘钥文件 以manage为例,执行命令,生成空字符串的秘钥(后面要使用公钥),命令是: ...

  8. java关于工作,跳槽之总结

    关于工作中: 如何展示自己项目中的亮点,技术或者难点: 总结我的经历和技术倒是可以,但是我做的项目和我会的技术都很平庸,实在找不到亮点怎么办? 如果知道了你没有亮点,也就是知道了你自己欠缺什么,那么下 ...

  9. ubuntu14.04远程软件VNC的安装、设置方法

    ubuntu中VNCX11開機啟動保持靜默狀態方法: 1首先安裝vncx11. 2.設置vnc密碼,會自動保存在/home/test/.vnc/passwd中 3.將密碼複製到/etc中 4.在/et ...

  10. cshtml中字符串中表示特殊字符@

    用“@@”表示字符串中的特殊字符@