USACO 2.3 Controlling Companies

TASK: concom
LANG: C++

Compiling...
Compile: OK

Executing...
   Test 1: TEST OK [0.000 secs, 3068 KB]
   Test 2: TEST OK [0.000 secs, 3068 KB]
   Test 3: TEST OK [0.000 secs, 3068 KB]
   Test 4: TEST OK [0.000 secs, 3068 KB]
   Test 5: TEST OK [0.000 secs, 3068 KB]
   Test 6: TEST OK [0.000 secs, 3068 KB]
   Test 7: TEST OK [0.000 secs, 3068 KB]
   Test 8: TEST OK [0.000 secs, 3068 KB]
   Test 9: TEST OK [0.351 secs, 3068 KB]

All tests OK.
1 /*
2 PROG: concom
3 ID: jiafeim1
4 LANG: C++
5 */
6
7 #include <algorithm>
8 #include <iostream>
9 #include <fstream>
10
11 using namespace std;
12
13 int n=0;
14
15 int control[104][104] = {0};
16 int temp[104];
17 std::ofstream fout("concom.out");
18
19 void work(int com)
20 {
21 for(int i = 0 ;i!=n;++i)
22 temp[i] = 0;
23 bool haveDo = false;
24 int last = 0;
25 for(int i = 0; i!=n;++i)
26 {
27 temp[i]=control[com][i];
28 if(control[com][i]>50)
29 {
30 haveDo = true;
31 ++last;
32 }
33 }
34
35 int count = 0;
36 bool havePlus[105] = {false};
37 int temp_last = 0;
38 while(haveDo && count++<n)
39 {
40 haveDo = false;
41 for(int i = 0;i!=n;++i)
42 {
43 if(!havePlus[i] && temp[i]>50)
44 {
45 havePlus[i] = true;
46 for(int j = 0;j!=n;++j)
47 {
48 temp[j] += control[i][j];
49 }
50 }
51 }
52 for(int i = 0 ;i!=n;++i)
53 if(temp[i]>50)
54 ++temp_last;
55
56 if(temp_last>last)
57 {
58 last = temp_last;
59 haveDo = true;
60 }
61
62 }
63
64 for(int i = 0 ;i!=n;++i)
65 {
66 if(temp[i]>50 && i!=com)
67 fout<<com+1<<" "<<i+1<<endl;
68 }
69 }
70
71 int main()
72 {
73 std::ifstream fin("concom.in");
74
75
76 int x;
77 fin>>x;
78
79 int t1,t2,t3;
80 for(int i = 0 ;i!=x;++i)
81 {
82 fin>>t1>>t2>>t3;
83 if(t1>n) n = t1;
84 if(t2>n) n = t2;
85 control[t1-1][t2-1] = t3;
86 }
87
88 for(int i = 0;i!=n;++i)
89 {
90 work(i);
91 }
92 fin.close();
93 fout.close();
94
95 }
posted @ 2011-05-07 00:02  幻魇  阅读(299)  评论(0)    收藏  举报