| Eat beans |
| Time Limit: 1000 MS |
Memory limit: 32768 K |
| Total submit: 59 (40 Users) |
Total accepted: 34 (34 Users) |
Rating: |
Special Judge: No |
|
| Description |
One day, woods and his grilfriend (GF) came to a fairy tale Kingdom town with many peas (for example, every circle in it is a bean), each of which goes east, south, roads in the West, North, southeast, northeast, northwest, and Southwest China directions. The distance between a straight line road and a diagonal line road is 1 meters, and the distance between the two lines is 2 meters. GF becomes hungry as soon as it sees it ...... Can you calculate the shortest path to get back to the starting point after eating all the beans once? For a 2x3 graph, the shortest distance (as shown in the Red Line) is 6 meters. |
| Input |
Multiple groups of test data. One row of test data in each group, including two integers n, m (1 <m <50 and 1 <n <50.), indicates that the graph size is n rows of M columns. |
| Output |
Output a row of data in each group, and only eat all the beans once. The shortest path is returned to the start point. (Precise to two decimal places ). |
| Sample Input |
2 2 2 3 |
| Sample output |
4.00 6.00 |
| Hint |
|
| Source |
| 2014 summer training and exercises (March August 13) |
Analysis: Finding rules
Code:
1 #include <iostream> 2 #include <cstdio> 3 #include <cmath> 4 using namespace std; 5 6 int main() { 7 int a, b; 8 while(EOF != scanf("%d %d",&a, &b) ) { 9 double ans = a * b + 1e-9;10 if(a % 2 == 1 && b % 2 == 1) ans += sqrt(2) - 1.0;11 printf("%.2lf\n",ans);12 }13 return 0;14 }View code
Hlg2157 [query Rules]