• 【BZOJ】1603: [Usaco2008 Oct]打谷机(水题+dfs)


    http://www.lydsy.com/JudgeOnline/problem.php?id=1603

    这种水题。。。

    dfs没话说。。

    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <string>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    #define rep(i, n) for(int i=0; i<(n); ++i)
    #define for1(i,a,n) for(int i=(a);i<=(n);++i)
    #define for2(i,a,n) for(int i=(a);i<(n);++i)
    #define for3(i,a,n) for(int i=(a);i>=(n);--i)
    #define for4(i,a,n) for(int i=(a);i>(n);--i)
    #define CC(i,a) memset(i,a,sizeof(i))
    #define read(a) a=getint()
    #define print(a) printf("%d", a)
    #define dbg(x) cout << #x << " = " << x << endl
    #define printarr(a, n, m) rep(aaa, n) { rep(bbb, m) cout << a[aaa][bbb]; cout << endl; }
    inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
    inline const int max(const int &a, const int &b) { return a>b?a:b; }
    inline const int min(const int &a, const int &b) { return a<b?a:b; }
    
    const int N=1005;
    int ihead[N], inext[N], to[N], cnt, d[N], f[N], n, vis[N];
    void dfs(const int &x, const int &t) {
    	if(vis[x]) return;
    	vis[x]=1;
    	f[x]=t;
    	for(int i=ihead[x]; i; i=inext[i]) dfs(to[i], t^d[i]);
    }
    
    int main() {
    	read(n);
    	int u, v, w;
    	rep(i, n-1) {
    		read(u); read(v); read(w);
    		inext[++cnt]=ihead[u]; ihead[u]=cnt; to[cnt]=v; d[cnt]=w;
    	}
    	dfs(1, 0);
    	print(f[n]);
    	return 0;
    }
    

    Description

    Farmer John有一个过时的打谷机(收割小麦),它需要带子来带动。发动机驱动轮1总是顺时针旋转的,用来带动转轮2,转轮2来带动转轮3,等等。一共有n(2<=n<=1000)个转轮(n-1条带子)。 上面的图解描述了转轮的两种连接方式,第一种方式使得两个轮子旋转的方向相同,第二种则相反。 给出一串带子的信息: *Si—驱动轮 *Di—被动轮 *Ci—连接的类型(0=直接连接,1=交叉连接) 不幸的是,列出的信息是随即的。 作为样例,考虑上面的图解,n=4,转轮1是驱动轮,可以得知最后转轮4是逆时针旋转的。

    Input

    *第一行:一个数n *第二行到第n行:每一行有三个被空格隔开的数:Si,Di,Ci

    Output

    *第一行:一个单独的数,表示第n个转轮的方向,0表示顺时针,1表示逆时针。

    Sample Input

    4
    2 3 0
    3 4 1
    1 2 0

    Sample Output

    1

    HINT

    Source

  • 相关阅读:
    php安装xcache (5.4)
    nginx博客系统(内含nginx图片缩略图处理代码,不错)
    一个mysql开启多个端口
    mysql源码重启
    ecshop支付时减库存方法
    n阶幻方问题
    codeforces 710A King Moves(水)
    关于ios::sync_with_stdio(false);和 cin.tie(0)加速c++输入输出流
    codeforces 701C. They Are Everywhere(尺取法)
    codeforces 701 B. Cells Not Under Attack
  • 原文地址:https://www.cnblogs.com/iwtwiioi/p/3949073.html
Copyright © 2020-2023  润新知