zoukankan      html  css  js  c++  java
  • Codeforces Round #642 (Div. 3) C. Board Moves

    You are given a board of size n×nn×n , where nn is odd (not divisible by 22 ). Initially, each cell of the board contains one figure.

    In one move, you can select exactly one figure presented in some cell and move it to one of the cells sharing a side or a corner with the current cell, i.e. from the cell (i,j)(i,j) you can move the figure to cells:

    • (i1,j1)(i−1,j−1) ;
    • (i1,j)(i−1,j) ;
    • (i1,j+1)(i−1,j+1) ;
    • (i,j1)(i,j−1) ;
    • (i,j+1)(i,j+1) ;
    • (i+1,j1)(i+1,j−1) ;
    • (i+1,j)(i+1,j) ;
    • (i+1,j+1)(i+1,j+1) ;

    Of course, you can not move figures to cells out of the board. It is allowed that after a move there will be several figures in one cell.

    Your task is to find the minimum number of moves needed to get all the figures into one cell (i.e. n21n2−1 cells should contain 00 figures and one cell should contain n2n2 figures).

    You have to answer tt independent test cases.

    Input

    The first line of the input contains one integer tt (1t2001≤t≤200 ) — the number of test cases. Then tt test cases follow.

    The only line of the test case contains one integer nn (1n<51051≤n<5⋅105 ) — the size of the board. It is guaranteed that nn is odd (not divisible by 22 ).

    It is guaranteed that the sum of nn over all test cases does not exceed 51055⋅105 (n5105∑n≤5⋅105 ).

    Output

    For each test case print the answer — the minimum number of moves needed to get all the figures into one cell.

    Example
    Input
    Copy
    3
    1
    5
    499993
    
    Output
    Copy
    0
    40
    41664916690999888

    找规律。可以看到正方形的每一个“圈”到中心的最小距离都是一样的(数一下就能发现规律)。然后把整个正方形分成八个小三角形+八条线或者直接按照圈来统计都行。
    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        int t;
        cin>>t;
        while(t--)
        {
            long long n,ans=0;
            long long i;
            cin>>n;
            for(i=2;i<=n/2+1;i++)
            {
                ans+=(i-2)*(i-1);
            } 
            ans*=8;
            for(i=1;i<=n/2+1;i++)
            {
                ans+=(i-1)*8;
            }      
            cout<<ans<<endl;                                                                              
        }
        return 0;
    }
  • 相关阅读:
    Docker,用任何工具链和任何语言来构建任何应用
    从Docker在Linux和Windows下的区别简单理解Docker的层次结构
    Docker在Windows下的安装以及Hello World
    (译)学习如何构建自动化、跨浏览器的JavaScript单元测试
    由Python的super()函数想到的
    PS:蓝天白云的制作
    PS:缝线颜色随着鞋帮颜色的改变发生改变.files
    Windows8 64位运行Silverlight程序不能访问WCF的解决方案
    背景图片之background的用法
    12306订票助手更新
  • 原文地址:https://www.cnblogs.com/lipoicyclic/p/12894731.html
Copyright © 2011-2022 走看看