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. VOL.1 利用vmware ThinApp 制作非XP下可以运行的IE6 【无插件版】(windows vista/7/8 x86/x64 )

    作为一名前端开发工程师,不免要考虑IE6的兼容性,但是大部分挑剔的同行们估计都不会用XP,所以基本上IE6的兼容性测试,都是使用IE Tester或者虚拟机. IE Tester的话,很多地方模拟的还 ...

  2. mybatis缓存清除方法

    String cacheName = IWenshiduDao.class.getName(); Ehcache cache = CacheManager.create().getEhcache(ca ...

  3. jmeter中webdriver插件,进行自动化压测

    1.下载JMeterPlugins-WebDriver-1.1.2 2.将JMeterPlugins-WebDriver-1.1.2\lib\ext中的*.jar拷贝到D:\apache-jmeter ...

  4. iOS崩溃报告获取二

    // // JKExceptionHandler.h // JKExceptionHandler // // Created by Jack on 16/9/7. // Copyright © 201 ...

  5. html-----006

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. 使用gdb跟踪Linux内核启动过程(从start_kernel到init进程启动)

    本次实验过程如下: 1. 运行MenuOS系统 在实验楼的虚拟机环境里,打击打开shell,使用下面的命令 cd LinuxKernel/ qemu -kernel linux-/arch/x86/b ...

  7. pushState与replaceState区别

    history.pushState(state, title, url) 将当前URL和history.state加入到history中,并用新的state和URL替换当前.不会造成页面刷新. sta ...

  8. freeswitch 拨号时添加自定义变量

    Using Channel Variables in Dialplan Condition Statements Channel variables can be used in conditions ...

  9. str、__str__ 、repr、 __repr__、``

    内建函数str()和repr() 或反引号操作符(``)可以方便地以字符串的方式获取对象的内容.类型.数值属性等信息. str()函数得到的字符串可读性好(故被print调用),而结果通常无法用eva ...

  10. linux c++ 遍历一个目录下的文件名 (包括子目录的文件名)

    最近写代码有一个要遍历目录下的每一个文件并取得这个文件的绝对路径的需求, 我们知道linux c++中有system命令所以我在代码中 先生成了一个log,然后去读log文件的每一行文件名,然后给存储 ...