就是校赛的题目啊,有木有。。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;
#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define nMax 101000
#define inf 0x7fffffff
#define LL long long
#define pb push_bacp
#define DB double
#define eps 1e-8
#define mp make_pair
#define xx first
#define yy second
struct BB{
int a,b,d;
void read(){
scanf("%d%d%d",&a,&b,&d);
}
friend bool operator < (const BB& a,const BB& b) {
if(a.d == b.d) return a.a > b.a;
return a.d < b.d;
}
}a[nMax];
typedef pair<int,double> Htp;
struct HEAP{
Htp heap[nMax];
int Count,root;
void clear(){
Count = 0,root=1;
}
void up(int x){
Htp s = heap[x];
for(int i=(x>>1);i>=1;i>>=1){
if(heap[i]<s) {
heap[x]=heap[i];
x=i;
}else break;
}
heap[x] = s;
}
void down(int x) {
Htp s = heap[x];
for(int i=(x<<1);i<=Count;i<<=1){
i += (i < Count && heap[i] < heap[i+1]);
if(heap[i]>s) {
heap[x] = heap[i];
x = i;
}else break;
}
heap[x] = s;
}
Htp top(){
return heap[root];
}
void push(Htp p){
heap[++Count] = p;
up(Count);
}
void pop(){
heap[root] = heap[Count];
Count --;
down(root);
}
};
HEAP que;
//priority_queue<Htp> que;
int main(){
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int Cas,n;
scanf("%d",&Cas);
while(Cas--){
scanf("%d",&n);
que.clear();
//while(!que.empty()) que.pop();
FOR(i,0,n-1) a[i].read();
sort(a,a+n);
DB T = 0;
double ans = 0;
FOR(i,0,n-1){
T += a[i].b;
que.push(mp(a[i].a,(double)a[i].b/a[i].a));
while(T>a[i].d){
Htp s = que.top();que.pop();
if(s.xx * s.yy > T - a[i].d){
ans += (T-a[i].d)/s.xx;
que.push(mp(s.xx,s.yy-(T-a[i].d)/s.xx));
T = a[i].d;
}else {
ans += s.yy;
T -= s.xx * s.yy;
}
}
}
printf("%.2f\n",ans);
}
return 0;
}
维护一个最大堆即可,中间的各种计算开始弄的头晕,后来还是A了
比较了STL 和 自己的堆
STL:
MyHEAP:
还是手写的快一点。。。