HDU 4572 Bottles Arrangement 解题报告

题意:有N列数,且N为奇数,每列是1到M的排列。且相邻两列相邻的数的差值<=1。求行之和最大值的最小值。

方法:试了几个,YY的结论是若N=2*n+1,ans=2*M+2*(M-1)+...+(M-n)


//Memory: 308 KB		Time: 0 MS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#define MAXN 210
#define MP(x,y) make_pair((x),(y))
#define FI first
#define SE second
#define INF 10000007
using namespace std;

int n,m;
int main()
{
    //freopen("/home/moor/Code/input.txt","r",stdin);
    while (scanf("%d%d",&m,&n)!=-1)
    {
        int tmp=m;
        long long ans=0;
        while (n>1)
        {
            ans+=tmp+tmp;
            n-=2;
            tmp-=1;
        }
        printf("%I64d\n",ans+tmp);
    }
    return 0;
}


你可能感兴趣的:(HDU 4572 Bottles Arrangement 解题报告)