bzoj1603: [Usaco2008 Oct]打谷机 (纱布题)
Time Limit: 5 Sec Memory Limit: 64 MB Submit: 774 Solved: 593 [Submit][Status][Discuss]
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
思路:傻逼模拟题。。。。排下序。
/* ***********************************************
Author :111qqz
Created Time :2016年03月31日 星期四 21时04分09秒
File Name :code/bzoj/1603.cpp
************************************************ */
1#include <cstdio>
2#include <cstring>
3#include <iostream>
4#include <algorithm>
5#include <vector>
6#include <queue>
7#include <set>
8#include <map>
9#include <string>
10#include <cmath>
11#include <cstdlib>
12#include <ctime>
13#define fst first
14#define sec second
15#define lson l,m,rt<<1
16#define rson m+1,r,rt<<1|1
17#define ms(a,x) memset(a,x,sizeof(a))
18typedef long long LL;
19#define pi pair < int ,int >
20#define MP make_pair
1using namespace std;
2const double eps = 1E-8;
3const int dx4[4]={1,0,0,-1};
4const int dy4[4]={0,-1,1,0};
5const int inf = 0x3f3f3f3f;
6const int N=1005;
7int n;
1struct node
2{
3 int s,d,c;
1 bool operator < (node b)const
2 {
3 return s<b.s;
4 }
5}a[N];
6int main()
7{
8 #ifndef ONLINE_JUDGE
9 freopen("code/in.txt","r",stdin);
10 #endif
11 cin>>n;
12 for ( int i = 1 ; i <= n-1 ; i ++) cin>>a[i].s>>a[i].d>>a[i].c;
1 sort(a+1,a+n);
2 int flag = 0;
3 for ( int i = 1 ;i <= n-1 ; i++)
4 {
5 if (a[i].c==1) flag^=1;
6 }
7 cout<<flag<<endl;
1 #ifndef ONLINE_JUDGE
2 fclose(stdin);
3 #endif
4 return 0;
5}