Best Meeting Point

本文介绍了一种算法,用于计算给定二进制网格中所有朋友家到一个理想的聚会地点的最小总旅行距离。该算法首先收集所有朋友的位置,然后找到使总旅行距离最小化的中心点,使用曼哈顿距离计算每一对点之间的距离。

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

Given an m x n binary grid grid where each 1 marks the home of one friend, return the minimal total travel distance.

The total travel distance is the sum of the distances between the houses of the friends and the meeting point.

The distance is calculated using Manhattan Distance, where distance(p1, p2) = |p2.x - p1.x| + |p2.y - p1.y|.

Example 1:

Input: grid = [[1,0,0,0,1],[0,0,0,0,0],[0,0,1,0,0]]
Output: 6
Explanation: Given three friends living at (0,0), (0,4), and (2,2).
The point (0,2) is an ideal meeting point, as the total travel distance of 2 + 2 + 2 = 6 is minimal.
So return 6.

Example 2:

Input: grid = [[1,1]]
Output: 1
思路:题目意思是为了求所有点到中间点的距离,也就是所有点到横轴中心点和纵轴中心点,距离和。
1,2,3,4,5 计算所有值往中间走的距离之和,也就是 list.get(j) - list.get(i) ,加起来就可以了。
// 别忘记了,sort list,才能双指针加减;
class Solution {
    public int minTotalDistance(int[][] grid) {
        int m = grid.length;
        int n = grid[0].length;
        List<Integer> rowlist = new ArrayList<>();
        List<Integer> collist = new ArrayList<>();
        for(int i = 0; i < m; i++) {
            for(int j = 0; j < n; j++) {
                if(grid[i][j] == 1) {
                    rowlist.add(i);
                    collist.add(j);
                }
            }
        }
        
        return findcost(rowlist) + findcost(collist);
    }
    
    private int findcost(List<Integer> list) {
        // 别忘记了,sort list,才能双指针加减;
        Collections.sort(list);
        int start = 0; int end = list.size() - 1;
        int res = 0;
        while(start < end) {
            res += list.get(end) - list.get(start);
            end--;
            start++;
        }
        return res;
    }
}
有如下邮件内容,请问如何用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
从邮件内容中提取任务标题和描述,尤其是针对Azure DevOps(ADO)任务,通常涉及自然语言处理(NLP)中的信息抽取技术。可以通过以下步骤实现: ### 1. 邮件内容预处理 首先,需要对邮件内容进行预处理,包括去除HTML标签、清理无用字符、标准化文本格式等。可以使用Python的`BeautifulSoup`库去除HTML标签,并使用`re`库进行正则表达式清洗。 ```python from bs4 import BeautifulSoup import re def clean_email_content(text): # 去除HTML标签 soup = BeautifulSoup(text, "html.parser") text = soup.get_text() # 去除多余的空格和特殊字符 text = re.sub(r'\s+', ' ', text).strip() return text ``` ### 2. 使用命名实体识别(NER)识别任务相关信息 可以使用`spaCy`库进行命名实体识别,识别出邮件中可能包含的任务标题、描述等关键信息。虽然`spaCy`的默认模型不会直接识别“任务标题”这类实体,但可以基于已有数据进行微调或使用规则匹配来提取。 ```python import spacy nlp = spacy.load("en_core_web_sm") def extract_entities(text): doc = nlp(text) for ent in doc.ents: print(ent.text, ent.label_) ``` ### 3. 使用正则表达式或模式匹配提取结构化信息 邮件中通常会包含特定的关键词或结构,例如“任务标题:”、“描述:”、“Title:”等。可以基于这些关键词使用正则表达式提取信息。 ```python def extract_title_and_description(text): title_match = re.search(r"(?:任务标题|Title):\s*(.*?)(?=\n|$)", text, re.IGNORECASE) description_match = re.search(r"(?:描述|Description):\s*(.*?)(?=\n|$)", text, re.IGNORECASE) title = title_match.group(1).strip() if title_match else None description = description_match.group(1).strip() if description_match else None return title, description ``` ### 4. 使用机器学习模型进行信息抽取 如果邮件格式较为一致,可以构建一个基于Transformer的模型(如BERT)进行信息抽取。借助`transformers`库,可以使用预训练模型并进行微调,以识别邮件中的任务标题和描述。 ```python from transformers import pipeline ner_pipeline = pipeline("ner", grouped_entities=True) def extract_with_ner(text): ner_results = ner_pipeline(text) # 假设标题和描述在实体中具有特定模式 title = None description = None for result in ner_results: if result['entity_group'] == 'TITLE': title = result['word'] elif result['entity_group'] == 'DESCRIPTION': description = result['word'] return title, description ``` ### 5. 结合规则与机器学习方法 在实际应用中,可以结合规则匹配与机器学习模型,提高准确率。例如,优先使用正则表达式匹配已知格式的字段,若匹配失败再使用模型进行预测。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值