标签:排序 规则 type 定义 strong 种类 typedef style ssi
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 2992 Accepted Submission(s): 987
#include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> #include <iostream> #include <sstream> #include <queue> #include <vector> #include <algorithm> #define maxn 100050 using namespace std; typedef long long ll; int n,m; int b[maxn]; struct node { int d; int p; } n1,n2; struct cmp { bool operator()(node n1,node n2) { return n1.p > n2.p; } }; bool cmp1(node a,node b) { return a.d>b.d; //按d降序排序 } bool cmp2(int a,int b) { return a>b; //b降序排序 } struct node jian[maxn]; int main() { while(scanf("%d%d",&n,&m)!=EOF) { priority_queue<node,vector<node>,cmp> q; //以node为元素,以p为小顶堆优先队列 int i,j; for(i=0; i<n; i++) { scanf("%d",&b[i]); } for(i=0; i<m; i++) { scanf("%d",&jian[i].d); } for(i=0; i<m; i++) { scanf("%d",&jian[i].p); } sort(b,b+n,cmp2); sort(jian,jian+m,cmp1); int flag=1; ll sum=0; int k=0; for(i=0; i<n; i++) { while(k < m&&jian[k].d>=b[i]) //把大于等于b[i]的箭压进队列 { q.push(jian[k]); k++; } if(q.empty()) { flag=0; break; } else { sum+=q.top().p; q.pop(); //删除队顶元素 } } if(flag) cout<<sum<<endl; else cout<<"No"<<endl; } } /* 另外一种定义结构体优先队列代码 struct node { int d; int p; friend bool operator<(node n1,node n2) { return n1.p > n2.p; } }; 调用语句 priority_queue<node> q; */
2017ecjtu-summer training # 9 HDU 4544
标签:排序 规则 type 定义 strong 种类 typedef style ssi
原文地址:http://www.cnblogs.com/stranger-/p/7242626.html