zoukankan      html  css  js  c++  java
  • 移动游戏By HYJ


    暴力求SG函数即可,记忆化贼方便

    /*program from Wolfycz*/
    #include<cmath>
    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    #define inf 0x7f7f7f7f
    using namespace std;
    typedef long long ll;
    typedef unsigned int ui;
    typedef unsigned long long ull;
    inline int read(){
    	int x=0,f=1;char ch=getchar();
    	for (;ch<'0'||ch>'9';ch=getchar())	if (ch=='-')    f=-1;
    	for (;ch>='0'&&ch<='9';ch=getchar())	x=(x<<1)+(x<<3)+ch-'0';
    	return x*f;
    }
    inline void print(int x){
    	if (x>=10)     print(x/10);
    	putchar(x%10+'0');
    }
    const int N=1e4,M=1e5;
    int pre[M+10],now[N+10],child[M+10],tot;
    int can[N+10];
    int n,m;
    void join(int x,int y){pre[++tot]=now[x],now[x]=tot,child[tot]=y;}
    void dfs(int x){
    	if (can[x]!=-1)	return;
    	bool flag=0;
    	for (int p=now[x],son=child[p];p;p=pre[p],son=child[p]){
    		dfs(son);
    		if (!can[son])	flag=1;
    	}
    	can[x]=flag;
    }
    void init(){
    	tot=0;
    	memset(now,0,sizeof(now));
    	memset(can,-1,sizeof(can));
    }
    int main(){
    	for (int Data=read();Data;Data--){
    		init();
    		n=read(),m=read(),can[n]=0;
    		for (int i=1;i<=m;i++){
    			int x=read(),y=read();
    			join(x,y);
    		}
    		dfs(1);
    		printf(can[1]?"yes":"no");
    		putchar('
    ');
    	}
    	return 0;
    }
    
  • 相关阅读:
    数组去重的方法
    ES5-ES8 数组拥有的方法
    常用的git操作命令
    vue中使用vue-echarts
    js的深复制与浅复制
    express 4.x 搭建Node项目框架
    网页布局分类
    shadow---实例
    animate动画解析
    3d------正方体
  • 原文地址:https://www.cnblogs.com/Wolfycz/p/8434304.html
Copyright © 2011-2022 走看看