• uva-10041-水题


    题意:有个人想找到个房子住,并且他经常去其他街道,输入n条街,给这个人选择一条街,使得他去其他街道的距离总和最小。

    排序,双重for

    #include <string>
    #include<iostream>
    #include<map>
    #include<memory.h>
    #include<vector>
    #include<algorithm>
    #include<queue>
    #include<vector>
    #include<stack>
    #include<math.h>
    #include<iomanip>
    #include<bitset>
    #include"math.h"
    namespace cc
    {
        using std::cout;
        using std::endl;
        using std::cin;
        using std::map;
        using std::vector;
        using std::string;
        using std::sort;
        using std::priority_queue;
        using std::greater;
        using std::vector;
        using std::swap;
        using std::stack;
        using std::bitset;
    
    
        constexpr int N = 501;
        int a[N];
        
        
        
        void solve()
        {
            int n,r;
            cin >> n;
            while (n--) 
            {
                cin >> r;
                for (int i = 0;i < r;i++)
                    cin >> a[i];
                sort(a,a+r);
                int curMin = 0x7fffffff;
                for (int i=0;i<r;i++) 
                {
                    int curTotal = 0;
                    for (int j=0;j<r;j++) 
                    {
                        if (i == j)
                            continue;
                        int t = abs(a[i]-a[j]);
                        curTotal += t;
                        if (curTotal >= curMin)
                            break;
                    }
                    if (curTotal < curMin)
                        curMin = curTotal;
                }
                cout << curMin << endl;
            }
            
    
    
        }
    
    };
    
    
    int main()
    {
    
    #ifndef ONLINE_JUDGE
        freopen("d://1.text", "r", stdin);
    #endif // !ONLINE_JUDGE
        cc::solve();
    
        return 0;
    }
  • 相关阅读:
    国庆清北 Day5 T3 holyshit
    清北国庆Day4 T2 r
    清北国庆Day4 T2 y
    国庆清北Day4 DP 题目
    国庆清北 DP
    国庆清北 搜索
    国庆清北 图论
    国庆清北 数据结构
    python爬虫学习:网页采集器、豆瓣电影爬取、百度翻译
    入门爬虫-requests模块
  • 原文地址:https://www.cnblogs.com/shuiyonglewodezzzzz/p/10253190.html
Copyright © 2020-2023  润新知