# 【SCOI2003】【BZOJ1092】蜘蛛难题

Input

Output

Sample Input

2
2 0 6
5 1 6
1
3 4 2
2 2

Sample Output

9

Hint

 1 #include<iostream>
2 #include<cstdio>
3 #include<cstring>
4 #include<cmath>
5 #include<algorithm>
6 #define N 30
7 #define M 110
8
9 using namespace std;
10
11 int n,m,S,T;
13 struct Node
14 {
15     int x,y,h,v;
16 }a[N];
17
18 void add(int u,int v,int fee)
19 {
20     cnt++;
23     rea[cnt]=v;
24     val[cnt]=fee;
25 }
26 int find(int x)
27 {
28     for (int i=1;i<=n;i++)
29         if (a[i].x==x) return i;
30     return 0;
31 }
32 int main()
33 {
35     int ans=0;
36     scanf("%d",&n);
37     for (int i=1;i<=n;i++)
38         scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].h);
39     for (int i=1;i<=n;i++)
40         a[i].h+=a[i].y;
41     a[1].v=1;
42     scanf("%d",&m);
43     int x,y,len;
44     for (int i=1;i<=m;i++)
45     {
46         scanf("%d%d%d",&x,&y,&len);
47         int st=find(x-1),ed=find(x+len);
49     }
50     scanf("%d%d",&S,&T);
51     while (1)
52     {
53         x=1;
54         while (x)
55         {
56             x=0;
57             for (int i=1;i<=n;i++)
58                 if (a[i].v)
60                 {
61                     int v=rea[j],fee=val[j];
62                     if (a[i].h<=fee&&!a[v].v) a[v].v=x=1;
63                 }
64         }
65         int mx=-1;
66         for (int i=1;i<=n;i++)
67             if (a[i].v) mx=max(mx,a[i].h);
68         if (a[S].v&&mx==T)
69         {
70             printf("%d\n",ans);
71             return 0;
72         }
73         for (int i=1;i<=n;i++)
74             if (a[i].v&&a[i].h==a[i].y&&mx==a[i].y)
75             {
76                 printf("-1\n");
77                 return 0;
78             }
79         for (int i=1;i<=n;i++)
80             if (a[i].v&&a[i].h==mx)
81             {
82                 a[i].h--;
83                 ans++;
84             }
85     }
86 }

posted @ 2017-10-06 20:10  Kaiser-  阅读(117)  评论(0编辑  收藏  举报