hdu5988 Coding Contest

网友投稿 774 2022-11-09

hdu5988 Coding Contest

hdu5988 Coding Contest

​​ Coding Contest

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 4164 Accepted Submission(s): 974 Problem Description A coding contest will be held in this university, in a huge playground. The whole playground would be divided into N blocks, and there would be M directed paths linking these blocks. The i-th path goes from the ui-th block to the vi-th block. Your task is to solve the lunch issue. According to the arrangement, there are si competitors in the i-th block. Limited to the size of table, bi bags of lunch including breads, sausages and milk would be put in the i-th block. As a result, some competitors need to move to another block to access lunch. However, the playground is temporary, as a result there would be so many wires on the path. For the i-th path, the wires have been stabilized at first and the first competitor who walker through it would not break the wires. Since then, however, when a person go through the i - th path, there is a chance of pi to touch the wires and affect the whole networks. Moreover, to protect these wires, no more than ci competitors are allowed to walk through the i-th path. Now you need to find a way for all competitors to get their lunch, and minimize the possibility of network crashing.

Input The first line of input contains an integer t which is the number of test cases. Then t test cases follow. For each test case, the first line consists of two integers N (N ≤ 100) and M (M ≤ 5000). Each of the next N lines contains two integers si and bi (si , bi ≤ 200). Each of the next M lines contains three integers ui , vi and ci(ci ≤ 100) and a float-point number pi(0 < pi < 1). It is guaranteed that there is at least one way to let every competitor has lunch.

Output For each turn of each case, output the minimum possibility that the networks would break down. Round it to 2 digits.

Sample Input 1 4 4 2 0 0 3 3 0 0 3 1 2 5 0.5 3 2 5 0.5 1 4 5 0.5 3 4 5 0.5

Sample Output 0.50

Source 2016ACM/ICPC亚洲区青岛站-重现赛(感谢中国石油大学)

这题非常的强orz 如何把乘法运算变成加法然后跑费用流 没错针对这个分数取一下log即可 但是问题在于这都是负数啊 我跑费用流 汇出现负权圈会有问题 那怎么办 我要求碰电线的概率最小是不是就是不碰电线的概率最大 所以我可以改为求-log(1-p)取一下对数 跑最小费用最大流即可 最后计算答案的时候由于都是对数 我要求的是总的概率最小 所以我直接把这些数加起来得到这个费用 然后再exp 求得e^x=ans 得到x 最后我的答案因为我预处理的时候是1-p所以 我需要输出1-x 这题可能我太菜了 竟然要卡常 spfa需要写slf优化 这个eps是看网上的人都这么写的 不知道如何计算这个eps gg

#include#include#include#include#include#define eps 1e-8#define N 110#define M 22000#define inf 0x3f3f3f3fusing namespace std;inline int read(){ int x=0;char ch=getchar(); while(ch<'0'||ch>'9') ch=getchar(); while(ch<='9'&&ch>='0') x=x*10+ch-'0',ch=getchar(); return x;}struct node{ int y,z,next;double c;}data[M];int num=1,flag[N],pre[N],path[N],h[N],T,TT,n,m;double f[N];inline void insert1(int x,int y,int z,double c){ data[++num].y=y;data[num].z=z;data[num].c=c;data[num].next=h[x];h[x]=num; data[++num].y=x;data[num].z=0;data[num].c=-c;data[num].next=h[y];h[y]=num;}inline bool spfa(){ memset(f,127,sizeof(f));dequeq;//memset(flag,0,sizeof(flag)); flag[0]=1;f[0]=0;memset(pre,-1,sizeof(pre));q.push_back(0); while(!q.empty()){ int x=q.front();q.pop_front();flag[x]=0; for (int i=h[x];i;i=data[i].next){ int y=data[i].y,z=data[i].z;double c=data[i].c; if(eps0) insert1(0,i,s-b,0);else insert1(i,T,b-s,0); } for (int i=1;i<=m;++i){ int x=read(),y=read(),z=read();double p;scanf("%lf",&p); insert1(x,y,z-1,-log(1-p));insert1(x,y,1,0); }double ans=0; while(spfa()){ int minn=inf,now=T; while(now) minn=min(minn,data[path[now]].z),now=pre[now];now=T;ans+=f[T]*minn; while(now) {data[path[now]].z-=minn;data[path[now]^1].z+=minn;now=pre[now];} }printf("%.2lf\n",1.0-exp(-ans)); } return 0;}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:SpringBoot +DynamicDataSource切换多数据源的全过程
下一篇:bzoj5027 数学题
相关文章

 发表评论

暂时没有评论,来抢沙发吧~