1603: [Usaco2008 Oct]打谷机

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 602  Solved: 458
[Submit][Status]

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

题解:
太水了。。。一遍dfs
代码:
 const maxn=;
var f:array[..maxn,..maxn] of longint;
g:array[..maxn] of longint;
v:array[..maxn] of boolean;
i,n,x,y,z:longint;
procedure dfs(x:longint);
var i:longint;
begin
v[x]:=true;
for i:= to n do
if (f[x,i]<>) and (not(v[i])) then
begin
if f[x,i]= then g[i]:=g[x] else g[i]:=g[x] xor ;
dfs(i);
end;
end;
begin
assign(input,'input.txt');assign(output,'output.txt');
reset(input);rewrite(output);
readln(n);
for i:= to n- do
begin
readln(x,y,z);inc(z);
f[x,y]:=z;
f[y,x]:=z;
end;
g[]:=;
dfs();
writeln(g[n]);
close(input);close(output);
end.
 

BZOJ1603: [Usaco2008 Oct]打谷机的更多相关文章

  1. bzoj1603: [Usaco2008 Oct]打谷机 (纱布题)

    Description Input Output Sample Input Sample Output Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 7 ...

  2. BZOJ 1603: [Usaco2008 Oct]打谷机

    题目 1603: [Usaco2008 Oct]打谷机 Time Limit: 5 Sec  Memory Limit: 64 MB Description Farmer John有一个过时的打谷机( ...

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

    http://www.lydsy.com/JudgeOnline/problem.php?id=1603 这种水题... dfs没话说.. #include <cstdio> #inclu ...

  4. BZOJ 1603 [Usaco2008 Oct]打谷机 dfs

    题意:id=1603">链接 方法:暴力 解析: 搜1到n路径上的边权异或和-. 这几个水题刷的我有点-.. 代码: #include <cstdio> #include ...

  5. bzoj 1603: [Usaco2008 Oct]打谷机【瞎搞】

    一棵树,碰到改变转向的边就异或一下,从1dfs一遍 #include<iostream> #include<cstdio> using namespace std; const ...

  6. BZOJ 1603 USACO 2008 Oct. 打谷机

    [题解] 水题.. 保存连接方式,按顺序处理即可. #include<cstdio> #include<algorithm> using namespace std; int ...

  7. bzoj1601: [Usaco2008 Oct]灌水

    经典延伸最小生成树问题... #include<cstdio> #include<cstring> #include<cctype> #include<alg ...

  8. BZOJ1602: [Usaco2008 Oct]牧场行走

    1602: [Usaco2008 Oct]牧场行走 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1084  Solved: 556[Submit][St ...

  9. BZOJ1600: [Usaco2008 Oct]建造栅栏

    1600: [Usaco2008 Oct]建造栅栏 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 825  Solved: 473[Submit][Sta ...

随机推荐

  1. HTML5 Canvas 2D绘图

    为了防止无良网站的爬虫抓取文章,特此标识,转载请注明文章出处.LaplaceDemon/ShiJiaqi. http://www.cnblogs.com/shijiaqi1066/p/4851774. ...

  2. Caused by: java.lang.ClassNotFoundException: com/sun/tools/internal/xjc/api/XJC

    Caused by: java.lang.ClassNotFoundException: com/sun/tools/internal/xjc/api/XJC 缺少com/sun/tools/inte ...

  3. 服務器提交協議衝突 (The server committed a protocol violation.)

    ---解決方法 (放在 app.config / web.config)--- <system.net> <settings> <httpWebRequest useUn ...

  4. CI框架篇之控制器篇--设置路由(1)

    CodeIgniter 定义默认控制器 当你的网站不存在某个URI 或者 用户直接从根目录访问的时候,CodeIgniter 会加载默认控制器. 打开 application/config/route ...

  5. CI框架篇之模型篇--AR操作(2)

    CodeIgniter 和众多的框架一样,有属于自己的一套对数据库的操作方式,本框架更是如此 有属于自己的一套对数据库的安全并且简单的操作, 成为AR操作:下面来对AR操作进行介绍: 首先,确定要启动 ...

  6. Nico Game Studio 3.地图纹理编辑 物体皮肤编辑

    完成功能: 1.地图纹理编辑功能. 图层编辑,添加/删除纹理,地图编辑.网格绘制.

  7. android - android Couldn't load runtimecore_java from loader

    在写Arcgis Android 或百度Android的时候,有时会报诸如,java.lang.UnsatisfiedLinkError:android Couldn't load runtimeco ...

  8. js setInterval和clearInterval 的使用

    setInterval(函数名, 时间);   函数名:不需要加括号:  时间:单位是毫秒: 例子: var inter= setInterval(searchTasksByCnd, 10 * 100 ...

  9. vi 替换字符串

    假如说我想把该文件中所有的Web替换成SOR_SYS,那么我们可以用vi打开该文件,然后按一下: 你的命令行的最后一行会出现:,这个时候就是提醒你输入替换的命令 %s/Web/SOR_SYS/g 按一 ...

  10. CSS Display(显示) 与 Visibility(可见性)

    display属性设置一个元素应如何显示,visibility属性指定一个元素应可见还是隐藏. Box 1 Box 2 Box 3 隐藏元素 - display:none或visibility:hid ...