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 = ;
int a[N]; void solve()
{
int n,r;
cin >> n;
while (n--)
{
cin >> r;
for (int i = ;i < r;i++)
cin >> a[i];
sort(a,a+r);
int curMin = 0x7fffffff;
for (int i=;i<r;i++)
{
int curTotal = ;
for (int j=;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 ;
}
uva-10041-水题的更多相关文章
- UVa 1595 (水题) Symmetry
颓废的一个下午,一直在切水题,(ˉ▽ ̄-) 首先如果这些点是对称的话,那么它们的对称轴就是x = m,m是横坐标的平均值. 把这些点放到一个集合里,然后扫描每个点,计算出它关于x = m的对称点,看这 ...
- UVa 10391 (水题 STL) Compound Words
今天下午略感无聊啊,切点水题打发打发时间,=_=|| 把所有字符串插入到一个set中去,然后对于每个字符串S,枚举所有可能的拆分组合S = A + B,看看A和B是否都在set中,是的话说明S就是一个 ...
- UVa 10935 (水题) Throwing cards away I
直接用STL里的queue模拟即可. #include <cstdio> #include <queue> using namespace std; ; int discard ...
- UVa 1593 (水题 STL) Alignment of Code
话说STL的I/O流用的还真不多,就着这道题熟练一下. 用了两个新函数: cout << std::setw(width[j]); 这个是设置输出宽度的,但是默认是在右侧补充空格 所 ...
- UVa 400 (水题) Unix ls
题意: 有n个文件名,排序后按列优先左对齐输出.设最长的文件名的长度为M,则最后一列长度为M,其他列长度为M+2. 分析: 这道题很简单,但要把代码写的精炼,还是要好好考虑一下的.lrj的代码中有两个 ...
- UVa 11040 (水题) Add bricks in the wall
题意: 45块石头如图排列,每块石头上的数等于下面支撑它的两数之和,求其余未表示的数. 分析: 首先来计算最下面一行的数,A71 = A81 + A82 = A91 + 2A92 + A93,变形得到 ...
- Square Numbers UVA - 11461(水题)
#include <iostream> #include <cstdio> #include <sstream> #include <cstring> ...
- UVa 489 HangmanJudge --- 水题
UVa 489 题目大意:计算机给定一个单词让你猜,你猜一个字母,若单词中存在你猜测的字母,则会显示出来,否则算出错, 你最多只能出错7次(第6次错还能继续猜,第7次错就算你失败),另注意猜一个已经猜 ...
- UVa 1339 Ancient Cipher --- 水题
UVa 1339 题目大意:给定两个长度相同且不超过100个字符的字符串,判断能否把其中一个字符串重排后,然后对26个字母一一做一个映射,使得两个字符串相同 解题思路:字母可以重排,那么次序便不重要, ...
- UVa 1225 Digit Counting --- 水题
UVa 1225 题目大意:把前n(n<=10000)个整数顺次写在一起,12345678910111213...,数一数0-9各出现多少字 解题思路:用一个cnt数组记录0-9这10个数字出现 ...
随机推荐
- 2.5 定义FTP工具的各种方法
用class定义ftp工具的各种方法 import os,sys from ftplib import FTP from mimetypes import guess_type,add_type fr ...
- 一、JAVA变量类型:②局部变量
局部变量声明在方法.构造方法或者语句块中: public class Test{ public void pupAge(){ int age = 0; //定义age为方法pupAge中的局部变量,并 ...
- SharePoint Framework Extensions GA Release
博客地址:http://blog.csdn.net/FoxDave SharePoint Framework Extensions GA版本已经发布了,介于最近个人工作的变动调整,还没时间好好了解一下 ...
- GitHub入门与实践 读书笔记一:欢迎来到GitHubde世界
1.什么是GitHub GitHubshi为开发者提供Git仓库的托管服务.除此之外,还为开发者提供能帮助提高代码效率和品质的功能. GitHub和Git的区别? Git是源码仓库而GitHub是在网 ...
- VMware网络连接模式——桥接模式、NAT模式以及仅主机模式的介绍和区别
在使用VMware Workstation(以下简称:VMware)创建虚拟机的过程中,配置虚拟机的网络连接是非常重要的一环,当我们为虚拟机配置网络连接时,我们可以看到如下图所示的几种网络连接模式:桥 ...
- Echarts tooltip 坐标值修改
tooltip: { trigger: 'axis', position:function(p){ //其中p为当前鼠标的位置 console.log(p); ] + , p[] - ]; } },
- centos7共享文件夹到windows访问--samba
第一步:安装samba服务 yum install samba 第二步:启动samba服务 systemctl start smb 查看samba的状态 systemctl status smb 看到 ...
- FreeSWITCH部署与功能配置
一.FreeSWITCH服务部署 1.wget http://www.freeswitch.org.cn/Makefile && make install 2.cd freeswitc ...
- 自动化测试-14.selenium加载FireFox配置
前言 有小伙伴在用脚本启动浏览器时候发现原来下载的插件不见了,无法用firebug在打开的页面上继续定位页面元素,调试起来不方便 . 加载浏览器配置,需要用FirefoxProfile(profile ...
- webStrom访问只一个很简单的html文件的时候显示local host无法访问。。
直接从文件夹运行html没问题的,,,然后百度半天,,乱七八糟的答案, 1.谷歌商店安装 JB插件--插件地址 https://chrome.google.com/webstore/detail/je ...