栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 2233 Pollution

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 2233 Pollution

#include<iostream>#include<cstring>#include<set>#include<stdio.h>using namespace std;enum {    SIZ = 108,};struct Node {    int n;    int d[SIZ];};Node tank[SIZ];set<int> s[SIZ];double dat[2][SIZ];double eps = 1e-4;int T,N,M;bool same(double *a, double *b){    for(int i=1; i<=N; i++){        if( (a[i]>b[i]&&a[i]-b[i]>eps) || (b[i]>a[i]&&b[i]-a[i]>eps)) return false;    }    return true;}void loop(double *cur, double *nex){    memset(nex, 0, sizeof(dat[0]));    int i,j;    double t;    for(i=1; i<=N; i++){        if(tank[i].n==0){ nex[i] = cur[i]; continue;        }        t = cur[i]/tank[i].n;        for(j=0; j<tank[i].n; j++){ nex[tank[i].d[j]] += t;        }    }}void output(double *cur){    for(int i=1; i<=N; i++){        printf("%.3lfn", cur[i]);    }    printf("n");}void fun(){    double *cur = dat[0], *nex=dat[1], *tmp;    do{        loop(cur, nex);        tmp=cur, cur=nex, nex=tmp;    }while(!same(cur, nex));    output(cur);}void readIn(){    scanf("%d%d ", &N,&M);    for(int i=1; i<=N; i++){        scanf("%lf ", &dat[0][i]);        s[i].clear();    }    int a,b;    for(int i=1; i<=M; i++){        scanf("%d%d ", &a,&b);        s[a].insert(b);        s[b].insert(a);    }    for(int i=1; i<=N; i++){        tank[i].n = s[i].size();        a=0;        for(set<int>::iterator it=s[i].begin();     it!=s[i].end(); ++it){ tank[i].d[a++] = *it;        }    }}int main(){    scanf("%d ", &T);    while(T--){        readIn();        fun();    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/379622.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号