zoukankan      html  css  js  c++  java
  • Codeforces Round #511 (Div. 1) T2 Little C Loves 3 II

    题目

    Little C loves number «3» very much. He loves all things about it.
    Now he is playing a game on a chessboard of size n×mn imes m. The cell in the xx-th row and in the yy-th column is called (x,y)(x,y). Initially, The chessboard is empty. Each time, he places two chessmen on two different empty cells, the Manhattan distance between which is exactly 33. The Manhattan distance between two cells (xi,yi)(x_i,y_i) and (xj,yj)(x_j,y_j) is defined as xixj+yiyj|x_i-x_j|+|y_i-y_j|.
    He want to place as many chessmen as possible on the chessboard. Please help him find the maximum number of chessmen he can place.
    Input
    A single line contains two integers nn and mm (1n,m1091 leq n,m leq 10^9) — the number of rows and the number of columns of the chessboard.
    Output
    Print one integer — the maximum number of chessmen Little C can place.
    Examples
    inputCopy
    2 2
    outputCopy
    0
    inputCopy
    3 3
    outputCopy
    8
    Note
    In the first example, the Manhattan distance between any two cells is smaller than 33, so the answer is 00.
    In the second example, a possible solution is (1,1)(3,2)(1,1)(3,2), (1,2)(3,3)(1,2)(3,3),(2,1)(1,3)(2,1)(1,3), (3,1)(2,3)(3,1)(2,3).

    和史前巨佬ldx还有dzy神仙一起做的

    这道题…

    可以说是打表吧

    首先我们可以观察到,对于任意一个161*6或者242*4的格子,都是可以填满的,

    那也就说如果有一边长能被6或者4给整除,那就是可以填满的

    然后对于5*5以下的了,我们可以直接打表预处理出来(因为有一些特殊情况吧)

    然后。。

    就被2*7给hack了

    然后特判了一个2*7就过了

    #include <bits/stdc++.h>
    #define ll long long
    using namespace std;
    int tr[5][5]={ {0,0,0,2,4},
    			   {0,0,4,8,10},
    			   {0,4,8,12,14},
    			   {2,8,12,16,18},
    			   {4,10,14,18,24}};
    int main() {
    	int n,m;
    	cin>>n>>m;
    	if(n<m) swap(n,m);
    	ll ans=0;
    	if(m==1)ans+=n/6*6,n%=6,ans+=tr[0][n-1];
    	else if(n%4==0 || m%4==0)ans=(ll)n*m;
    	else if(n%6==0 || m%6==0)ans=(ll)n*m;
    	else if(n<=5 && m<=5)ans=tr[n-1][m-1];
    	else if(n==7 && m==2)ans=12;else ans=(ll)n*m/2*2;
    	cout<<ans<<'
    ';
    } 
    
    

    反正dzy神仙带我飞,什么都不怕

  • 相关阅读:
    字节跳动2020年九月笔试题-爬楼梯(不能连续爬两个两步)
    c/c++经典面试题-part1
    C++单例模式之一见钟情
    多线程同步的四种方式(史上最详细+用例)
    c++多态之动态绑定
    Redis从入门到入坑
    编写一个 C 函数,该函数在一个字符串中找到可能的最长的子字符串,且该字符串 是由同一字符组成的。
    面试之进制转换函数
    c++编程题之空调遥控器
    static 和 const关键字的作用
  • 原文地址:https://www.cnblogs.com/stargazer-cyk/p/10366501.html
Copyright © 2011-2022 走看看