第一次用STL :3
#include<stdio.h> #include<cstring> #include<algorithm> #include<queue> #include<cmath> using namespace std; priority_queue<double> minheap; int main() { int n;scanf("%d",&n); while(n--) { char a[5];double b; scanf("%s %lf",a,&b); minheap.push(-b); } double penalty=0; while(minheap.size()>=2) { double a,b; a=minheap.top(); minheap.pop(); b=minheap.top(); minheap.pop(); penalty+=a+b; minheap.push(a+b); } printf("%.2f",-penalty); return 0; }
沒有留言:
張貼留言