原题:https://codeforces.com/contest/1353/problem/A
题意:t组案例,n和m两个整数,将m分解成n个数,可为零,使得相邻两数差的绝对值之和最大并求最大值。
思路:n=1,输出0
n=2,输出m-0
n>2,数组可以分为:0 0 0…0 0 m 0 0 …0 0 0结果为2*m
故代码为:
#include <bits/stdc++.h>
using namespace std;
int t,n,m;
int main()
{
cin>>t;
while(t--){
cin>>n>>m;
if(n==1)
cout<<0<<endl;
else
if(n==2)
cout<<m<<endl;
else
cout<<2*m<<endl;
}
}