hdu 4312 Meeting point-2(4级)

本文深入探讨了游戏开发领域的关键技术,包括游戏引擎、编程语言、硬件优化等,并聚焦于AI音视频处理在游戏场景的应用,如语音识别、图像处理和AR特效,为游戏开发者提供前沿技术洞察。
部署运行你感兴趣的模型镜像

Meeting point-2

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 866    Accepted Submission(s): 472


Problem Description
It has been ten years since TJU-ACM established. And in this year all the retired TJU-ACMers want to get together to celebrate the tenth anniversary. Because the retired TJU-ACMers may live in different places around the world, it may be hard to find out where to celebrate this meeting in order to minimize the sum travel time of all the retired TJU-ACMers.

It's an opportunity to show yourself in front of your predecessors!

There is an infinite integer grid at which N retired TJU-ACMers have their houses on. They decide to unite at a common meeting place, which is someone's house. From any given cell, all 8 adjacent cells are reachable in 1 unit of time.

Eg: (x,y) can be reached from (x-1,y), (x+1,y), (x, y-1), (x, y+1), (x-1,y+1), (x-1,y-1), (x+1,y+1), (x+1,y-1).

Finding a common meeting place which minimizes the sum of the travel time of all the retired TJU-ACMers.
 

Input
The first line is an integer T represents there are T test cases. (0<T <=10)
For each test case, the first line is an integer n represents there are n retired TJU-ACMers. (0<n<=100000), the following n lines each contains two integers x, y coordinate of the i-th TJU-ACMer. (-10^9 <= x,y <= 10^9)
 

Output
For each test case, output the minimal sum of travel times.
 

Sample Input
  
4 6 -4 -1 -1 -2 2 -4 0 2 0 3 5 -2 6 0 0 2 0 -5 -2 2 -2 -1 2 4 0 5 -5 1 -1 3 3 1 3 -1 1 -1 10 -1 -1 -3 2 -4 4 5 2 5 -4 3 -1 4 3 -1 -2 3 4 -2 2
 

Sample Output
  
20 15 14 38
Hint
In the first case, the meeting point is (0,2); the second is (0,0), the third is (1,-1) and the last is (-1,-1)
 

Author
TJU
 

Source
 

Recommend
zhuyuanchen520

思路:

max{|x|,|y|}=1/2(|x+y|+|x-y|);

因此将x变成x+y,y->x-y;就可以算曼哈顿距离了。

x,y到某点的曼哈顿距离可以分开算,因此,分开枚举以某点为中心的值球最小就好了。

           预处理,kx[x]以某点 x为中心的所有x距离和,ky[]同理。kx[i]=kx[i-1]+(i-n+i)*(f[i].x-f[i-1].x);


另外还有一种很狗屎的办法,猜测+枚举,运气好的话,数据不是非常强就可以过。

就是将其按照 X,Y排序,答案在中间段取点,但应该枚举几个呢???这是个问题,所以有点狗屎


#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
const int mm=2e5+9;
class node
{
public:
    __int64 x,y;
    int id;
} f[mm];
bool cmpx(node a,node b)
{
    return a.x<b.x;
}
bool cmpy(node a,node b)
{
    return a.y<b.y;
}
__int64 kx[mm],ky[mm];
__int64 sum;
__int64 aabs(__int64 x)
{
    if(x<0)return -x;
    return x;
}
int main()
{
    int cas;__int64 n,xx,yy;
    while(~scanf("%d",&cas))
    {
        while(cas--)
        {
            scanf("%I64d",&n);
            for(int i=0; i<n; ++i)
                {
                scanf("%I64d%I64d",&xx,&yy);
                f[i].x=xx-yy;f[i].y=xx+yy;
                }
            sort(f,f+n,cmpx);
            kx[0]=0;
            for(int i=0; i<n; ++i)
            {
                kx[0]+=aabs(f[i].x-f[0].x);
                f[i].id=i;
            }
            for(__int64 i=1; i<n; ++i)
                kx[i]=kx[i-1]+(i-n+i)*(f[i].x-f[i-1].x);
            //for(int i=0;i<n;++i)
            //cout<<" "<<kx[i]<<" ";puts("");
            sort(f,f+n,cmpy);
            ky[0]=0;
            for(int i=0;i<n;++i)
            ky[0]+=aabs(f[i].y-f[0].y);
            for(__int64 i=1;i<n;++i)
               ky[i]=ky[i-1]+(i+i-n)*(f[i].y-f[i-1].y);
            //for(int i=0;i<n ;++i)
            //cout<<" "<<ky[i]<<" ";puts("");
            sum=6e18;
            for(int i=0;i<n;++i)
            { //cout<<f[i].id<<" "<<i<<" "<<kx[f[i].id]<<" "<<ky[i]<<" "<<ky[i]+kx[f[i].id]<<endl;
              if(sum>ky[i]+kx[f[i].id])sum=ky[i]+kx[f[i].id];
            }
           printf("%I64d\n",sum/2);
        }
    }
    return 0;
}

///250以下基本就错了,以上基本就超了。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <set>
#include <algorithm>

using namespace std;
const int maxn = 1000010;

pair<int,int> p[maxn];

int abs1(int a) {
    return a<0?-a:a;
}
int main()
{
    int T,n;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);
        for(int i=0;i<n;i++)
           scanf("%d %d",&p[i].first,&p[i].second);
        sort(p,p+n);
        int l = max(n/2-250,0);
        int r  = min(n/2+250,n);
        __int64 ans = 999999999999999LL;
        //cout << ans << endl;
        for(int i=l;i<r;i++)
        {
            __int64 tmp = 0;
            for(int j=0;j<n;j++)
               tmp += max(abs1(p[j].first-p[i].first),abs1(p[j].second-p[i].second));
            ans = min(ans,tmp);
        }
        printf("%I64d\n",ans);
    }
    return 0;
}
/*
3
10 88
0 1
0 5
1
0 2
0 0
1
1
1
*/



您可能感兴趣的与本文相关的镜像

GPT-SoVITS

GPT-SoVITS

AI应用

GPT-SoVITS 是一个开源的文本到语音(TTS)和语音转换模型,它结合了 GPT 的生成能力和 SoVITS 的语音转换技术。该项目以其强大的声音克隆能力而闻名,仅需少量语音样本(如5秒)即可实现高质量的即时语音合成,也可通过更长的音频(如1分钟)进行微调以获得更逼真的效果

MATLAB代码实现了一个基于多种智能优化算法优化RBF神经网络的回归预测模型,其核心是通过智能优化算法自动寻找最优的RBF扩展参数(spread),以提升预测精度。 1.主要功能 多算法优化RBF网络:使用多种智能优化算法优化RBF神经网络的核心参数spread。 回归预测:对输入特征进行回归预测,适用于连续值输出问题。 性能对比:对比不同优化算法在训练集和测试集上的预测性能,绘制适应度曲线、预测对比图、误差指标柱状图等。 2.算法步骤 数据准备:导入数据,随机打乱,划分训练集和测试集(默认7:3)。 数据归一化:使用mapminmax将输入和输出归一化到[0,1]区间。 标准RBF建模:使用固定spread=100建立基准RBF模型。 智能优化循环: 调用优化算法(从指定文件夹中读取算法文件)优化spread参数。 使用优化后的spread重新训练RBF网络。 评估预测结果,保存性能指标。 结果可视化: 绘制适应度曲线、训练集/测试集预测对比图。 绘制误差指标(MAE、RMSE、MAPE、MBE)柱状图。 十种智能优化算法分别是: GWO:灰狼算法 HBA:蜜獾算法 IAO:改进天鹰优化算法,改进①:Tent混沌映射种群初始化,改进②:自适应权重 MFO:飞蛾扑火算法 MPA:海洋捕食者算法 NGO:北方苍鹰算法 OOA:鱼鹰优化算法 RTH:红尾鹰算法 WOA:鲸鱼算法 ZOA:斑马算法
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值