hdu 3177 Crixalis's Equipment

Crixalis‘s Equipment

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 2562    Accepted Submission(s): 1056

Problem Description

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

Input

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

Output

For each case output "Yes" if Crixalis can move all his equipment into the new hole or else output "No".

Sample Input

2

20 3
10 20
3 10
1 7

10 2
1 10
2 11

Sample Output

Yes
No

分析:

停放体积 移动体积

第一件物品   a1     b1

第二件物品   a2     b2

如果这两件物品的移动体积都不大于洞的体积V

a1+b2为先放第一件物品 后放第二件物品的最大瞬时体积

a2+b1为先放第二件物品 后放第一件物品的最大瞬时体积

我们应该选择a1+b2和a2+b1中比較小的先放.

如果n件物品的移动体积都不大于洞的体积V(如果有大于的 那么结果必定是NO)

将N件物品依照a1+b2<a2+b1进行排序,然后依次放入洞中。即依照差值从大到小放入洞中.

#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;

struct node
{
	int x,y;
}p[10005];

bool cmp(node a,node b)  // 差值排序
{
	return (a.y-a.x)>(b.y-b.x);
}

int main ()
{
	int t,n,m,i,j;
	int flag;
	scanf("%d",&t);
	for(i=0;i<t;i++)
	{
		scanf("%d%d",&n,&m);
		for(j=0;j<m;j++)
			scanf("%d%d",&p[j].x,&p[j].y);
		sort(p,p+m,cmp);
		flag=1;
		for(j=0;j<m;j++)
		{
			if(p[j].y>n)
			{
				flag=0;
				break;
			}
			n-=p[j].x;
		}
		if(flag) printf("Yes\n");
		else printf("No\n");
	}
	return 0;

}

hdu 3177 Crixalis's Equipment

时间: 2024-11-15 18:52:46

hdu 3177 Crixalis&#39;s Equipment的相关文章

Hdu 3177 Crixalis&#39;s Equipment

Crixalis's Equipment Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2795    Accepted Submission(s): 1141 Problem Description Crixalis - Sand King used to be a giant scorpion(蝎子) in the deserts

hdu 3177 Crixalis&#39;s Equipment(贪心)

Problem Description Crixalis - 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

[HDU] 3177.Crixalis&#39;s Equipment (贪心)

Problem Description 题目大意: 有V的空间以及N个物品,对于放入每个物品有Ai(放入物品后剩余空间的减少大小),Bi(放入该物品之前需要的最小剩下空间大小,如果大于当前剩余空间大小则无法放入) Input T组数据,每组数据有N+1行,每组数据第一行输入V,N,之后的N行每行描述一个物品的Ai,Bi 0<T<= 10, 0<V<10000, 0<N<1000, 0 <Ai< V, Ai <= Bi < 1000. Output

杭电 3177 Crixalis&#39;s Equipment

http://acm.hdu.edu.cn/showproblem.php?pid=3177 Crixalis's Equipment Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2562    Accepted Submission(s): 1056 Problem Description Crixalis - Sand King

hdoj 3177 Crixalis&#39;s Equipment 【贪心】

Crixalis's Equipment Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3073    Accepted Submission(s): 1250 Problem Description Crixalis - Sand King used to be a giant scorpion(蝎子) in the deserts

HDUJ 3177 Crixalis&#39;s Equipment 贪心

Crixalis's Equipment Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2568    Accepted Submission(s): 1059 Problem Description Crixalis - Sand King used to be a giant scorpion(蝎子) in the deserts

hdu 5348 MZL&amp;#39;s endless loop

给一个无向图(事实上是有向的.可是没有指定边的方向),你须要指定边的方向,使得每一个点入度和出度相差不超过1. 事实上就是找很多条路径.合起来能走完这个图..先统计各个顶点的度.度为奇数必是起点或终点,否则是中间点或者同为起点和终点. 邻接表建图(建双向),先从每一个奇数度顶点出发找路径,再从偶数度顶点出发找路径.经过的边要删去不然超时. #include <iostream> #include <cstring> #include <cstdio> #include

hdu 4274 Spy&amp;#39;s Work(水题)

Spy's Work Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1266    Accepted Submission(s): 388 Problem Description I'm a manager of a large trading company, called ACM, and responsible for the

HDU 1160 FatMouse&amp;#39;s Speed DP题解

本题就先排序老鼠的重量,然后查找老鼠的速度的最长递增子序列,只是由于须要按原来的标号输出,故此须要使用struct把三个信息打包起来. 查找最长递增子序列使用动态规划法.主要的一维动态规划法了. 记录路径:仅仅须要记录后继标号,就能够逐个输出了. #include <stdio.h> #include <algorithm> using namespace std; const int MAX_N = 1005; struct MouseSpeed { int id, w, s;