zoukankan      html  css  js  c++  java
  • 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
    ");
    	}
    }
    
  • 相关阅读:
    django之数据库orm
    Python的迭代器和生成器
    xhprof 安装使用
    http_load
    sysbench
    LINUX系统下MySQL 压力测试工具super smack
    apache ab工具
    关于流量升高导致TIME_WAIT增加,MySQL连接大量失败的问题
    mysql5.6优化
    php-fpm超时时间设置request_terminate_timeout分析
  • 原文地址:https://www.cnblogs.com/lcxer/p/10375423.html
Copyright © 2011-2022 走看看