zoukankan      html  css  js  c++  java
  • Pahom on Water(最大流)

    Pahom on Water

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 770    Accepted Submission(s): 353

    Problem Description
    Pahom on Water is an interactive computer game inspired by a short story of Leo Tolstoy about a poor man who, in his lust for land, forfeits everything. The game's starting screen displays a number of circular pads painted with colours from the visible light spectrum. More than one pad may be painted with the same colour (defined by a certain frequency) except for the two colours red and violet. The display contains only one red pad (the lowest frequency of 400 THz) and one violet pad (the highest frequency of 789 THz). A pad may intersect, or even contain another pad with a different colour but never merely touch its boundary. The display also shows a figure representing Pahom standing on the red pad. The game's objective is to walk the figure of Pahom from the red pad to the violet pad and return back to the red pad. The walk must observe the following rules: 1.If pad α and pad β have a common intersection and the frequency of the colour of pad α is strictly smaller than the frequency of the colour of pad β, then Pahom figure can walk from α to β during the walk from the red pad to the violet pad 2. If pad α and pad β have a common intersection and the frequency of the colour of pad α is strictly greater than the frequency of the colour of pad β, then Pahom figure can walk from α to β during the walk from the violet pad to the red pad 3. A coloured pad, with the exception of the red pad, disappears from display when the Pahom figure walks away from it. The developer of the game has programmed all the whizzbang features of the game. All that is left is to ensure that Pahom has a chance to succeed in each instance of the game (that is, there is at least one valid walk from the red pad to the violet pad and then back again to the red pad.) Your task is to write a program to check whether at least one valid path exists in each instance of the game.
     
    Input
    The input starts with an integer K (1 <= K <= 50) indicating the number of scenarios on a line by itself. The description for each scenario starts with an integer N (2 <= N <= 300) indicating the number of pads, on a line by itself, followed by N lines that describe the colors, locations and sizes of the N pads. Each line contains the frequency, followed by the x- and y-coordinates of the pad's center and then the radius. The frequency is given as a real value with no more than three decimal places. The coordinates and radius are given, in meters, as integers. All values are separated by a single space. All integer values are in the range of -10,000 to 10,000 inclusive. In each scenario, all frequencies are in the range of 400.0 to 789.0 inclusive. Exactly one pad will have a frequency of “400.0” and exactly one pad will have a frequency of “789.0”.
     
    Output
    The output for each scenario consists of a single line that contains: Game is VALID, or Game is NOT VALID
     
    Sample Input
    2 2 400.0 0 0 4 789.0 7 0 2 4 400.0 0 0 4 789.0 7 0 2 500.35 5 0 2 500.32 5 0 3
     
    Sample Output
    Game is NOT VALID Game is VALID

    题解:题意就是光圈相交了才能走,只能从频率大的到小的,问是否能从红光到紫光再回到红光,红光到紫光频率要从小到大<<<<紫光到红光频率要从大到小>>>>>,由此直接红光与源点连,紫光连汇点,频率从小到大,就加边,能从红到紫,自然能从紫到红了;

    代码:

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    #include<queue>
    #include<vector>
    using namespace std;
    #define mem(x,y) memset(x,y,sizeof(x))
    const int INF=0x3f3f3f3f;
    const int MAXN=310;
    const int MAXM=90010<<1;
    struct Edge{
        int from,to,next,cup,flow;
    };
    Edge edg[MAXM];
    int head[MAXM],dis[MAXN],edgnum,vis[MAXN],h[MAXM];
    void initial(){
        edgnum=0;mem(head,-1);
    }
    struct Dot{
        double fq,x,y,r;
    }dt[310];
    void add(int u,int v,int w){
        Edge E={u,v,head[u],w,0};
        edg[edgnum]=E;
        head[u]=edgnum++;
        E={v,u,head[v],0,0};
        edg[edgnum]=E;
        head[v]=edgnum++;
    }
    bool bfs(int s,int e){
        mem(dis,-1);mem(vis,0);
        queue<int>dl;
        dis[s]=0;vis[s]=1;dl.push(s);
        while(!dl.empty()){
            int u=dl.front();
            dl.pop();
            for(int i=head[u];i!=-1;i=edg[i].next){
                Edge v=edg[i];
                if(!vis[v.to]&&v.cup-v.flow){
                    vis[v.to]=1;
                    dis[v.to]=dis[u]+1;
                    dl.push(v.to);//
                    if(v.to==e)return true;
                }
            }
        }
        return false;
    }
    int dfs(int x,int la,int e){
        
        if(x==e||la==0)return la;
        int temp,flow=0;
        for(int i=h[x];i!=-1;i=edg[i].next){
            Edge &v=edg[i];
            if(dis[v.to]==dis[x]+1&&(temp=dfs(v.to,min(la,v.cup-v.flow),e))>0){
                flow+=temp;
                v.flow+=temp;
                edg[i^1].flow-=temp;
                la-=temp;
                if(la==0)break;
            }
        }
        return flow;
    }
    int maxflow(int s,int e){
        int flow=0;
        while(bfs(s,e)){
            memcpy(h,head,sizeof(head));
            flow+=dfs(s,INF,e);
        }
        return flow;
    }
    bool judge(Dot a,Dot b){
        if(a.fq<b.fq&&(pow(b.x-a.x,2)+pow(b.y-a.y,2)<pow(b.r+a.r,2)))return true;
         return false;
    }
    int main(){
        int k,N;
        scanf("%d",&k);
        while(k--){
            initial();
            scanf("%d",&N);
            for(int i=1;i<=N;i++){
                scanf("%lf%lf%lf%lf",&dt[i].fq,&dt[i].x,&dt[i].y,&dt[i].r);
                if(fabs(789.0-dt[i].fq)<=1e-5)add(i,N+1,2);
                if(fabs(dt[i].fq-400.0)<=1e-5)add(0,i,2);
            }
            for(int i=1;i<=N;i++){
                for(int j=1;j<=N;j++){
                    if(i==j)continue;
                    if(judge(dt[i],dt[j]))add(i,j,1);
                }
            }
            if(maxflow(0,N+1)==2)puts("Game is VALID");
            else puts("Game is NOT VALID");
        }
        return 0;
    }
  • 相关阅读:
    jQuery form插件的使用--处理server返回的JSON, XML,HTML数据
    jQuery form插件的使用--使用 fieldValue 方法校验表单
    jQuery form插件的使用--用 formData 参数校验表单,验证后提交(简单验证).
    jQuery form插件的使用--ajaxForm()和ajaxSubmit()的可选参数项对象
    jQuery Form 表单提交插件-----formSerialize,fieldSerialize,fieldValue,resetForm,clearForm,clearFields的 应用
    jQuery Form 表单提交插件-----ajaxSubmit() 的应用
    jQuery Form 表单提交插件-----ajaxForm() 的应用
    jQuery Form 表单提交插件----Form 简介,官方文档,官方下载地址
    jQuery Validate 表单验证插件----自定义一个验证方法
    jQuery Validate 表单验证插件----自定义校验结果样式
  • 原文地址:https://www.cnblogs.com/handsomecui/p/4944856.html
Copyright © 2011-2022 走看看