Walking through the forest
Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 1607 accepted submission (s): 1090
Problem descriptiongardon and John enjoy walking in the forest outside the house every night. There are N open spaces in the forest, and there is a path connecting any two open spaces. Each time they depart from any blank space, they return to the original space after all the open space.
Because they like fresh trips, they do not want to go through any path twice. How many such fresh trips can they guarantee at most?
For example (figure), when n = 5, they can only keep this fresh trip twice.
The input contains multiple groups of data, each of which occupies one row and is a number n. (0 <n <= 1000000000)
The file ends at 0. Output for n of each input, the output can ensure a maximum of times of fresh travel. Sample input50 sample output2 was very difficult to look at the beginning of this question. It must involve some algorithms. After half a day, I did not come up with an algorithm that could solve this question... So I put this question there .. = When you eat, the sky shines. For the starting point, set the number of edges around it to n. If two edges are consumed for each round trip, you can go n/2 times in total, that is, n/2 fresh trips... When I think of this idea, I instantly feel a little Petrochemical... Orz code:
1 #include <stdio.h> 2 #include <algorithm> 3 #include <string.h> 4 #include <iostream> 5 #include <vector> 6 #include <map> 7 #include <queue> 8 #include <set> 9 #include <vector>10 #include <string>11 #include <sstream>12 using namespace std;13 14 main()15 {16 int n;17 while(scanf("%d",&n)==1&&n)18 {19 printf("%d\n",(n-1)>>1);20 }21 }