标签:code sizeof clear enter char fir set zjoi pre
显然二分,最大流判定
要满足两个条件:
(1) 在任一时刻,一只老鼠最多可以吃一块奶酪;
(2) 在任一时刻,一块奶酪最多被一只老鼠吃。
先按照奶酪的边界进行离散化, 变成num个块
卡精度啊,,,,,
inf设太大了
并且为了防止被inf卡,可以直接记录ret表示流出流量,直接返回ret即可
#include<bits/stdc++.h> #define reg register int #define il inline #define fi first #define se second #define mk(a,b) make_pair(a,b) #define numb (ch^‘0‘) #define pb push_back #define solid const auto & #define enter cout<<endl #define pii pair<int,int> #define double long double using namespace std; typedef long long ll; template<class T>il void rd(T &x){ char ch;x=0;bool fl=false; while(!isdigit(ch=getchar()))(ch==‘-‘)&&(fl=true); for(x=numb;isdigit(ch=getchar());x=x*10+numb); (fl==true)&&(x=-x); } template<class T>il void output(T x){if(x/10)output(x/10);putchar(x%10+‘0‘);} template<class T>il void ot(T x){if(x<0) putchar(‘-‘),x=-x;output(x);putchar(‘ ‘);} template<class T>il void prt(T a[],int st,int nd){for(reg i=st;i<=nd;++i) ot(a[i]);putchar(‘\n‘);} namespace Miracle{ const int N=33; const int P=33*33*2+44; const double inf=1e9; const double eps=1e-8; int n,m; struct node{ int nxt,to; double w; }e[2*(P*N+N+P)]; int hd[P],cnt=1; int p[N],st[N],nd[N]; int sp[N]; double mem[2*N]; int num; int sum; void add(int x,int y,double z){ e[++cnt].nxt=hd[x]; e[cnt].to=y; e[cnt].w=z; hd[x]=cnt; e[++cnt].nxt=hd[y]; e[cnt].to=x; e[cnt].w=0; hd[y]=cnt; } int d[P]; int s,t; double dfs(int x,double flow){ if(x==t) return flow; double res=flow; for(reg i=hd[x];i&&res>eps;i=e[i].nxt){ int y=e[i].to; if(e[i].w>eps&&d[y]==d[x]+1){ double k=dfs(y,min(res,e[i].w)); if(!k) d[y]=0; res-=k; e[i].w-=k; e[i^1].w+=k; } } return flow-res; } int q[P],l,r; bool bfs(){ memset(d,0,sizeof d); l=1;r=0; q[++r]=s; d[s]=1; while(l<=r){ int x=q[l++]; for(reg i=hd[x];i;i=e[i].nxt){ int y=e[i].to; if(e[i].w>eps&&!d[y]){ d[y]=d[x]+1; q[++r]=y; if(y==t) return true; } } } return false; } int id(int x,int y){ return m+(x-1)*num+y; } bool che(double mid){ memset(hd,0,sizeof hd); cnt=1; num=0; for(reg i=1;i<=m;++i){ mem[++num]=st[i];mem[++num]=nd[i]+mid; } sort(mem+1,mem+num+1); num=unique(mem+1,mem+num+1)-mem-1; --num;//warning!!! s=0,t=id(n,num)+1; for(reg i=1;i<=m;++i){ add(i,t,p[i]); } for(reg i=1;i<=n;++i){ for(reg j=1;j<=num;++j){ for(reg k=1;k<=m;++k){ if(st[k]<=mem[j]&&mem[j+1]<=nd[k]+mid){ add(id(i,j),k,(double)sp[i]*(mem[j+1]-mem[j])); } } add(s,id(i,j),(double)sp[i]*i*(mem[j+1]-mem[j])); } } double flow=0,ret=0; while(bfs()){ while(1){ flow=dfs(s,inf); if(flow<eps) break; ret+=flow; } } if(ret+eps>sum) return true; return false; } void clear(){ sum=0; s=0;t=0; } bool cmp(int x,int y){ return x>y; } int main(){ int T; rd(T); while(T--){ clear(); rd(m);rd(n); for(reg i=1;i<=m;++i){ rd(p[i]);rd(st[i]);rd(nd[i]); sum+=p[i]; } for(reg i=1;i<=n;++i){ rd(sp[i]); } sort(sp+1,sp+n+1,cmp); sp[n+1]=0; for(reg i=1;i<=n;++i){ sp[i]-=sp[i+1]; } double L=0.0,R=1e7+3; for(reg i=1;i<=60;++i){ double mid=(R+L)/2; if(che(mid)) R=mid; else L=mid; } printf("%.10Lf\n",L); } return 0; } } signed main(){ Miracle::main(); return 0; } /* Author: *Miracle* */
标签:code sizeof clear enter char fir set zjoi pre
原文地址:https://www.cnblogs.com/Miracevin/p/10840899.html