hdu——3177——Crixalis's Equipment
来源:互联网 发布:js 高级编程视频教程 编辑:程序博客网 时间:2024/05/20 05:53
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.
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.
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
220 310 203 101 710 21 102 11
Sample Output
YesNo
#include <iostream>#include <cstring>using namespace std;int n,m;struct node{ int a,b;}Node[1005];int cmp(const void *p,const void *k){ node *x=(node *)p; node *y=(node *)k; if(x->b!=y->b) return y->b-y->a-x->b+x->a; else return x->a-y->a;}int main(){ int t,i; cin>>t; while(t--) { memset(Node,0,sizeof(Node)); cin>>n>>m; for(i=1;i<=m;i++) { cin>>Node[i].a>>Node[i].b; } sort(Node,Node+m,cmp); for(i=1;i<=m;i++) { if(n>=Node[i].b) n-=Node[i].a; else break; } if(i>m) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0;}
- hdu——3177——Crixalis's Equipment
- hdu3177——Crixalis's Equipment
- 【巧妙的贪心条件】HDU 3177—— Crixalis's Equipment
- hdu 3177 - Crixalis's Equipment
- HDU 3177 Crixalis's Equipment
- HDU 3177 Crixalis's Equipment
- hdu 3177 Crixalis's Equipment
- hdu 3177 Crixalis's Equipment
- HDU 3177 Crixalis's Equipment
- hdu 3177 Crixalis's Equipment
- HDU 3177 Crixalis's Equipment
- HDU-3177 Crixalis's Equipment
- HDU - 3177 Crixalis's Equipment
- 杭电ACM3117——Crixalis's Equipment
- HDU Crixalis's Equipment
- HDU Crixalis's Equipment
- HDU Crixalis's Equipment
- hdu Crixalis's Equipment
- 项目报错一
- pctfree对 index索引在什么时候有效?
- Oracle 用户及角色 介绍
- Windows内核函数的命名
- Ubuntu12.04 下Samba服务器搭建
- hdu——3177——Crixalis's Equipment
- PowerPC汇编指令集简析
- 【互动】针对 Windows 8.1预览版 与win8的大家的看法
- java基础--final用法
- 代码实现UITextField收键盘
- ARCHelper兼容ARC/MRC
- Java基础--static、this、super用法
- JDK的安装与配置
- poj 1142 Smith Numbers