zoukankan      html  css  js  c++  java
  • P2868 [USACO07DEC]Sightseeing Cows G(分数规划)

    include

    include

    include

    include

    include

    using namespace std;
    int n,p;
    double a[1000001];
    int x,y,z;
    struct e{
    int to;
    int v;
    int ne;
    }ed[1000001];
    int pp;
    int head[100001];
    void add(int f,int to,int ne){
    ed[++pp].to=to;
    ed[pp].ne=head[f];
    ed[pp].v=ne;
    head[f]=pp;
    }
    int vis[1000001];
    double dis[1000001];
    int num[1000001];
    bool check(double ke){
    queue q;
    for(int i=1;i<=n;++i){
    q.push(i);
    dis[i]=0;
    vis[i]=1;
    num[i]=1;
    }
    while(!q.empty()){
    int x=q.front();
    q.pop();
    vis[x]=0;
    for(int i=head[x];i;i=ed[i].ne){
    int v=ed[i].to;
    if(dis[v]>(double)dis[x]+keed[i].v-a[x]){
    dis[v]=(double)dis[x]+ke
    ed[i].v-a[x];
    if(!vis[v]){
    q.push(v);
    vis[v]=1;
    if(++num[v]>=n+10){
    return 1;
    }
    }

    		}
    	}
    }
    return 0;
    

    }
    int main(){
    scanf("%d%d",&n,&p);
    for(int i=1;i<=n;++i){
    cin>>a[i];
    }
    for(int i=1;i<=p;++i){
    scanf("%d%d%d",&x,&y,&z);
    add(x,y,z);
    }
    double l=0,r=1000010;
    while(r-l>1e-4){
    double mid=(l+r)/2;
    if(check(mid)){
    l=mid;
    }else
    r=mid;
    }
    printf("%.2lf",l);
    return 0;
    }

  • 相关阅读:
    尺取法 C
    并查集
    欧拉路与欧拉回路
    C
    最大连续区间和算法总结
    C
    python中的random函数方法
    Python可视化
    MFC学习之模态对话框和非模态对话框
    dropna
  • 原文地址:https://www.cnblogs.com/For-Miku/p/15130692.html
Copyright © 2011-2022 走看看