superman

聚精会神搞建设 一心一意谋发展
posts - 190, comments - 17, trackbacks - 0, articles - 0
   :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

 1 /* Accepted 1243 C++ 00:00.00 848K */
 2 #include <string>
 3 #include <iostream>
 4 
 5 using namespace std;
 6 
 7 int main()
 8 {
 9     int n; string s;
10     
11     cin >> n;
12     for(int i = 1; i <= n; i++)
13     {
14         int p;
15         cin >> s;
16         
17         p = s.find("://");
18         
19         string protocol = s.substr(0, p);
20         string host = s.substr(p + 3, s.size());
21         string port;
22         string path;
23         
24         p = host.find('/');
25         if(p != string::npos)
26         {
27             path = host.substr(p + 1, host.size());
28             host = host.substr(0, p);
29         }
30         
31         p = host.find(':');
32         if(p != string::npos)
33         {
34             int k;
35             for(k = p + 1; isdigit(host[k]); k++)
36                 port += host[k];
37             host = host.substr(0, p);
38         }
39         
40         cout << "URL #" << i << endl
41              << "Protocol = " << protocol << endl
42              << "Host     = " << host     << endl
43              << "Port     = " << (port == "" ? "<default>" : port) << endl
44              << "Path     = " << (path == "" ? "<default>" : path) << endl << endl;
45     }
46     
47     return 0;
48 }
49 

posted @ 2008-05-08 15:07 superman 阅读(282) | 评论 (0)编辑 收藏

 1 /* Accepted 1242 C++ 00:00.00 844K */
 2 #include <math.h>
 3 #include <iostream>
 4 
 5 using namespace std;
 6 
 7 int main()
 8 {
 9     int w, d, n = 1;
10     while(cin >> w >> d)
11     {
12         if(w == 0 && d == 0)
13             break;
14         
15         double x = log10(d / (w * 810.0)) / log10(0.5* 5730;
16         
17         int ans;
18         if(x <= 10000)
19         {
20             ans = int(x) / 100;
21             if(int(x) % 100 >= 50)
22                 ans++;
23             ans *= 100;
24         }
25         else
26         {
27             ans = int(x) / 1000;
28             if(int(x) % 1000 >= 500)
29                 ans++;
30             ans *= 1000;
31         }
32         
33         cout << "Sample #" << n++ << endl;
34         cout << "The approximate age is " << ans << " years." << endl << endl;
35     }
36     
37     return 0;
38 }
39 

posted @ 2008-05-08 12:20 superman 阅读(316) | 评论 (0)编辑 收藏

 1 /* Accepted 1241 C++ 00:00.00 844K */
 2 #include <math.h>
 3 #include <iostream>
 4 
 5 using namespace std;
 6 
 7 int main()
 8 {
 9     cout.setf(ios_base::showpoint);
10     cout.setf(ios_base::fixed);
11     cout.precision(3);
12     
13     int a, b, c, n = 0;
14     while(cin >> a >> b >> c)
15     {
16         if(a == 0 && b == 0 && c == 0)
17             break;
18         n++;
19         cout << "Triangle #" << n << endl;
20         if(a == -1)
21         {
22             if(b >= c)
23                 cout << "Impossible." << endl;
24             else
25                 cout << "a = " << pow(c * c - b * b, 0.5<< endl;
26         }
27         if(b == -1)
28         {
29             if(a >= c)
30                 cout << "Impossible." << endl;
31             else
32                 cout << "b = " << pow(c * c - a * a, 0.5<< endl;
33         }
34         if(c == -1)
35             cout << "c = " << pow(a * a + b * b, 0.5<< endl;
36         cout << endl;
37     }
38     
39     return 0;
40 }
41 

posted @ 2008-05-08 10:03 superman 阅读(190) | 评论 (0)编辑 收藏

 1 /* Accepted 1240 C++ 00:00.00 840K */
 2 #include <iostream>
 3 
 4 using namespace std;
 5 
 6 int main()
 7 {
 8     int n; cin >> n;
 9     
10     n = 0;
11     string s;
12     while(cin >> s)
13     {
14         n++;
15         cout << "String #" << n << endl;
16         for(int i = 0; i < s.size(); i++)
17             if(s[i] == 'Z')
18                 cout << 'A';
19             else
20                 cout << char(s[i] + 1);
21         cout << endl << endl;
22     }
23     
24     return 0;
25 }
26 

posted @ 2008-05-08 09:37 superman 阅读(278) | 评论 (0)编辑 收藏

 1 /* Accepted 1205 C++ 00:00.00 836K */
 2 #include <iostream>
 3 
 4 using namespace std;
 5 
 6 int main()
 7 {
 8     while(true)
 9     {
10         char a[200= { 0 };
11         char b[200= { 0 };
12         
13         if(cin >> a >> b == false)
14             break;
15         
16         int alen = strlen(a);
17         int blen = strlen(b);
18         
19         for(int i = 0; i < alen / 2; i++)
20             swap(a[i], a[alen - i - 1]);
21         for(int i = 0; i < blen / 2; i++)
22             swap(b[i], b[blen - i - 1]);
23         
24         for(int i = 0; i < alen; i++)
25             a[i] -= (isdigit(a[i]) ? '0' : 'a' - 10);
26         for(int i = 0; i < blen; i++)
27             b[i] -= (isdigit(b[i]) ? '0' : 'a' - 10);
28         
29         char c[200= { 0 };
30         
31         int maxlen = max(alen, blen);
32         for(int i = 0; i < maxlen; i++)
33             c[i] = a[i] + b[i];
34         for(int i = 0; i < maxlen; i++)
35             c[i + 1+= c[i] / 20, c[i] %= 20;
36         
37         if(c[maxlen])
38             maxlen++;
39         
40         char m[] = "0123456789abcdefghij";
41         for(int i = maxlen - 1; i >= 0; i--)
42             cout << m[c[i]];
43         cout << endl;
44     }
45     
46     return 0;
47 }
48 

posted @ 2008-05-07 11:05 superman 阅读(415) | 评论 (0)编辑 收藏

 1 /* Accepted 1203 C++ 00:00.01 924K */
 2 #include <math.h>
 3 #include <iostream>
 4 
 5 using namespace std;
 6 
 7 int n;
 8 double map[100][100];
 9 
10 double prim()
11 {
12     double lowcost[100], ans = 0.0;
13     bool vset[100= { true };
14     
15     for(int i = 1; i < n; i++)
16         lowcost[i] = map[0][i];
17     
18     int v = 0;
19     for(int i = 1; i < n; i++)
20     {
21         double min = INT_MAX; int idx;
22         for(int j = 0; j < n; j++)
23             if(vset[j] == false && lowcost[j] < min)
24             {
25                 min = lowcost[j];
26                 idx = j;
27             }
28         
29         ans += min;
30         
31         vset[idx] = true;
32         v = idx;
33         
34         for(int j = 0; j < n; j++)
35             if(vset[j] == false && map[v][j] < lowcost[j])
36                 lowcost[j] = map[v][j];
37     }
38     return ans;
39 }
40 
41 int main()
42 {
43     cout.setf(ios_base::showpoint);
44     cout.setf(ios_base::fixed);
45     cout.precision(2);
46     
47     int C = 1;
48     
49     cin >> n;
50     
51     while(n)
52     {
53         double x[100], y[100];
54         for(int i = 0; i < n; i++)
55             cin >> x[i] >> y[i];
56         
57         for(int i = 0; i < n - 1; i++)
58         for(int j = i + 1; j < n; j++)
59             map[i][j] = map[j][i] = sqrt(pow(x[i] - x[j], 2+ pow(y[i] - y[j], 2));
60     
61         cout << "Case #" << C++ << ':' << endl;
62         cout << "The minimal distance is: " << prim() << endl;
63         
64         cin >> n;
65         if(n)
66             cout << endl;
67     }
68     
69     return 0;
70 }
71 

posted @ 2008-05-06 07:49 superman 阅读(556) | 评论 (0)编辑 收藏

 1 /* Accepted 1084 C++ 00:00.01 836K */
 2 #include <iostream>
 3 
 4 using namespace std;
 5 
 6 int n, m;
 7 bool map[26][26];
 8 
 9 int x[26]; bool finded;
10 
11 void search(int i)
12 {
13     if(finded)
14         return;
15     if(i > n)
16     {
17         finded = true;
18         return;
19     }
20     for(int col = 1; col <= m; col++)
21     {
22         x[i] = col;
23         
24         int k;
25         for(k = 0; k < n; k++)
26             if(map[i][k] && x[i] == x[k])
27                 break;
28         if(k == n)
29             search(i + 1);
30     }
31 }
32 
33 int main()
34 {
35     freopen("p1084.in""r", stdin);
36     
37     while((cin >> n) && n)
38     {
39         memset(map, falsesizeof(map));
40         
41         char s, t; getchar();
42         for(int i = 0; i < n; i++)
43         {
44             scanf("%c:"&s);
45             while((t = getchar()) != '\n')
46                 map[s - 'A'][t - 'A'= true;
47         }
48         for(m = 1; ; m++)
49         {
50             memset(x, 0sizeof(x));
51             finded = false;
52             search(0);
53             
54             if(finded)
55             {
56                 cout << m << (m > 1 ? " channels " : " channel "<< "needed." << endl;
57                 break;
58             }
59         }
60     }
61     
62     return 0;
63 }
64 

posted @ 2008-05-05 08:58 superman 阅读(311) | 评论 (0)编辑 收藏

 1 /* Accepted 1085 C++ 00:00.00 872K */
 2 #include <queue>
 3 #include <string>
 4 #include <sstream>
 5 #include <iostream>
 6 
 7 using namespace std;
 8 
 9 int n, et, del;
10 bool map[10][10];
11 
12 bool visited[10];
13 void dfs(int p)
14 {
15     visited[p] = true;
16     for(int i = 0; i < n; i++)
17         if(i != del && map[p][i] && visited[i] == false)
18             dfs(i);
19 }
20 
21 void spfa(int s, int d[])
22 {
23     for(int i = 0; i < n; i++)
24         d[i] = INT_MAX;
25     queue <int> q;
26     q.push(s);
27     d[s] = 0;
28     while(q.empty() == false)
29     {
30         int u = q.front(); q.pop();
31         for(int v = 0; v < n; v++)
32             if(map[v][u] && d[u] + 1 < d[v])
33             {
34                 d[v] = d[u] + 1;
35                 q.push(v);
36             }
37     }
38 }
39 
40 int main()
41 {
42     int N;
43     cin >> N;
44     
45     while(N--)
46     {
47         memset(map, 0sizeof(map));
48         
49         cin >> n >> et;
50         
51         int s, t;
52         string str;
53         getline(cin, str);
54         
55         while(true)
56         {
57             if(getline(cin, str) == false || str == ""break;
58             stringstream in(str);
59             in >> s >> t; map[s][t] = true;
60         }
61         
62         int d[10];
63         spfa(et, d);
64         
65         bool x[10= { false };
66         while(true)
67         {
68             int min = INT_MAX;
69             for(int i = 0; i < n; i++)
70                 if(i != et && x[i] == false)
71                     if(d[i] < min)
72                     {
73                         min = d[i];
74                         del = i;
75                     }
76             if(min == INT_MAX)
77             {
78                 cout << "Put guards in room " << 0 << '.' << endl; break;
79             }
80             memset(visited, falsesizeof(visited));
81             x[del] = true;
82             dfs(0);
83             
84             if(visited[et] == false)
85             {
86                 cout << "Put guards in room " << del << '.' << endl; break;
87             }
88         }
89         if(N)
90             cout << endl;
91     }
92     
93     return 0;
94 }
95 

posted @ 2008-05-04 22:29 superman 阅读(339) | 评论 (0)编辑 收藏

 1 /* Accepted 1221 C++ 00:00.00 840K */
 2 #include <iostream>
 3 
 4 using namespace std;
 5 
 6 int main()
 7 {
 8     int Test = 0;
 9     while(true)
10     {
11         unsigned map[21][21];
12         memset(map, 255sizeof(map));
13         
14         for(int s = 1; s < 20; s++)
15         {
16             int n, t;
17             if(cin >> n == false)
18                 return 0;
19             while(n--)
20             {
21                 cin >> t;
22                 map[s][t] = map[t][s] = 1
23             }
24         }
25         
26         for(int k = 1; k <= 20; k++)
27         for(int i = 1; i <= 20; i++)
28         for(int j = 1; j <= 20; j++)
29             if(map[i][k] != UINT_MAX && map[k][j] != UINT_MAX)
30                 map[i][j] <?= (map[i][k] + map[j][k]);
31         
32         int n, s, t; cin >> n;
33         
34         cout << "Test Set #" << ++Test << endl;
35         while(n--)
36         {
37             cin >> s >> t;
38             cout << s << " to " << t << "" << map[s][t] << endl;
39         }
40         cout << endl;
41     }
42     
43     return 0;
44 }
45 

posted @ 2008-05-03 22:59 superman 阅读(179) | 评论 (0)编辑 收藏

 1 /* Accepted 1709 C++ 00:00.02 848K */
 2 #include <iostream>
 3 
 4 using namespace std;
 5 
 6 int n, m;
 7 char map[100][100];
 8 
 9 void floodfill(int x, int y)
10 {
11     map[x][y] = '*';
12     for(int i = x - 1; i <= x + 1; i++if(i >= 0 && i < n)
13     for(int j = y - 1; j <= y + 1; j++if(j >= 0 && j < m)
14         if(map[i][j] == '@')
15             floodfill(i, j);
16 }
17 
18 int main()
19 {
20     while((cin >> n >> m) && n)
21     {
22         for(int i = 0; i < n; i++)
23             for(int j = 0; j < m; j++)
24                 cin >> map[i][j];
25         
26         int cnt = 0;
27         for(int i = 0; i < n; i++)
28             for(int j = 0; j < m; j++)
29                 if(map[i][j] == '@')
30                 {
31                     cnt++;
32                     floodfill(i, j);
33                 }
34         cout << cnt << endl;
35     }
36     
37     return 0;
38 }
39 

posted @ 2008-05-03 21:22 superman 阅读(167) | 评论 (0)编辑 收藏

仅列出标题
共19页: First 7 8 9 10 11 12 13 14 15 Last