URAL 2067 Friends and Berries

本文介绍了一种通过计算儿童间的好感度来寻找最佳朋友对的算法。好感度由距离公式定义,通过判断所有儿童是否共线来确定最佳朋友对。文章提供了完整的C++代码实现。
There is a group of n children. According to a proverb, every man to his own taste. So the children value strawberries and raspberries differently. Let’s say that i-th child rates his attachment to strawberry as s i and his attachment to raspberry as r i.
According to another proverb, opposites attract. Surprisingly, those children become friends whose tastes differ.
Let’s define friendliness between two children v, u as: p( v, u) = sqrt(( s vs u) 2 + ( r vr u) 2)
The friendliness between three children v, u, w is the half the sum of pairwise friendlinesses: p( v, u, w) = ( p( v, u) + p( v, w) + p( u, w)) / 2
The best friends are that pair of children v, u for which vu and p( v, u) ≥ p( v, u, w) for every child w. Your goal is to find all pairs of the best friends.
Input
In the first line there is one integer n — the amount of children (2 ≤ n ≤ 2 · 10 5).
In the next n lines there are two integers in each line — s i and r i (−10 8s i, r i ≤ 10 8).
It is guaranteed that for every two children their tastes differ. In other words, if vu then s vs u or r vr u.
Output
Output the number of pairs of best friends in the first line.
Then output those pairs. Each pair should be printed on a separate line. One pair is two numbers — the indices of children in this pair. Children are numbered in the order of input starting from 1. You can output pairs in any order. You can output indices of the pair in any order.
It is guaranteed that the amount of pairs doesn’t exceed 10 5.
Example
inputoutput
2
2 3
7 6
1
1 2
3
5 5
2 -4
-4 2
0
Hint

题目中那两个公式的意思就是如果两个点与其他任意一个点都共线并在同一边上,就存在最好的朋友,否则输出0
先排序,最远的两个点即为所求。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
struct node
{
    int x,y;
    int num;
}a[300005];
bool cmp(node a,node b)
{
    if(a.x==b.x) return a.y<b.y;
    return a.x<b.x;
}
int main()
{
    int n;
    scanf("%d",&n);
    int i;
    for(i=0;i<=n-1;i++)
    {
        scanf("%d%d",&a[i].x,&a[i].y);
        a[i].num=i+1;
    }
    sort(a,a+n,cmp);
    int flag=0;
    for(i=0;i<=n-1;i++)
    {
        if(abs(a[i].x-a[0].x)*abs(a[i].y-a[n-1].y)!=abs(a[i].x-a[n-1].x)*abs(a[i].y-a[0].y))
        {
            flag=1;
            break;
        }
    }
    if(!flag)
    {
        printf("1\n");
        printf("%d %d\n",a[0].num,a[n-1].num);
    }
    else printf("0\n");
    return 0;
}

内容概要:本文介绍了一项创新性未发表的研究,即利用多元宇宙优化算法(Multiverse Optimizer, MVO)对分时电价下的需求响应与综合能源系统调度问题进行建模与求解,旨在实现能源系统的经济性、高效性与可持续性运行。该研究构建了包含多种能源设备(如光伏、风机、燃气轮机、储能系统等)及可调节负荷的综合能源系统模型,充分考虑了用户侧的需求响应行为在分时电价机制下的响应特性,通过MVO算法对系统运行成本、能源利用率、碳排放等多目标进行协同优化,实现了日前调度计划的智能决策。研究还提供了完整的MATLAB代码实现,便于研究人员复现实验、验证算法性能,并为进一步研究提供可靠的仿真基础。; 适合人群:具备一定电力系统、优化算法及MATLAB编程基础的科研人员、研究生以及从事能源互联网、综合能源系统规划与运行的技术工程师。; 使用场景及目标:① 学习并掌握多元宇宙优化算法在复杂能源系统调度中的具体应用方法;② 研究分时电价机制如何通过需求响应引导用户参与电网互动,实现削峰填谷;③ 实现综合能源系统(IES)中冷、热、电、气等多种能源的协同优化调度,以降低运行成本、提高新能源消纳能力和系统可靠性;④ 为相关领域的学术研究提供可复现的代码实例和仿真平台。; 阅读建议:此资源以MATLAB代码为核心载体,深入剖析了算法应用与系统建模的全过程。建议读者在学习时,不仅应关注代码的实现细节,更要理解其背后的数学模型、优化目标设定和约束条件的物理意义。建议结合文档中的模型描述,逐步调试代码,观察不同参数和场景下的优化结果,从而深刻掌握综合能源系统优化调度的设计思想与关键技术。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值