思路:
一道简单的思维题,自己推吧。。。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
int n, m;
int stepn, stepm;
int ans;
int main(){
freopen ("cyl.in", "r", stdin);
freopen ("cyl.out", "w", stdout);
scanf("%d%d", &n, &m);
if( (n - 1) % 3 == 0 ){
stepn = (n - 1) / 3 * 2;
stepm = (m - 1) % 3 + (m - 1) / 3 * 2;
ans = stepn + stepm;
}
else if(n < 4){
if( (m - 1) % 3 == 0 ){
stepn = n - 1;
stepm = (m - 1) / 3 * 2;
ans = stepn + stepm;
}
else if(n == 3 && m == 3) ans = 8;
else if(n == 3){
if( (m - 1) % 3 == 0 ) ans = (m - 1) / 3 * 2 + 2;
else ans = (m - 1) / 3 * 2 + (m - 1) % 3 + 4;
}
else ans = -1;
}
else{
stepn = (n - 1) % 3 + (n - 1) / 3 * 2;
stepm = (m - 1) % 3 + (m - 1) / 3 * 2;
ans = stepn + stepm;
}
printf("%d", ans);
return 0;
}