zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    类型转换
    new Overload函数输出
    快捷键加入属性代码段
    xp 下 安装Ubuntu 11.04 双系统
    native2ascii 用法解析
    apusic jconsole jmx connecitons url
    oracle 分页
    几条最基本的 sqlplus命令
    windows下plsql 设置 里面timestamp显示的格式
    oracle 时间差 做查询条件
  • 原文地址:https://www.cnblogs.com/shuiyonglewodezzzzz/p/10253190.html
Copyright © 2011-2022 走看看