• bzoj3417:[POI2013]MOR-Tales of seafaring


    传送门

    这个题比较水,很容易看出
    1、最短路小于d,直接看奇偶性就好了
    2,最短路大于d,puts("NIE ");
    主要就是判奇偶性的问题,将每个点拆成奇点和偶点跑bfs就行了
    在线需要开short,不然空间会炸,离线就没有这个忧虑
    代码:

    #include<cstdio>
    #include<iostream>
    #include<algorithm>
    #include<queue>
    using namespace std;
    void read(int &x) {
        char ch; bool ok;
        for(ok=0,ch=getchar(); !isdigit(ch); ch=getchar()) if(ch=='-') ok=1;
        for(x=0; isdigit(ch); x=x*10+ch-'0',ch=getchar()); if(ok) x=-x;
    }
    #define rg register
    const int maxn=5e3+1;
    int n,m,k,ans,pre[maxn*4],nxt[maxn*4],h[maxn*2],cnt;
    short g[maxn][maxn*2];
    queue<int>q;
    void add(int x,int y)
    {
    	pre[++cnt]=y,nxt[cnt]=h[x],h[x]=cnt;
    	pre[++cnt]=x,nxt[cnt]=h[y],h[y]=cnt;
    }
    void bfs(int y)
    {
    	q.push(y);
    	while(!q.empty())
    	{
    		int x=q.front();q.pop();
    		for(rg int i=h[x];i;i=nxt[i])
    			if(!g[y][pre[i]])g[y][pre[i]]=g[y][x]+1,q.push(pre[i]);
    	}
    }
    int main()
    {
    	read(n),read(m),read(k);
    	for(rg int i=1,x,y;i<=m;i++)read(x),read(y),add(x,y+n),add(x+n,y);
    	for(rg int i=1;i<=n;i++)bfs(i);
    	for(rg int i=1,x,y,z;i<=k;i++)
    	{
    		read(x),read(y),read(z);
    		if(z&1)(g[x][y+n]&&g[x][y+n]<=z)?printf("TAK
    "):printf("NIE
    ");
    		else (g[x][y]&&g[x][y]<=z)?printf("TAK
    "):printf("NIE
    ");
    	}
    }
    
  • 相关阅读:
    二分查找
    基本功能
    pandas的数据结构
    部署metrics-server遇到的坑
    Promethus安装指南
    Spark学习笔记
    Hadoop学习笔记
    大数据处理框架
    大数据Hadoop生态圈:Pig和Hive
    Hadoop HA 机制学习
  • 原文地址:https://www.cnblogs.com/lcxer/p/10375423.html
Copyright © 2020-2023  润新知