锘??xml version="1.0" encoding="utf-8" standalone="yes"?>![]()
Code
1
#include <iostream>
2
#include <iomanip>
3
using namespace std;
4
5
const float PI = 3.1415927;
6
const int FEET_MILE = 5280;
7
const int INCH_FOOT = 12;
8
const int MINUTES_HOUR = 60;
9
const int SECONDS_MINUTE = 60;
10
const float METERS_FURLONG = 201.168f;
11
12
int _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>
2
using namespace std;
3
4
const int N = 28;
5
const int UNLINK = 0x7fffffff;
6
int g[N][N];
7
int weight[N];
8
bool visited[N];
9
10
int _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>
2
using namespace std;
3
4
int _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>
3
using namespace std;
4
5
int _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>
3
using namespace std;
4
5
const int N = 9;
6
7
int factorial(int n)
8

{
9
if(n == 0)
10
return 1;
11
return n * factorial(n - 1);
12
}
13
14
int _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
}
]]>
#include <iostream>
#include <iomanip>
using namespace std;
const int N = 9;
int factorial(int n)

{
if(n == 0)
return 1;
return n * factorial(n - 1);
}
int _tmain(int argc, _TCHAR* argv[])

{
cout << "n e" << endl;
cout << "- -----------" << endl;
double result = 0.0f, temp;
for(int i = 0; i <= N; ++i)
{
result = 0.0f;
for(int j = i; j > -1; --j)
{
result += 1.0 / factorial(j);
}
if(i > 2)
{
printf("%d %.9f\n", i, result);
}
else
{
cout << i << " " << result << endl;
}
}
return 0;
}
#include "BigInteger.h"
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;
bool IsCyclic(string input, string result)

{
int length = input.length();
int flag[100] =
{0};
for(int i = 0; i < length; ++i)
{
for(int j = 0; j < length; ++j)
{
if(!flag[j] && input.at(i) == result.at(j))
{
flag[j] = 1;
break;
}
}
}
for(int i = 0; i < length; ++i)
{
if(!flag[i])
return false;
}
return true;
}

int _tmain(int argc, _TCHAR* argv[])

{
string input;
while(cin >> input)
{
int length = input.length();
BigInteger integer(input);
BigInteger result(1);
bool isCyclic = true;
for(int i = 2; i < length + 1; ++i)
{
result = integer * BigInteger(i);
if(!IsCyclic(input, result.GetString()))
{
isCyclic = false;
break;
}
}
if(isCyclic)
cout << input << " is cyclic" << endl;
else
cout << input << " is not cyclic" << endl;
}
return 0;
}
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])

{
int n;
bool reInput = false;
while(cin >> n && n != 0)
{
if(reInput)
cout << endl;
reInput = true;
int *A = new int[n];
int *B = new int[n];
for(int i = 0; i < n; ++i)
{
cin >> A[i];
}
for(int i = 0; i < n; ++i)
{
cin >> B[i];
}
int score_A = 0;
int score_B = 0;
for(int i = 0; i < n; ++i)
{
if(A[i] > B[i])
{
if(A[i] - B[i] == 1)
{
if(A[i] == 2)
{
score_B += 6;
}
else
{
score_B += A[i];
score_B += B[i];
}
}
else
{
score_A += A[i];
}
}
else if(A[i] < B[i])
{
if(B[i] - A[i] == 1)
{
if(B[i] == 2)
{
score_A += 6;
}
else
{
score_A += A[i];
score_A += B[i];
}
}
else
{
score_B += B[i];
}
}
}
cout << "A has " << score_A << " points. B has " << score_B << " points." << endl;
delete A, B;
}
return 0;
}
