洛谷P2950 [USACO09OPEN]牛绣Bovine Embroidery

P2950 [USACO09OPEN]牛绣Bovine Embroidery

题目描述

Bessie has taken up the detailed art of bovine embroidery. Cows embroider a cloth mounted in a circular hoop of integer radius d (1 <= d <= 50,000). They sew N (2 <= N <= 50,000) threads, each in a straight line from one point on the edge of the hoop to another point on the edge of the hoop (no two embroidered points share a location on the hoop's edge).

Being mathematically inclined, Bessie knows a formula of the form ax + by + c = 0 for each straight line piece of thread. Conveniently, a, b, and c are integers (-1,000,000 <= a <= 1,000,000; -1,000,000 <= b <= 1,000,000; -1,000,000 <= c <= 1,000,000). Even more

conveniently, no two threads coincide exactly.

Perhaps less conveniently, Bessie knows that her set of formula coefficients also includes a number of formulae for threads that do not appear to pass inside the hoop's circle. She regrets this greatly.

The origin (0,0) is in the precise middle of the hoop, so all points on the hoop's edge are distance d from the origin. At least one of the coefficients a and b is non-zero for each thread's formula.

Bovine embroidery is more highly regarded when the number of thread intersections is maximized. Help Bessie: count the number of pairs of threads that intersect on the cloth (i.e., within distance d of the origin). Note that if three threads happen to coincide at the same point, that would be three pairs of intersections. Four threads at the same point -> six pairs of intersections, etc.

Bessie学会了刺绣这种精细的工作。牛们在一片半径为d(1 <= d <= 50000)的圆形布上绣花. 它们一共绣了N (2 <= N <= 50000)条直线,每条直线连接布的边缘上的两个点(没有两条线通过边上同一个点)。

作为一只热爱数学的牛,Bessie 知道每条线的公式, ax + by + c = 0. a, b, 和 c 为整数(-1000000 <= a <= 1000000; -1000000 <= b <= 1000000; -1000000 <= c <= 1000000).没有两条线完全重合。

不幸的是, 一部分线不通过圆布的内部. 原点(0,0)在布的正中央, 所有边上的点离原点距离为d. 每条线的公式满足至少a,b中的一个非零. 对于牛来说,刺绣作品中线的交点越多,便越有价值。帮助Bessie计算在圆中相交的线的对数,也就是说交点与原点的距离小于d。注意如果三条线在圆内同一点相交,这算3对线。4线共点->6对线.

输入输出格式

输入格式:

 

  • Line 1: Two space-separated integers: N and d

  • Lines 2..N+1: Line i+1 describes thread i with three integers: a, b, and c

 

输出格式:

 

  • Line 1: One integer, on a line by itself, that is the count of pairs of threads that intersect.

 

输入输出样例

输入样例#1:
2 1 
1 0 0 
0 1 0 
输出样例#1:
1 

说明

The two lines are x=0 and y=0.

The two lines intersect at (0,0), which is clearly with 1 of the origin.

#include<iostream>
#include<cstdio>
using namespace std;
#define maxn 50010
int n,d,a[maxn],b[maxn],c[maxn],ans;
bool check(int i,int j){
    int a1=a[i],a2=a[j],b1=b[i],b2=b[j],c1=c[i],c2=c[j];
    double x,y;
    int x1=a2*c1-a1*c2;
    int x2=b2*a1-a2*b1;
    y=(double)(x1)/(double)(x2);
    double x3=(double)(b1)*y+(double)(c1);
    x3=-x3;
    x=x3/(double)(a1);
    if(x*x+y*y<=d)return 1;
    return 0;
}
int main(){
    scanf("%d%d",&n,&d);
    d=d*d;
    for(int i=1;i<=n;i++)scanf("%d%d%d",&a[i],&b[i],&c[i]);
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            if(check(i,j))ans++;
        }
    }
    printf("%d",ans);
}
70分 暴力
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
#define N 100010
int n,num,c[N],vis[N];
long long ans,d;
const double eps=1e-9;
struct node{
    double ct;
    int id;
}p[N];
bool cmp(node x,node y){
    return x.ct-y.ct>eps;
}
int lowbit(int x){return x&(-x);}
void update(int p,int x){
    while(p<=2*n){
        c[p]+=x;
        p+=lowbit(p);
    }
}
long long query(int p){
    long long sum=0;
    while(p){
        sum+=c[p];
        p-=lowbit(p);
    }
    return sum;
}
int main(){
    //freopen("Cola.txt","r",stdin);
    scanf("%d%lld",&n,&d);
    long long a,b,c;
    for(int i=1;i<=n;i++){
        scanf("%lld%lld%lld",&a,&b,&c);
        //cin>>a>>b>>c;
        if(c*c<d*d*(a*a+b*b)){
            double tmp=a*a+b*b,tmp2=sqrt(d*d*tmp-c*c);
            double x1=(a*c+b*tmp2)/tmp;
            double x2=(a*c-b*tmp2)/tmp;
            double y1=(b*c-a*tmp2)/tmp;
            double y2=(b*c+a*tmp2)/tmp;
            p[++num].ct=atan2(y1,x1);p[num].id=i;
            p[++num].ct=atan2(y2,x2);p[num].id=i;
        }
    }
    sort(p+1,p+1+num,cmp);
    for(int i=1;i<=num;i++){
        if(vis[p[i].id]){
            ans+=query(i)-query(vis[p[i].id]);
            update(vis[p[i].id],-1);
        }
        else {
            vis[p[i].id]=i;
            update(i,1);
        }
    }
    printf("%lld",ans);
    return 0;
}
100分

 

转载于:https://www.cnblogs.com/thmyl/p/7352721.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
图像识别技术在病虫害检测中的应用是一个快速发展的领域,它结合了计算机视觉和机器学习算法来自动识别和分类植物上的病虫害。以下是这一技术的一些关键步骤和组成部分: 1. **数据收集**:首先需要收集大量的植物图像数据,这些数据包括健康植物的图像以及受不同病虫害影响的植物图像。 2. **图像预处理**:对收集到的图像进行处理,以提高后续分析的准确性。这可能包括调整亮度、对比度、去噪、裁剪、缩放等。 3. **特征提取**:从图像中提取有助于识别病虫害的特征。这些特征可能包括颜色、纹理、形状、边缘等。 4. **模型训练**:使用机器学习算法(如支持向量机、随机森林、卷积神经网络等)来训练模型。训练过程中,算法会学习如何根据提取的特征来识别不同的病虫害。 5. **模型验证和测试**:在独立的测试集上验证模型的性能,以确保其准确性和泛化能力。 6. **部署和应用**:将训练好的模型部署到实际的病虫害检测系统中,可以是移动应用、网页服务或集成到智能农业设备中。 7. **实时监测**:在实际应用中,系统可以实时接收植物图像,并快速给出病虫害的检测结果。 8. **持续学习**:随着时间的推移,系统可以不断学习新的病虫害样本,以提高其识别能力。 9. **用户界面**:为了方便用户使用,通常会有一个用户友好的界面,显示检测结果,并提供进一步的指导或建议。 这项技术的优势在于它可以快速、准确地识别出病虫害,甚至在早期阶段就能发现问题,从而及时采取措施。此外,它还可以减少对化学农药的依赖,支持可持续农业发展。随着技术的不断进步,图像识别在病虫害检测中的应用将越来越广泛。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值