POJ 1990 MooFest 树状数组

MooFest
Time Limit: 1000MS Memory Limit: 30000K
Total Submissions: 9189 Accepted: 4158

Description

Every year, Farmer John's N (1 <= N <= 20,000) cows attend "MooFest",a social gathering of cows from around the world. MooFest involves a variety of events including haybale stacking, fence jumping, pin the tail on the farmer, and of course, mooing. When the cows all stand in line for a particular event, they moo so loudly that the roar is practically deafening. After participating in this event year after year, some of the cows have in fact lost a bit of their hearing. 

Each cow i has an associated "hearing" threshold v(i) (in the range 1..20,000). If a cow moos to cow i, she must use a volume of at least v(i) times the distance between the two cows in order to be heard by cow i. If two cows i and j wish to converse, they must speak at a volume level equal to the distance between them times max(v(i),v(j)). 

Suppose each of the N cows is standing in a straight line (each cow at some unique x coordinate in the range 1..20,000), and every pair of cows is carrying on a conversation using the smallest possible volume. 

Compute the sum of all the volumes produced by all N(N-1)/2 pairs of mooing cows. 

Input

* Line 1: A single integer, N 

* Lines 2..N+1: Two integers: the volume threshold and x coordinate for a cow. Line 2 represents the first cow; line 3 represents the second cow; and so on. No two cows will stand at the same location. 

Output

* Line 1: A single line with a single integer that is the sum of all the volumes of the conversing cows. 

Sample Input

4
3 1
2 5
2 6
4 3

Sample Output

57

Source

USACO 2004 U S Open

题意 给你若干牛的声贝值和他们的x坐标 叫你求每两个牛之间的距离乘上他们两个的最大声贝值

我们怎么分析呢?我们这样考虑

大声贝的牛出现 会影响乘法的声贝值

那么我们按照声贝排序 按小到大的顺序 这样每次我乘法的声贝值都是取新加的这个牛

这个牛x坐标前面有几个牛呢? 维护一个lsum 左边的牛 那么右边的牛数目自然为i-1-lsum

那么左边的牛的距离和是多少呢?是lsum * x - lsumdisx(左边牛的距离和) 那么右边牛的距离自然为sumdisx(总距离和)-lsumdisx-(i-1-lsum)*x

那么我们这样树状数组 维护一个 数量前缀数组a

距离前缀和数组b 就可以实现了

#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
const int MAX_N = 20024;
long long a[MAX_N],b[MAX_N],xsum[MAX_N];
struct node {
    int x;
    int v;
    bool operator < ( const node &t) const {
         return v<t.v;
    }
}col[MAX_N];
long long getsum(int x,long long *arr){
    long long ans = 0;
    for(int i = x;i;i-=i&(-i)) ans+=arr[i];
    return ans;
}
void change(int x,long long dis,long long *arr,long long v){
   for(;x<=dis;x+=x&(-x)) arr[x]+=v;
}

int main(){
    int n;
    scanf("%d",&n);
    long long dis = -1;
    for(int i=1;i<=n;++i){
        scanf("%d%d",&col[i].v,&col[i].x);
        if(col[i].x>=dis) dis= col[i].x;
    }
    sort(col+1,col+1+n);
    long long ans = 0;
    for(int i=1;i<=n;++i) xsum[i] = xsum[i-1]+col[i].x;
    for(int i=1;i<=n;++i){
      long long dl = getsum(col[i].x,a);
      long long dr = i-1-dl;
      long long lsum = getsum(col[i].x,b);
      long long rsum = xsum[i-1]-lsum;
      ans+=col[i].v*(dl*col[i].x-lsum);
      ans+=col[i].v*(rsum-dr*col[i].x);
      change(col[i].x,dis,a,1);
      change(col[i].x,dis,b,col[i].x);
    }
    printf("%lld\n",ans);
    return 0;
}

内容概要:本文系统介绍了基于C#(VS2022+.NET Core)与HALCON 24.11的工业视觉测量拟合技术,涵盖边缘提取、几何拟合、精度优化及工业部署全流程。文中详细解析了亚像素边缘提取、Tukey抗噪算法、SVD平面拟合等核心技术,并提供了汽车零件孔径测量、PCB焊点共面性检测等典型应用场景的完整代码示例。通过GPU加速、EtherCAT同步等优化策略,实现了±0.01mm级测量精度,满足ISO 1101标准。此外,文章还探讨了深度学习、量子启发式算法等前沿技术的应用前景。 适合人群:具备一定编程基础,尤其是熟悉C#和HALCON的工程师或研究人员,以及从事工业视觉测量与自动化检测领域的技术人员。 使用场景及目标:①学习如何使用C#和HALCON实现高精度工业视觉测量系统的开发;②掌握边缘提取、抗差拟合、3D点云处理等核心技术的具体实现方法;③了解工业部署中的关键技术,如GPU加速、EtherCAT同步控制、实时数据看板等;④探索基于深度学习和量子计算的前沿技术在工业视觉中的应用。 其他说明:本文不仅提供了详细的理论分析和技术实现,还附有完整的代码示例和实验数据,帮助读者更好地理解和实践。同时,文中提到的硬件选型、校准方法、精度验证等内容,为实际项目实施提供了重要参考。文章最后还给出了未来的技术演进方向和开发者行动建议,如量子-经典混合计算、自监督学习等,以及参与HALCON官方认证和开源社区的建议。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值