D. Little C Loves 3 II

传送门

[http://codeforces.com/contest/1047/problem/D]

题意

给你n*m得棋盘,让你找两点之间距离为3的点的个数,不能重复使用,距离定义,两坐标差绝对值之和

分析

自己动手找发现规律,16,24,25,34都可以用完所有格子,超过他们范围的都可由他们拼成,这时只需要对特殊的几种情况做特殊处理即可
尤其注意27的情况和nm为奇数的情况,有一个没有配对,所以减一。一定自己找规律,动手。

代码

#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int a[6]={0,0,0,0,2,4};
int main(){
    ll n,m,i;
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    while(cin>>n>>m){
        ll ans=0;
        if(n>m) swap(n,m);
        if(n==1) ans+=m/6*6,m%=6,ans+=a[m];
        else if(n==2) ans=m==2?0:m==3?4:m==7?12:m<<1;
        else ans=n*m/2*2;
        cout<<ans<<endl;
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/mch5201314/p/9721571.html