Hlg2157 [query Rules]

Source: Internet
Author: User
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]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.