国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

BZOJ 2118 墨墨的等式

2019-11-06 06:35:06
字體:
來源:轉載
供稿:網友

模意義下最短路

掛題解 http://blog.csdn.net/PoPoQQQ/article/details/46605701

#include<cstdio>#include<cstring>#include<queue>#include<algorithm>#define N 500005#define M 14using namespace std;namespace runzhe2000{ typedef long long ll; const ll INF = 1ll<<60; ll dis[N], Bmin, Bmax; bool inq[N]; int ecnt, n, last[N], a[M]; struct edge{int next, to, val;}e[N*M]; void addedge(int a, int b, int c) { e[++ecnt] = (edge){last[a], b, c}; last[a] = ecnt; } void SPFA() { queue<int> q; q.push(0); for(int i = 0; i < a[1]; i++) dis[i] = INF; dis[0] = 0; for(; !q.empty(); q.pop()) { int x = q.front(); inq[x] = 0; for(int i = last[x]; i; i = e[i].next) { int y = e[i].to; if(dis[x] + e[i].val < dis[y]) { dis[y] = dis[x] + e[i].val; if(!inq[y])q.push(y), inq[y] = 1; } } } } ll calc(ll lim, ll a, int b) // 干,沒注意到a也要看long long,調了好一會兒 { if(lim < a) return 0; else return (lim - a) / b + 1; } void main() { scanf("%d%lld%lld",&n,&Bmin,&Bmax); for(int i = 1; i <= n; i++) { scanf("%d",&a[i]); if(!a[i]){i--; n--; continue;} } sort(a+1, a+1+n); for(int i = 0; i < a[1]; i++) for(int j = 2; j <= n; j++) addedge(i, (i+a[j])%a[1], a[j]); SPFA(); ll ans = 0; for(int i = 0; i < a[1]; i++) { if(dis[i] == INF) continue; ans += calc(Bmax, dis[i], a[1]); ans -= calc(Bmin-1, dis[i], a[1]); }
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 抚远县| 禹城市| 乌兰县| 定结县| 平昌县| 金华市| 鄂温| 天峨县| 乌苏市| 新巴尔虎左旗| 井陉县| 阿拉善右旗| 浦北县| 阳高县| 肥乡县| 桂阳县| 金坛市| 工布江达县| 铜梁县| 迁西县| 阳信县| 仁寿县| 金寨县| 紫金县| 湄潭县| 佛坪县| 淳化县| 保康县| 翁源县| 凤庆县| 澳门| 绥阳县| 墨脱县| 凤台县| 故城县| 喜德县| 监利县| 阳山县| 桑日县| 家居| 台北县|