dlut1224题解-贪心及注意事项
来源:互联网 发布:ubuntu默认启动windows 编辑:程序博客网 时间:2024/04/30 09:45
这是我写的贪心第一题,注意:1:这一题的sort对相同力量的要排质量,(因为这个wa了3次,最后给我yy对了);2:是注意为N=0的情况;
#include<cstring>#include<iostream>#include<cstdio>#include<algorithm>using namespace std;const int maxn=100005;struct node{ int power; int weight;};node peo[maxn];bool cmp(node a,node b){ if(a.power==b.power)return a.weight<b.weight; return a.power<b.power;}int main(){ int T; scanf("%d",&T); while(T--){ int N; scanf("%d",&N); for(int i=0;i<N;i++) scanf("%d%d",&peo[i].weight,&peo[i].power); sort(peo,peo+N,cmp); int sum=0,cnt=0; for(int i=0;i<N;i++){ if(sum<=peo[i].power){ sum+=peo[i].weight; cnt++; } } printf("%d\n",cnt); } return 0;}
0 0
- dlut1224题解-贪心及注意事项
- sequence题解(贪心)
- 贪心:HDU - 2037 题解
- 贪心 HDU 2037题解
- HDU贪心题解
- SGU 259 单机调度问题 +贪心 及此题解法的证明
- SGU 259 单机调度问题 +贪心 及此题解法的证明
- 【BZOJ】【P2697】【特技飞行】【题解】【贪心】
- HLJU14级贪心训练题解
- 【BZOJ】【P2474】【订单】【题解】【贪心】
- uva 10382题解(贪心)
- 贪心2 HDU - 1050 题解
- 贪心5 HDU - 1789 题解
- 【贪心】17.6.1 漂流 题解
- 【BZOJ2796】【贪心】 Fibonacci Representation题解
- [贪心]51Nod 1241 题解
- USACO月赛题解 第四讲 贪心
- HDU 1661 Assigments 贪心法题解
- Hibernate+struts+JqueryAjax+jSON实现无刷新三级联动
- [ACM] hdu 2067 小兔的棋盘(卡特兰数Catalan)
- github简单使用教程
- 快速算法实现----挖坑填数
- shell脚本学习(二)
- dlut1224题解-贪心及注意事项
- php中提示Undefined index的解决方法
- vector详解
- 文件与目录类命令
- 每首歌都有一段历史
- SQLite-Java-Hibernate类似hibernate的数据库辅助工具
- MVC:界面开发的一般步骤
- 每日笔记——Delphi如何通过ADO链接.db(.dbf)文件
- XML基础学习