题目描述

又是一年秋季时,陶陶家的苹果树结了n个果子。陶陶又跑去摘苹果,这次她有一个a公分的椅子。当他手够不着时,他会站到椅子上再试试。

这次与NOIp2005普及组第一题不同的是:陶陶之前搬凳子,力气只剩下s了。当然,每次摘苹果时都要用一定的力气。陶陶想知道在s<0之前最多能摘到多少个苹果。

现在已知n个苹果到达地上的高度xi,椅子的高度a,陶陶手伸直的最大长度b,陶陶所剩的力气s,陶陶摘一个苹果需要的力气yi,求陶陶最多能摘到多少个苹果。

输入输出格式

输入格式:

第1行:两个数 苹果数n,力气s。

第2行:两个数 椅子的高度a,陶陶手伸直的最大长度b。

第3行~第3+n-1行:每行两个数 苹果高度xi,摘这个苹果需要的力气yi。

输出格式:

只有一个整数,表示陶陶最多能摘到的苹果数。

输入输出样例

import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner; public class Main {
private static Scanner cin; public static void main(String args[]) throws Exception {
cin = new Scanner(System.in);
LinkedList<Apple> list = new LinkedList<Apple>();
int n = cin.nextInt();
int s = cin.nextInt();
int a = cin.nextInt();
int b = cin.nextInt();
int height = 0;
int strength = 0;
int count = 0;
for(int i = 0; i<n;i++) {
height = cin.nextInt();
strength = cin.nextInt();
if((a+b)>=height) {
Apple t = new Apple(height,strength);
list.add(t);
}
} Object[] apples = list.toArray();
Arrays.sort(apples);
for(Object apple :apples) {
Apple tmp = (Apple)apple;
s = s-tmp.getStrength();
if(s >= 0) {
count++;
}
}
System.out.println(count);
} } class Apple implements Comparable<Object>{
private int height;
private int strength; public Apple(int height, int strength) {
this.height = height;
this.strength = strength;
} public int getHeight() {
return height;
} public void setHeight(int height) {
this.height = height;
} public int getStrength() {
return strength;
} public void setStrength(int strength) {
this.strength = strength;
} @Override
public int compareTo(Object o) {
// TODO Auto-generated method stub
Integer a = new Integer(strength);
Apple t = (Apple)o;
Integer b = new Integer(t.getStrength());
return a.compareTo(b);
}
}

Java实现 洛谷 P1487 陶陶摘苹果(升级版)的更多相关文章

  1. 【洛谷P2028 龙兄摘苹果】动态规划

    分析 第二类striling数 考虑最后一个数到底是放在之前的任意一个集合内,还是自成一个集合 \[F_{i\ j}=F_{i-1\ j-1}+j\times F_{i-1,j} \] AC代码 #i ...

  2. 陶陶摘苹果(升级版)P1478_巧妙模拟

    如此水的题居然让我绞尽脑汁,我在想我是不是快退役了. 这道题我看见很多解法:贪心,背包,桶排乱七八糟一大堆. 题目 题目描述 又是一年秋季时,陶陶家的苹果树结了 n 个果子.陶陶又跑去摘苹果,这次他有 ...

  3. Java实现 洛谷 Car的旅行路线

    输入输出样例 输入样例#1: 1 3 10 1 3 1 1 1 3 3 1 30 2 5 7 4 5 2 1 8 6 8 8 11 6 3 输出样例#1: 47.5 import java.util. ...

  4. Java实现 洛谷 P1738 洛谷的文件夹

    题目描述 kkksc03是个非凡的空想家!在短时间内他设想了大量网页,然后总是交给可怜的lzn去实现. 洛谷的网页端,有很多文件夹,文件夹还套着文件夹. 例如:/luogu/application/c ...

  5. Java实现洛谷 P1428 小鱼比可爱

    题目描述 人比人,气死人:鱼比鱼,难死鱼.小鱼最近参加了一个"比可爱"比赛,比的是每只鱼的可爱程度.参赛的鱼被从左到右排成一排,头都朝向左边,然后每只鱼会得到一个整数数值,表示这只 ...

  6. 洛谷.1919.[模板]A*B Problem升级版(FFT)

    题目链接:洛谷.BZOJ2179 //将乘数拆成 a0*10^n + a1*10^(n-1) + ... + a_n-1的形式 //可以发现多项式乘法就模拟了竖式乘法 所以用FFT即可 注意处理进位 ...

  7. Java实现 洛谷 P1046 陶陶摘苹果

    import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = ...

  8. 【洛谷】P1478 陶陶摘苹果(升级版)-全AC题解

    #include <iostream> #include <algorithm> using namespace std; int main() { int n,s,a,b; ...

  9. Java实现洛谷 P1007独木桥

    题目背景 战争已经进入到紧要时间.你是运输小队长,正在率领运输部队向前线运送物资.运输任务像做题一样的无聊.你希望找些刺激,于是命令你的士兵们到前方的一座独木桥上欣赏风景,而你留在桥下欣赏士兵们.士兵 ...

随机推荐

  1. 【HDU4991】树状数组

    http://acm.hdu.edu.cn/showproblem.php?pid=4991 用f[i][j] 表示 前i个数以第i个数结尾的合法子序列的个数,则递推式不难写出: f[i][j] = ...

  2. 1013 Battle Over Cities (25分) 图的连通分量+DFS

    题目 It is vitally important to have all the cities connected by highways in a war. If a city is occup ...

  3. 超过百万的StackOverflow Flutter 问题-第二期

    老孟导读:一个月前分享的<超过百万的StackOverflow Flutter 问题-第一期>受到很多朋友的喜欢,非常感谢大家的支持,在文章末尾有第一期的链接,希望此文能对你有所帮助. N ...

  4. An SWT error has occurred

    对话框标题:Problem Occurred 对话框内容:Unhandled event loop exception No more handles 对话框按钮:第一个超链接:Show Error ...

  5. webpack的proxytable的配置

    这个一定不能忘记了/rest/后面的/,否则就是404找不到接口 这样的实现效果是 this.axios.post('/api/delShare', qs.stringify({'Id':Number ...

  6. vue v-for 渲染input 输入有问题 解决方案

    v-for循环input标签的时候输入信息两个输入框一同显示输入信息 解决方案: <input :placeholder="items.title" v-model = &q ...

  7. 我的.emacs配置

    我不是大神,使用vim和emacs只是兴趣,打发空闲时间. 上代码: ;; Added by Package.el. This must come before configurations of ; ...

  8. 网鼎杯2020青龙组writeup-web

    本文首发于Leon的Blog,如需转载请注明原创地址并联系作者 AreUSerialz 开题即送源码: <?php include("flag.php"); highligh ...

  9. ambari hdp ssh链接错误

    错误信息: ERROR 2019-09-05 10:29:05,700 NetUtil.py:96 - EOF occurred in violation of protocol (_ssl.c:57 ...

  10. 关于MYSQL 和INNODB的逻辑关系图。最好的理解是一点点动手做,观察,记录,思考。

    每隔0.1秒就刷一次MYSQL文件的变化,并闪动标示出来,以观察SQL执行时,MYSQL的处理顺序. watch -n 0.1 -d stat /var/lib/mysql/ib_logfile0 / ...