首页 > 代码库 > CodeForces 645B Mischievous Mess Makers

CodeForces 645B Mischievous Mess Makers

简单题。

第一次交换$1$和$n$,第二次交换$2$和$n-1$,第三次交换$3$和$n-2$.....计算一下就可以了。

#pragma comment(linker, "/STACK:1024000000,1024000000")#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<vector>#include<map>#include<set>#include<queue>#include<stack>#include<iostream>using namespace std;typedef long long LL;const double pi=acos(-1.0),eps=1e-6;void File(){    freopen("D:\\in.txt","r",stdin);    freopen("D:\\out.txt","w",stdout);}template <class T>inline void read(T &x){    char c=getchar(); x=0;    while(!isdigit(c)) c=getchar();    while(isdigit(c)) {x=x*10+c-0; c=getchar();}}int n,k;int main(){    scanf("%d%d",&n,&k);    if(k>n/2) k=n/2;    LL ans=0; int num=n;    for(int i=1;i<=k;i++)    {        ans=ans+num-1+num-2;        num=num-2;    }    printf("%lld\n",ans);    return 0;}

 

CodeForces 645B Mischievous Mess Makers