zoukankan      html  css  js  c++  java
  • 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
    ",ans);
        return 0;
    }
  • 相关阅读:
    csu 1965
    csu 1947 三分
    Codeforces 336C 0-1背包
    POJ 1743 后缀数组
    POJ 2774 后缀数组
    UVA 12333 大数,字典树
    POJ 2942 圆桌骑士
    POJ 1503 大整数
    POJ 2342 树的最大独立集
    POJ 3088 斯特林
  • 原文地址:https://www.cnblogs.com/zufezzt/p/5916011.html
Copyright © 2011-2022 走看看