2017 Multi-University Training Contest 5 hdu 6090

HDU 6090

思路:

AC代码:

#include "iostream"
#include "string.h"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#include "set"
#include "map"
#include "algorithm"
#include "stdio.h"
#include "math.h"
#pragma comment(linker, "/STACK:102400000,102400000")
#define ll long long
#define endl ("\n")
#define bug(x) cout<<x<<" "<<"UUUUU"<<endl;
#define mem(a,x) memset(a,x,sizeof(a))
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define ft (frist)
#define sd (second)
#define lrt (rt<<1)
#define rrt (rt<<1|1)
using namespace std;
const long long INF = 1e18+1LL;
const int inf = 1e9+1e8;
const int N=1e5+100;
const ll mod=1e9+7;

ll n,m,ans;
int main(){
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    int T;
    cin>>T;
    while(T--){
        cin>>n>>m;
        if(m<=n-1){
            ll c=n-m-1;
            ans=2*m+2*(m-1)*m+2*(m+1)*c*n+c*(c-1)*n;
        }
        else{
            m-=n-1;
            ans=2*(n-1)+2*(n-1)*(n-2);
            ans-=2*m;
        }
        if(ans<n*(n-1)) ans=n*(n-1);
        cout<<ans<<endl;
    }
    return 0;
}

 

posted on 2017-08-23 23:35  lazzzy  阅读(104)  评论(0编辑  收藏  举报

导航