HDU3177 贪心
Crixalis's Equipment
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3957 Accepted Submission(s): 1625

- Sand King used to be a giant scorpion(蝎子) in the deserts of
Kalimdor. Though he's a guardian of Lich King now, he keeps the living
habit of a scorpion like living underground and digging holes.
Someday
Crixalis decides to move to another nice place and build a new house
for himself (Actually it's just a new hole). As he collected a lot of
equipment, he needs to dig a hole beside his new house to store them.
This hole has a volume of V units, and Crixalis has N equipment, each of
them needs Ai units of space. When dragging his equipment into the
hole, Crixalis finds that he needs more space to ensure everything is
placed well. Actually, the ith equipment needs Bi units of space during
the moving. More precisely Crixalis can not move equipment into the hole
unless there are Bi units of space left. After it moved in, the volume
of the hole will decrease by Ai. Crixalis wonders if he can move all his
equipment into the new hole and he turns to you for help.
first line contains an integer T, indicating the number of test cases.
Then follows T cases, each one contains N + 1 lines. The first line
contains 2 integers: V, volume of a hole and N, number of equipment
respectively. The next N lines contain N pairs of integers: Ai and Bi.
0<T<= 10, 0<V<10000, 0<N<1000, 0 <Ai< V, Ai <= Bi < 1000.
20 3
10 20
3 10
1 7
10 2
1 10
2 11
No
lcy | We have carefully selected several similar problems for you: 1789 1051 1053 1045
代码:
/*
应该先放实际体积小而需要的体积大的,所以按照差值由大到小排序
*/
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<queue>
#include<stack>
using namespace std;
int t,v,n;
struct eq
{
int a,b;
}e[];
bool cmp(eq x,eq y)
{
return x.b-x.a>y.b-y.a;
}
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&v,&n);
for(int i=;i<n;i++)
{
scanf("%d%d",&e[i].a,&e[i].b);
}
sort(e,e+n,cmp);
for(int i=;i<n;i++)
{
if(v<e[i].b)
{
v=-;
break;
}
v-=e[i].a;
}
if(v==-)
printf("No\n");
else printf("Yes\n");
}
return ;
}
HDU3177 贪心的更多相关文章
- 【贪心】【HDU3177】 搬家问题
</pre><pre name="code" class="cpp">#include <iostream> #includ ...
- BZOJ 1692: [Usaco2007 Dec]队列变换 [后缀数组 贪心]
1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1383 Solved: 582[Submit][St ...
- HDOJ 1051. Wooden Sticks 贪心 结构体排序
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- BZOJ 1691: [Usaco2007 Dec]挑剔的美食家 [treap 贪心]
1691: [Usaco2007 Dec]挑剔的美食家 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 786 Solved: 391[Submit][S ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【BZOJ-4245】OR-XOR 按位贪心
4245: [ONTAK2015]OR-XOR Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 486 Solved: 266[Submit][Sta ...
- code vs 1098 均分纸牌(贪心)
1098 均分纸牌 2002年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 有 N 堆纸牌 ...
- 【BZOJ1623】 [Usaco2008 Open]Cow Cars 奶牛飞车 贪心
SB贪心,一开始还想着用二分,看了眼黄学长的blog,发现自己SB了... 最小道路=已选取的奶牛/道路总数. #include <iostream> #include <cstdi ...
随机推荐
- 【POI word】使用POI实现对Word的读取以及生成
项目结构如下: 那第一部分:先是读取Word文档 package com.it.WordTest; import java.io.FileInputStream; import java.io.Fil ...
- Practical JAVA(二)关于对象的类型和equals函数
Practice5,6,9,10,11,12,13,14,15 ==判断等号两边两个变量储存的值是否相同,如果是两个对象,则判断两个变量储存的对象地址是否相同. 大多数时候,我们需要判断的不是左右两个 ...
- mob免费短信验证码安卓SDK调用方法
很不错的一款免费验证码平台,支持IOS.安卓,比那些收费的稳定.开发容易.分享给大家,希望大家不要滥用 官网: http://mob.com/ 官方有开发文档,但是有几点要注意的官方没有提到,导致初始 ...
- HTML轉PDF - 使用Pechkin套件
剛好跟人討論到HTML轉PDF需求,便對工具進行簡單評估以備不時之需. 網路上比較多人推的是WkHtmlToPdf,如果是用.NET開發,已經有人包成NuGet套件,直接搜尋pechkin就可找到,它 ...
- Codeforces Round #355 (Div. 2)-A
A. Vanya and Fence 题目连接:http://codeforces.com/contest/677/problem/A Vanya and his friends are walkin ...
- css3 -- 网页字体
1.@font-face规则 @font-face{ font-family:chunk; src:local('chunkFive'), url("chunkFive.ttf“) form ...
- get请求
写在前面的话 XMLHttpRequest对象的open方法的第一个参数为request-type,取值可以为get或post.本篇介绍get请求. get请求的目的,主要是为了获取数据.虽然get请 ...
- python 代码片段25
#coding=utf-8 # 虽然python是面向对象的语言,但是没有显式的构造函数概念. # python没有new关键词 class MyClass(object): pass m=MyCla ...
- 20145308刘昊阳 《Java程序设计》实验五报告
20145308刘昊阳 <Java程序设计>实验五 Java网络编程及安全 实验报告 实验名称 Java网络编程及安全 实验内容 1.掌握Socket程序的编写: 2.掌握密码技术的使用: ...
- Android ftp 上传图片
1.确定ftp文件夹 /** FTP文件夹 **/ private String ftpPath = "hshscrenncap" + "/" + DateUt ...