锘??xml version="1.0" encoding="utf-8" standalone="yes"?>Code
1#include <iostream>
2#include <iomanip>
3using namespace std;
4
5const float PI = 3.1415927;
6const int FEET_MILE = 5280;
7const int INCH_FOOT = 12;
8const int MINUTES_HOUR = 60;
9const int SECONDS_MINUTE = 60;
10const float METERS_FURLONG = 201.168f;
11
12int _tmain(int argc, _TCHAR* argv[])
13{
14 float diameter, time;
15 int revolutions;
16
17 int index = 1;
18
19 while(cin >> diameter >> revolutions >> time && revolutions != 0)
20
{
21 float mile = 2 * PI * diameter / 2 * revolutions / INCH_FOOT / FEET_MILE;
22
23 float MPH = mile / (time / SECONDS_MINUTE / MINUTES_HOUR);
24
25 cout << "Trip #" << index << ": " << fixed << setprecision(2) << mile << " " << MPH << endl;
26 ++index;
27 }
28
29 return 0;
30}
]]>
Code
1#include <iostream>
2using namespace std;
3
4const int N = 28;
5const int UNLINK = 0x7fffffff;
6int g[N][N];
7int weight[N];
8bool visited[N];
9
10int _tmain(int argc, _TCHAR* argv[])
11{
12 int vertex, t_vertex;
13 while(cin >> t_vertex && t_vertex != 0)
14
{
15 vertex = t_vertex;
16 memset(visited, false, sizeof(visited));
17
18 for(int i = 0; i < vertex; ++i)
19
{
20 weight[i] = UNLINK;
21 for(int j = 0; j < vertex; ++j)
22
{
23 g[i][j] = UNLINK;
24 }
25 }
26
27 char v;
28 int num, t_num;
29 while(--t_vertex)
30
{
31 cin >> v >> t_num;
32 num = t_num;
33
34 char vl;
35 int edge;
36 while(t_num--)
37
{
38 cin >> vl >> edge;
39 g[(int)(v - 'A')][(int)(vl - 'A')] = edge;
40 g[(int)(vl - 'A')][(int)(v - 'A')] = edge;
41 }
42 }
43
44 for(int i = 0; i < vertex; ++i)
45
{
46 weight[i] = g[0][i];
47 }
48 visited[0] = true;
49 int min(UNLINK), nearest(-1), total_weight(0);
50
51 for(int i = 0; i < vertex; ++i)
52
{
53 min = UNLINK;
54 nearest = -1;
55 for(int j = 0; j < vertex; ++j)
56
{
57 if(min > weight[j] && !visited[j])
58
{
59 min = weight[j];
60 nearest = j;
61 }
62 }
63 visited[nearest] = true;
64 total_weight += weight[nearest];
65
66 for(int j = 0; j < vertex; ++j)
67
{
68 if(g[nearest][j] < weight[j])
69
{
70 weight[j] = g[nearest][j];
71 }
72 }
73 }
74
75 cout << total_weight << endl;
76 }
77 return 0;
78}
79
80
]]>Code
1#include <iostream>
2using namespace std;
3
4int _tmain(int argc, _TCHAR* argv[])
5{
6 int cases;
7 cin >> cases;
8
9 while(cases--)
10
{
11 int n;
12 cin >> n;
13
14 int * cells = new int[n + 1];
15 for(int i = 0; i <= n; ++i)
16
{
17 cells[i] = 0;
18 }
19
20 for(int i = 2; i <= n; ++i)
21
{
22 if(i > n / 2)
23 break;
24 for(int j = i; j <= n; j += i)
25
{
26 ++cells[j];
27 }
28 }
29
30 int result = 0;
31
32 for(int i = 1; i <= n / 2; ++i)
33
{
34 if((cells[i] & 1) == 0)
35 ++result;
36 }
37
38 for(int i = n / 2 + 1; i <= n; ++i)
39
{
40 if((cells[i] & 1) == 1)
41 ++result;
42 }
43 cout << result << endl;
44 delete cells;
45 }
46 return 0;
47}
48
49
]]>
1.絎竴閲岯FS鏍規嵁綆卞瓙鍙Щ鍔ㄧ殑浣嶇疆榪涜BFS.
2.絎簩閲嶅皢綆卞瓙鐩墠鎵鍦ㄧ殑浣嶇疆璁句負涓嶅彲杈?鏍規嵁綆卞瓙鎵鍦ㄧ殑浣嶇疆寰楀嚭浜烘墍搴旇鍦ㄧ殑浣嶇疆,鏍規嵁姝や綅緗浜鴻繘琛屼簡BFS.
鍗沖彲.
]]>
1.絎竴閲岯FS鏍規嵁綆卞瓙鍙Щ鍔ㄧ殑浣嶇疆榪涜BFS.
2.絎簩閲嶅皢綆卞瓙鐩墠鎵鍦ㄧ殑浣嶇疆璁句負涓嶅彲杈?鏍規嵁綆卞瓙鎵鍦ㄧ殑浣嶇疆寰楀嚭浜烘墍搴旇鍦ㄧ殑浣嶇疆,鏍規嵁姝や綅緗浜鴻繘琛屼簡BFS.
鍗沖彲.
]]>Code
1#include <iostream>
2#include <string>
3using namespace std;
4
5int _tmain(int argc, _TCHAR* argv[])
6{
7 int t;
8 cin >> t;
9 for(int g = 0; g < t; ++g)
10
{
11 if(g != 0)
12 cout << endl;
13
14 int n;
15 cin >> n;
16 getchar();
17
18 string res, r_res;
19
20 for(int i = 0; i < n; ++i)
21
{
22 getline(cin, res);
23 int length = res.length();
24 int last_space = -1;
25
26 for(int i = 0; i <= length; ++i)
27
{
28 if(i == length || res.at(i) == ' ')
29
{
30 for(int j = i - 1; j > last_space; --j)
31
{
32 cout << res.at(j);
33 }
34 if(i != length)
35 cout << " ";
36 last_space = i;
37 }
38 }
39 cout << endl;
40 }
41 }
42 return 0;
43}
44
45
]]>Code
1#include <iostream>
2#include <iomanip>
3using namespace std;
4
5const int N = 9;
6
7int factorial(int n)
8{
9 if(n == 0)
10 return 1;
11 return n * factorial(n - 1);
12}
13
14int _tmain(int argc, _TCHAR* argv[])
15{
16 cout << "n e" << endl;
17 cout << "- -----------" << endl;
18
19 double result = 0.0f, temp;
20
21 for(int i = 0; i <= N; ++i)
22
{
23 result = 0.0f;
24
25 for(int j = i; j > -1; --j)
26
{
27 result += 1.0 / factorial(j);
28 }
29
30 if(i > 2)
31
{
32 printf("%d %.9f\n", i, result);
33 }
34 else
35
{
36 cout << i << " " << result << endl;
37 }
38 }
39 return 0;
40}
]]>