SCU's closet(排序法的应用)
来源:互联网 发布:尺八制作数据 编辑:程序博客网 时间:2024/06/06 01:54
http://cstest.scu.edu.cn/soj/problem.action?id=4263
B: SCU's closet
Description
Summer comes with the hot weather.Today xiaoL wants to take the heavy coats in her closet out and bring her T-shirts and skirts in.We have konwn that the volume of SCU's closet is V units,xiaoL has N pieces of clothing to put in,each of them needs Ai units of space.When putting the i-th clothes into the closet,she finds that she needs Bi units of space to ensure the i-th clothes will be placed well.After that,the volume of the closet will decrease by Ai.Now,She wonders whether she can move all her clothes into the closet.
Input
There are multiple test cases,for each case,the first line contains 2 integers:V,N,then followed N lines,each of them contains 2 integers Ai and Bi as descriped above.
( 0 < V < 10000, 0 < N< 1000, 0 < Ai < V, Ai <= Bi < 1000 )
Output
For each test case output "YES" if she can put all her clothes into the closet or else output "NO"
Sample Input
20 3
10 20
3 10
1 7
10 2
1 10
2 11
Sample Output
YES
NO
Author
lentty
题意:给你一个衣橱体积为V
每件衣服的体积为ai,总共需要bi的空间,问是否可以把全部衣服都放进去。
这里我原来的题意完全理解错了,导致一直解不出来
思路:排序,贪心。
两种择优情况:一。按所空间较大优先来考虑
二。按所体积较小的考虑
思路:按照以上两种情况进行排序:只要有一种满足情况即可
*/
#include<stdio.h>#include<algorithm>#include <iostream>using namespace std;const int maxn=1000+10;struct cloth{int a;int b;}c1[maxn],c2[maxn];int cmp1(cloth ch1,cloth ch2 ) //按所空间较大优先来考虑{ return (ch1.b>ch2.b)||(ch1.b==ch2.b&&ch1.a<ch2.a);}int cmp2(cloth ch1,cloth ch2 ) //按所体积较小的考虑{ return (ch1.a<ch2.a)||(ch1.a==ch2.a&&ch1.b>ch2.b);}int main(){ int n,v,i,ok1,ok2,t1,t2;while(scanf("%d%d",&v,&n)!=EOF) { ok1=1; ok2=1; t1=v; t2=v; for(i=0;i<n;i++) { scanf("%d%d",&c1[i].a,&c1[i].b); c2[i].a=c1[i].a; c2[i].b=c1[i].b; } sort(c1,c1+n,cmp1); sort(c2,c2+n,cmp2); //for(i=0;i<n;i++) //printf("%d %d\n",c[i].a,c[i].b); for(i=0;i<n;i++) {if(t1<c1[i].b) {ok1=0; break; } t1=t1-c1[i].a; } for(i=0;i<n;i++) {if(t2<c2[i].b) {ok2=0; break; } t2=t2-c2[i].a; } if(ok1==1||ok2==1) printf("YES\n"); else printf("NO\n");}return 0;}
- SCU's closet(排序法的应用)
- SCU's Bathhouse
- scu-3296: Windy's S
- SCU 4427 Miss Zhao's Graph (dp)
- SCU 3082 windy's cake II(容斥)
- [SCU 4498] RunningPhoton's Nightmare (BFS预处理+SPFA)
- [SCU 4516] Mingo's Game (斜率DP)
- SCU 4488 king's trouble II(dp||枚举)
- SCU~4488: king's trouble II(dp)
- SCU 4512 Goozy的积木(dp)
- king's trouble II SCU
- [SCU 4514] Simple dp (XJBLG法)
- 刷题的日常[Leetcode]——16)3 Sum Closet
- 算法实验(四)Closet-Points Problem
- SCU 4487 king's trouble I(dfs)||(0找1)
- SCU
- SCU
- SCU
- 【30篇突击 android】源码统计 十八
- DOM DEM DLG DRG之间的区别
- Android学习 —— 数据的存储与访问方式二: SharedPreferences(偏好参数保存)
- 问题五十四: 输出10000以内的所有回文素数。
- 两界面间传值方法总结
- SCU's closet(排序法的应用)
- 1016 两浮点数相除
- 列表框消息
- 项目5
- POJ 1740 (博弈)
- jquery合成事件-hover() toggle()
- 小技巧
- Android 游戏引擎libgdx之Box2D 案例实践——弹球
- Qwt源码解读之开篇记