题意简述
- 有 种物品,第 种售价为 ( 表示不可售出)。
- 种生产方式,每种给出 :
- 若 :一个工人一天可直接生产 件物品 (忽略 )。
- 若 :一个工人一天可用 件物品 生产 件物品 ()。
- 每个工人独立生产,求平均每个工人一天能获得的最大收益(四舍五入保留两位小数)。
数据范围:,,,,。保证至少存在一个 。
思路
很好想的,最终只可能卖单个品类产品。否则将其余的劳动力去做性价比最高的品类会更赚。
考虑 品类依赖 ,这一定是一个 DAG。同时,其所有的依赖都是小指向大,连拓扑排序都不用写,只按照 排序就可以了。
设 表示单个工人最多能生产多少 产品,最终答案是 的最大值。
当 为 时, 是 。
否则,计算 公式是 除以生产 件物品需要的劳动力数量。生产其原料需要 除以 个工人,将原料加工需要 个人,相加即是需要的劳动力数量。
代码
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define pii pair<int,int>
#define f(i,a,b) for(int i=(a);i<=(b);i++)
#define Dl(a) cout << #a << " : " << a << "\n";
#define D(a) cout << #a << " : " << a;
#define Da(a,i,j) cout << #a << " : ";f(idx,i,j){cout << a[idx] <<" ";}
const int N = 3e5+10;
struct st{
int x,y,k,w;
bool operator < (st a){
return y < a.y;
}
}s[N];
int a[N];
int n,m;
double dp[N];
signed main(){
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
cin >> n >> m;
f(i,1,n){
cin >> a[i];
}
f(i,1,m){
cin >> s[i].x >> s[i].y >> s[i].k >> s[i].w;
}
sort(s+1,s+1+m);
f(i,1,m){
if (s[i].k == 0){
dp[s[i].y] = max(dp[s[i].y],s[i].w * 1.0);
}
else{
if (dp[s[i].x] == 0) continue;
dp[s[i].y] = max(dp[s[i].y],(double) s[i].w / ((double)s[i].k / dp[s[i].x] + 1.0));
}
}
double ans = 0;
f(i,1,n){
ans = max(ans,dp[i] * a[i]);
}
printf("%.2lf",ans);
return 0;
}