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)
题目要求的比它的邻居比自己奖励,因此,我们有最少一个多的.所有我们可以找到所有的坑,凹坑例如,存在以下三种情况. 找到全部的凹点后,我们就能够从凹点处開始向左右两个方向依次查找递增序列.当中每一个高的 ...
随机推荐
- Codeforces Round #419
A Karen and Morning 找最近的回文时间 模拟 往后推 判判就行 //By SiriusRen #include <bits/stdc++.h> using namesp ...
- ACM_圆的面积
圆的面积 Time Limit: 2000/1000ms (Java/Others) Problem Description: AB是圆O的一条直径,CD.EF是两条垂直于AB的弦,并且以CD为直径的 ...
- cmd bat 相对命令
"%~dp0",在BAT中,是不是“相对路径”的意思 (2013-08-21 12:19:32) 转载▼ 标签: 杂谈 分类: C# 0念 零 ,代表你的批处理本身. d p是FO ...
- asp.net MVC 给Controler传一个JSon集合,后台通过List<Model>接收
需求情景 View层经常需要通过Ajax像后台发送一个json对象的集合,但是在后台通过List<Model>无法接收,最后只能通过妥协的方式,在后台获取一个json的字符串,然后通过Js ...
- Leetcode0143--Reorder List 链表重排
[转载请注明]https://www.cnblogs.com/igoslly/p/9351564.html 具体的图示可查看 链接 代码一 /** * Definition for singly-li ...
- 剔除重复jar包,查找重复类
作为程序员,没有遇到过jar包冲突,不是你幸运,就是你还年轻. jar包冲突有着无穷的魔力,一提到就会有说不完的怨愤,道不清的忧伤,这都是内伤.jar 包冲突就像深藏地底的地雷,看上去平常无奇,一切是 ...
- 2015.12.20-2015.12.25 大论文迭代 A
进一步充实大论文内容.结构,完善一遍大论文 12.20周天,完成论文第五章总结部分,和第一章的修改 12.21周一,完成论文第二章的修改充实 12.22周二,完成论文第三章的修改充实 12.23周三, ...
- ABP初始化
默认认为你手中已经有abp-zero项目,当前4.6.0 angularJS切换到jquery 运行项目,初始化是跳转到~/App/common/views/layout/layout.cshtml, ...
- Java多线程学习笔记(一)——多线程实现和安全问题
1. 线程.进程.多线程: 进程是正在执行的程序,线程是进程中的代码执行,多线程就是在一个进程中有多个线程同时执行不同的任务,就像QQ,既可以开视频,又可以同时打字聊天. 2.线程的特点: 1.运行任 ...
- Python 之字符串操作
# capitalize()将字符串的第一个字符转换为大写 # center(width, fillchar)返回一个指定的宽度 width 居中的字符串,fillchar 为填充的字符,默认为空格. ...