美文网首页
2020-09-09 跳跳!

2020-09-09 跳跳!

作者: JalorOo | 来源:发表于2020-09-09 21:51 被阅读0次

https://www.luogu.com.cn/problem/P4995

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <sstream>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;

//template<typename DataType>
//DataType qmi(DataType m, int k)
//{
//    DataType res = 1, t = m;
//    while (k)
//    {
//        if (k&1) res = res * t;
//        t = t * t;
//        k >>= 1;
//    }
//    return res;
//}


int qmi(int m, int k)
{
    int res = 1, t = m;
    while (k)
    {
        if (k&1) res = res * t;
        t = t * t;
        k >>= 1;
    }
    return res;
}

int read(){
    int x = 0,f = 1;
    char c = getchar();
    while (c<'0'||c>'9') {
        if (c=='-') {
            f = -1;
        }
        c = getchar();
    }
    while (c>='0'&&c<='9') {
        x = x*10+c-'0';
        c = getchar();
    }
    return x*f;
}

#define fi(a,b) for(int i = a; i <= b; i++)
#define fj(a,b) for(int j = a; j >= b; j--)

struct priceAndCnt{
    int price,cnt;
};

void quickSort(priceAndCnt *a,int left,int right){
    int i,j;
    
    priceAndCnt temp,t;
    
    temp = a[(left+right)/2];//基准值
    
    i = left;
    j = right;
    
    while(i<=j){
        while (a[j].price > temp.price) {
            j--;
        }
        
        while (a[i].price < temp.price) {
            i++;
        }
        
        if (i<=j) {
            t = a[i];
            a[i] = a[j];
            a[j] = t;
            //继续下一步
            i++;
            j--;
        }
    }
    
    if(left<j)quickSort(a,left, j);//继续分治
    if(i<right)quickSort(a,i, right);//继续分治
}

int n;
long long ans = 0;
priceAndCnt arr[305];
int main(){
    //输入部分
    n = read();
    fi(1, n){
        arr[i].price = read();
    }
    
    //排序,然后一一匹配
    quickSort(arr, 1, n);
    
//    fi(1, n){
//        cout<<arr[i].price<<endl;
//    }
    
    int i = 1,j = n;
    ans = arr[j].price * arr[j].price;
    
    bool f = true;
    while(i < j){
        int a = (arr[j].price - arr[i].price);
        if( f ){
            ans += a * a;
            j --;
            f = false;
        } else {
            ans += a * a;
            i ++;
            f = true;
        }
    }
    cout<<ans;
}
/*
2
2 1
============
5
*/

相关文章

  • 2020-09-09 跳跳!

    https://www.luogu.com.cn/problem/P4995

  • 跳跳跳跳跳

    肥头大耳的中年男人,一向入不了颜控的发眼,怎么也不会是yy的对象;奇葩说可能让很多颜控改观了,矮大紧、马东东,连臭...

  • 跳跳跳

    今年的冬天似乎来得早了点 ,太阳早早收起明媚的笑脸,只留几缕安静阳光挂在窗角,可教室内的我们此时却是无比的亢奋...

  • 跳跳跳

    今天的体智能课上依旧是欢乐多多,小朋友对新鲜的事物,总是很感兴趣!这不我们熙宝小朋友,也很愉快的参与进来了。...

  • 兼容RSQL 查询DateTime 带空格无法解析问题

    问题 再使用RSQL的时候由于日期带上了空格.rsql=createTime==2020-09-09 10:08:...

  • 【读书会】第三期分享

    周岳 2020-09-09 快乐的读书会,进行了两期,非常期...

  • 青蛙🐸跳跳跳

    一只青蛙跳,嘣 两只青蛙跳,嘣嘣 三只青蛙跳,嘣嘣嘣 …… 各小组依次起立,并齐声念出来… 错误的,惩罚…

  • 左眼皮跳跳跳跳

    “左眼皮跳跳,好事要来到,不是要升官,就是快完发财了”。可我这眼皮是跳哪个意思嘛!大早上出门就开始跳,难道是睡...

  • 为k8s搭建harbor镜像仓库

    2020-09-09 为k8s搭建harbor镜像仓库 准备: 操作系统:Centos7.6k8s-harbor(...

  • 僵尸跳跳跳1

    2018年5月12日晚,在某个广场跳舞的人群后面,一个身影正随着音乐扭动着自己的身体:扭腰,提跨,左手伸,右手缩…...

网友评论

      本文标题:2020-09-09 跳跳!

      本文链接:https://www.haomeiwen.com/subject/vybyektx.html