随笔分类 -  ACM_贪心

摘要:#include<stdio.h>#include<algorithm>using namespace std;struct node{ int number,num,price;}hotel[1009];int cmp(node a,node b){ return a.price<b.price;}int main(){ int T,n,i,t,g,m; scanf("%d",&T); while(T--) { scanf("%d",&n); for(i=1;i<=n;i++) { scanf(&qu 阅读全文
posted @ 2013-04-15 12:51 宛如 阅读(162) 评论(0) 推荐(0)
摘要:新学到cmp还可以这样写,更简单int cmp(wood a,wood b){ if(a.l!=b.l) return a.l<b.l; return a.w<b.w;}表示先对l升序排列,如果相等,再对w升序排列#include<stdio.h>#include<algorithm>#include<iostream> /*要写这两个才能用sort*/using namespace std; /* */struct wooden{ int l,w;}wood[5009];int cmp(wooden a,wooden b){ if(a.l< 阅读全文
posted @ 2013-04-15 12:49 宛如 阅读(198) 评论(0) 推荐(0)
摘要:/*头文件:#include <algorithm>using namespace std;1.默认的sort函数是按升序排。对应于1)sort(a,a+n); //两个参数分别为待排序数组的首地址和尾地址2.可以自己写一个cmp函数,按特定意图进行排序。对应于2)例如:int cmp( const int &a, const int &b ){ if( a > b ) return 1; else return 0;}sort(a,a+n,cmp);是对数组a降序排序又如:int cmp( const POINT &a, const POINT &a 阅读全文
posted @ 2013-04-15 12:47 宛如 阅读(145) 评论(0) 推荐(0)