# 洛谷P3199 [HNOI2009]最小圈(01分数规划)

## Sol

#include<bits/stdc++.h>
#define Pair pair<int, double>
#define MP(x, y) make_pair(x, y)
#define fi first
#define se second
//#define int long long
#define LL long long
#define Fin(x) {freopen(#x".in","r",stdin);}
#define Fout(x) {freopen(#x".out","w",stdout);}
using namespace std;
const int MAXN = 3001, mod = 998244353, INF = 2e9 + 10;
const double eps = 1e-9;
template <typename A, typename B> inline bool chmin(A &a, B b){if(a > b) {a = b; return 1;} return 0;}
template <typename A, typename B> inline bool chmax(A &a, B b){if(a < b) {a = b; return 1;} return 0;}
template <typename A, typename B> inline LL add(A x, B y) {if(x + y < 0) return x + y + mod; return x + y >= mod ? x + y - mod : x + y;}
template <typename A, typename B> inline void add2(A &x, B y) {if(x + y < 0) x = x + y + mod; else x = (x + y >= mod ? x + y - mod : x + y);}
template <typename A, typename B> inline LL mul(A x, B y) {return 1ll * x * y % mod;}
template <typename A, typename B> inline void mul2(A &x, B y) {x = (1ll * x * y % mod + mod) % mod;}
template <typename A> inline void debug(A a){cout << a << '\n';}
template <typename A> inline LL sqr(A x){return 1ll * x * x;}
char c = getchar(); int x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
int N, M;
vector<Pair> v[MAXN];
double a[MAXN], dis[MAXN];
int vis[MAXN], times[MAXN], can[MAXN];
bool SPFA(int S,  double k) {
queue<int> q; q.push(S);
for(int i = 1; i <= N; i++) vis[i] = 0, times[i] = 0, dis[i] = INF;
dis[S] = 0;
times[S]++;
while(!q.empty()) {
int p = q.front(); q.pop(); vis[p] = 0;
can[p] = 1;
for(auto &sta : v[p]) {
int to = sta.fi; double w = sta.se;
if(chmin(dis[to], dis[p] + w - k)) {
if(!vis[to]) q.push(to), vis[to] = 1, times[to]++;
if(times[to] > 50) return 1;
}
}
}
return 0;
}
bool check(double val) {
memset(can, 0, sizeof(can));
for(int i = 1; i <= N; i++)
if(!can[i] && SPFA(i, val)) return 1;
return 0;
}
signed main() {
//Fin(a);
for(int i = 1; i <= M; i++) {
v[x].push_back({y, z});
}
double l = -1e7 - 10, r = 1e7 + 10;
while(r - l > eps) {
double mid = (l + r) / 2;
if(check(mid)) r = mid;
else l = mid;
}
printf("%.8lf", l);
return 0;
}
/*
10 3
aaaabbbbab
7 7 3 9 10 6 7 6 6 1
2 6 2
1 3 1
2 9 1
*/

0 条评论

• ### cf121C. Lucky Permutation(康托展开)

由于阶乘的数量增长非常迅速，而$$k$$又非常小，那么显然最后的序列只有最后几位会发生改变。

• ### 洛谷P4589 [TJOI2018]智力竞赛(二分答案 二分图匹配)

多读读题就会发现题目要求的就是可相交的最小路径覆盖，那么按照套路先floyd一遍，如果能联通的话就再二分图中加边，然后判一下最大匹配数就行了。刚开始以为因为有的...

• ### cf900D. Unusual Sequences(容斥 莫比乌斯反演)

考虑容斥，设$$g[i]$$表示满足和为$$i$$的序列的方案数，显然$$g[i] = 2^{i-1}$$(插板后每空位放不放)

• ### BZOJ3122: [Sdoi2013]随机数生成器(BSGS)

直接把$$X_{i+1} = (aX_i + b) \pmod P$$展开，推到最后会得到这么个玩意儿