1 条题解

  • 0
    @ 2023-6-21 19:29:35

    C++ :

    #include<set>
    #include<map>
    #include<cmath>
    #include<queue>
    #include<bitset>
    #include<string>
    #include<cstdio>
    #include<cctype>
    #include<cassert>
    #include<cstdlib>
    #include<cstring>
    #include<sstream>
    #include<iostream>
    #include<algorithm>
    
    #define For(i,x,y) for (int i=x;i<y;i++)
    #define pb push_back
    #define mp make_pair
    #define fi first
    #define se second
    #define lf else if
    
    #define dprintf(...) fprintf(stderr,__VA_ARGS__)
    using namespace std;
    
    typedef long long ll;
    typedef double db;
    typedef pair<int,int> pii;
    typedef vector<int> Vi;
    
    int IN(){
    	int c,f,x;
    	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
    	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
    }
    
    const int N=500+19;
    const int M=200000;
    const int oo=(1<<30)-1;
    
    struct Edge{
    	int y,f,nxt;
    } E[M];
    
    int vis[N],x[N],y[N],r[N],w[N],dis[N],las[N];
    int n,m,cnt,S,T,tot,X,Y,W,sum;
    
    void Add_Edge(int x,int y,int f){
    	E[cnt]=(Edge){y,f,las[x]};las[x]=cnt++;
    	E[cnt]=(Edge){x,0,las[y]};las[y]=cnt++;
    }
    bool bfs(){
    	static int Q[N];
    	int f=1,w=0;Q[1]=S;
    	memset(dis,-1,sizeof(dis));
    	dis[S]=1;
    	while (f>w){
    		int x=Q[++w];
    		for (int i=las[x],y;~i;i=E[i].nxt)
    			if (E[i].f&&dis[y=E[i].y]==-1){
    				dis[y]=dis[x]+1;
    				Q[++f]=y;
    				if (y==T) return 1;
    			}
    	}
    	return 0;
    }
    int dinic(int x,int flow){
    	if (x==T||!flow) return flow;
    	int res=0;
    	for (int i=las[x],y;~i&&flow;i=E[i].nxt)
    		if (E[i].f&&dis[y=E[i].y]==dis[x]+1){
    			int tmp=dinic(y,min(flow,E[i].f));
    			res+=tmp,flow-=tmp,E[i].f-=tmp,E[i^1].f+=tmp;
    		}
    	if (!res) dis[x]=-1;
    	return res;
    }
    
    int sqr(int x){
    	return x*x;
    }
    void Main(){
    	memset(las,-1,sizeof(las));
    	cnt=0;sum=0;
    	n=IN(),m=IN();
    	For(i,1,n+1){
    		x[i]=IN(),y[i]=IN(),w[i]=IN(),r[i]=IN();
    	}
    	tot=n;
    	S=++tot;T=++tot;
    	For(i,1,m+1){
    		int chk=0;
    		X=IN(),Y=IN(),W=IN();
    		if (sqr(x[1]-X)+sqr(y[1]-Y)<=sqr(r[1])){
    			w[1]+=W;
    			continue;
    		}
    		For(j,2,n+1){
    			if (sqr(x[j]-X)+sqr(y[j]-Y)<=sqr(r[j])) chk=1;
    		}
    		if (!chk) continue;
    		tot++;
    		Add_Edge(S,tot,W);
    		sum+=W;
    		For(j,2,n+1){
    			if (sqr(x[j]-X)+sqr(y[j]-Y)<=sqr(r[j])){
    				Add_Edge(tot,j,oo);
    			}
    		}
    	}
    	For(i,2,n+1){
    		if (w[i]>w[1]){
    			puts("qaq");
    			return;
    		}
    		Add_Edge(i,T,w[1]-w[i]);
    	}
    	while (bfs()) sum-=dinic(S,oo);
    	puts(sum==0?"ZQC! ZQC!":"qaq");
    }
    
    int main(){
    	for (int T=IN();T--;) Main();
    }
    
    • 1

    #505. 「邢台编程 β Round」ZQC 的游戏

    信息

    ID
    985
    时间
    1000ms
    内存
    256MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者