Codeforces Round #102 (Div. 2)——D. Help General

这题乍一看,没有什么思路。不过画了下图,就大概猜到了。

当输入为1行或1列时,那么最大值肯定为max(n,m).

当输入为2行或2列时,那么最大值也可分析的出来:

max(n,m)/4)*4+2(max(n,m)%4 == 1),max(n,m)/4)*4(max(n,m)%4 == 0),max(n,m)/4)*4+4(其他)这三种情况.

当输入为其他时,分析可知如果n*m%2 == 0,则为n*m/2.

反之则为n*m/2+1.

View Code
 1 #include<iostream>
2 #include<cstdio>
3 using namespace std;
4
5 int main()
6 {
7 int m,n;
8
9 scanf("%d%d",&n,&m);
10 if (n == 1 || m == 1) {
11 printf("%d\n",max(m,n));
12 } else {
13 if (n == 2 || m == 2) {
14 if (max(n,m)%4 == 1) {
15 printf("%d\n",(max(n,m)/4)*4+2);
16 } else {
17 if (max(n,m)%4 == 0) {
18 printf("%d\n",(max(n,m)/4)*4);
19 } else {
20 printf("%d\n",(max(n,m)/4)*4+4);
21 }
22 }
23 } else {
24 if ((n*m)%2 == 0) {
25 printf("%d\n",n*m/2);
26 } else {
27 printf("%d\n",n*m/2+1);
28 }
29 }
30 }
31
32 return 0;
33 }



posted on 2012-01-14 15:32  Dev-T  阅读(299)  评论(0编辑  收藏  举报