296. Best Meeting Point

本文探讨了一个二维网格中寻找一个点,使得该点到所有标记点的曼哈顿距离之和最小的问题。通过将问题简化为一维并找到中间点来解决,提供了一个高效的算法实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Problem

A group of two or more people wants to meet and minimize the total travel distance. You are given a 2D grid of values 0 or 1, where each 1 marks the home of someone in the group. The distance is calculated using Manhattan Distance, where distance(p1, p2) = |p2.x - p1.x| + |p2.y - p1.y|.

For example, given three people living at (0,0)(0,4), and (2,2):

1 - 0 - 0 - 0 - 1
|   |   |   |   |
0 - 0 - 0 - 0 - 0
|   |   |   |   |
0 - 0 - 1 - 0 - 0

The point (0,2) is an ideal meeting point, as the total travel distance of 2+2+2=6 is minimal. So return 6


Solution

如果是一维的,那就是以最中间的那个点为见面地点( buggy : 不是坐标的平均值
class Solution {
public:
    int minTotalDistance(vector<vector<int>>& grid) {
        vector<int> iArr, jArr;
        int iSum = 0, jSum = 0;
        for( int i = 0; i < grid.size(); i++){
            for( int j = 0; j < grid[0].size(); j++){
                if(grid[i][j] == 1){
                    iArr.push_back(i);
                    jArr.push_back(j);
                    iSum += i;
                    jSum += j;
                }
            }
        }
        
        const int N = iArr.size();
        sort( jArr.begin(), jArr.end());
        int iMid = iArr[N/2], jMid = jArr[N/2], rst = 0;
        
        for( int i = 0; i < N; i++){
            rst += abs( iArr[i] - iMid) + abs( jArr[i] - jMid);
        }
        return rst;
    }
};


有如下邮件内容,请问如何用python通过AI中的自然语言处理NLP的方法,总结出ADO任务的标题和简单的任务描述?From: Summer Sent: Friday, April 25, 2025 5:10 PM To: Pavan Cc: Candace; Xiaoyi Subject: RE: DQMA Discussion for GFOX - meeting minutes 20241209 Dear Pavan, OK got that, how about point3 please? And if needed, please kindly provide me an ADO sample. Thank you! Best Regards, Summer HE -------------------------------------------------------------------------------------------------------- From: Pavan Sent: Friday, April 25, 2025 5:10 PM To: Summer Cc: Candace; Xiaoyi Subject: RE: DQMA Discussion for GFOX - meeting minutes 20241209 INTERNAL Hi Summer, Below is the reporting lake WI. Our target is to deploy the changes in one of the releases in August (either Aug 2nd or Aug 23rd). https://dev.azure.com/sc-ado/FMQPR/_workitems/edit/8540473 Regards, Pavan -------------------------------------------------------------------------------------------------------- From: Summer Sent: Friday, April 25, 2025 5:10 PM To: Pavan Cc: Candace; Xiaoyi Subject: RE: DQMA Discussion for GFOX - meeting minutes 20241209 INTERNAL Dear Pavan, Here are the points we discussed this noon time based on your below email, together with Sowmya and Xiaoyi. 1. Although only EMIR_Controls_Positions_Full report is impacted by GFOX, for consistency, your API call date for COB Fri file will be changed from Sat to Mon morning for all 3 Controls reports. Only OLA date is changed, while timing remains the same, i.e.: These 3 reports are generated around 3:00am GMT on Sat for COB Fri, and after release: 3:00am GMT on Mon for COB Fri. 2. For the rest 2 EMIR_Controls report, the records will be the same for COB Fri, even it is generated on Mon instead of Sat. 3. PaCman and RL/DQMA will make the release together during the same release window. 4. If GFOX trades booked in prod before release and get captured in EMIR_Controls_Positions_Full report, negative impact is: break will happen in recon. While COB Mon-Thu shouldn’t be impacted. Pending Actions: 1. Once GFOX trades happen in production, Summer to notify Pavan. 2. Pavan and Sowmya to further check internally on the release date. 3. Pavan to check with PO, if GFOX should be included into EMIR_Controls_Positions_Full report or not before our release. If the answer is no, PaCman will make a control from XTP side to exclude GFOX entries from EMIR_Controls_Positions_Full report. Thank you! Best Regards, Summer HE -------------------------------------------------------------------------------------------------------- From: Summer Sent: Friday, April 25, 2025 5:10 PM To: Ram Cc: Candace Xiaoyi Subject: RE: DQMA Discussion for GFOX - meeting minutes 20241209 INTERNAL Dear Ram, OK, thank you for confirmation on this! And for the 3 EMIR Controls report, do you think all of them can be changed to the new timing, for easier maintenance in future? Or only #3 should be changed (COB = Fri file to be generated on Mon) while the other 2 remain the same (COB = Fri file still generates on Sat)? 1. EMIR_Controls_Trades_Positions_Values.YYYYMMDD.csv - No impact, no need to include GFOX entries. 2. EMIR_ Controls _Collateral.YYYYMMDD.csv - No impact, no need to include GFOX entries. 3. EMIR_Controls_Positions_Full.YYYYMMDD.csv - To include GFOX entries. We only change the generation time of COB = Fri EMIR Controls report, and EMIR_Controls_Positions_Full.YYYYMMDD will include GFOX entries then. Thank you! Best Regards, Summer HE -------------------------------------------------------------------------------------------------------- From: Ramsunder Sent: Friday, April 25, 2025 5:29 PM To: Summer; Sheryl; Nandan; Singh; Gunipe; Pavan; Uttara Subject: RE: DQMA Discussion for GFOX - meeting minutes 20241209 INTERNAL Hi Summer, The requirements and understanding of these reports are as follows. 1. EMIR_Controls_Trades_Positions_Values.YYYYMMDD.csv -- I know no impact, but stating for common understanding. This report will Contain all daily Transaction , valuation and position of Records that are submitted by Brokers & ICE. 2. EMIR_Refit_Collateral.YYYYMMDD.csv – Similar to above point, no impact. This report will contain daily collateral submissions. 3. EMIR_Controls_Positions_Full.YYYYMMDD.csv - The expectation and requirement of this report is to have all OPEN position as of a day ( Irrespective of if its self Reported or Broker/Ice Reported). The usage of the content of the report might differ and as on today we might not be using all the content w.r.t Recon or MI. But the requirement is to have the full self + Broker/ICE related position information. So GFOX information should be included in this report. This part is clear. Now, changes to EOD timing will Impact RL , Recon and potentially DQMA too ( depending on how RL handles the changes to the timing). This was brought up to the team only in last week of April. I get to understand that TRACK is already receiving their files and they have gone Live with GFOX reporting. That is fine w,r,t Controls as we also consume self reported data from TRACK. But the Expectation of the “EMIR_Controls_Positions_Full.YYYYMMDD.csv” to have all Data needs to be met. So please co-ordinate with Reporting Lake and enable this change at a suitable date from everyone’s point of view. Pavan – you will have to discuss with Recon and DQMA too. Thanks & Rgds, Ram -------------------------------------------------------------------------------------------------------- From: Ramsunder Sent: Friday, April 25, 2025 5:29 PM To: Summer; Sheryl; Nandan; Singh; Gunipe; Pavan; Uttara Subject: RE: DQMA Discussion for GFOX - meeting minutes 20241209 INTERNAL Hi Summer, Looping in Appropriate teams. Friday EOD files being received on Monday morning instead of Sat morning – I don’t believe there is an impact to our side. @Gangulikar, Uttara Bhaskar / @DQMA Team – Can you please check and double confirm. This will obviously impact the OLA documents between systems. Once the team confirms, you will have to work with @Shivannagari, Pavan to update relevant OLA. @Shivannagari, Pavan – please check if you have to update anything from your side, in terms of monitoring etc. Thanks & Rgds, Ram -------------------------------------------------------------------------------------------------------- From: Summer Sent: Friday, April 25, 2025 5:10 PM To: Ram Cc: Candace Xiaoyi Subject: RE: DQMA Discussion for GFOX - meeting minutes 20241209 INTERNAL Dear Ram, Once GFOX goes live, considering of the EOD timing difference for Prime, you may receive the Friday EMIR Report the following Monday instead of Sat. OLA may be changed then. And PRIME EOD on Monday normally is around 11:00 AM SGT/03:00 AM GMT, when files are generated and sent to downstreams. While no impact to the reports for Mon – Thu. Are you fine with this please? Best Regards, Summer HE
08-16
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值