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 ;
return ;
}
int main(){
scanf("%d%d",&n,&d);
d=d*d;
for(int i=;i<=n;i++)scanf("%d%d%d",&a[i],&b[i],&c[i]);
for(int i=;i<=n;i++){
for(int j=i+;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-;
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<=*n){
c[p]+=x;
p+=lowbit(p);
}
}
long long query(int p){
long long sum=;
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=;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+,p++num,cmp);
for(int i=;i<=num;i++){
if(vis[p[i].id]){
ans+=query(i)-query(vis[p[i].id]);
update(vis[p[i].id],-);
}
else {
vis[p[i].id]=i;
update(i,);
}
}
printf("%lld",ans);
return ;
}

100分

洛谷P2950 [USACO09OPEN]牛绣Bovine Embroidery的更多相关文章

  1. 洛谷 2953 [USACO09OPEN]牛的数字游戏Cow Digit Game

    洛谷 2953 [USACO09OPEN]牛的数字游戏Cow Digit Game 题目描述 Bessie is playing a number game against Farmer John, ...

  2. 洛谷——P2952 [USACO09OPEN]牛线Cow Line

    P2952 [USACO09OPEN]牛线Cow Line 题目描述 Farmer John's N cows (conveniently numbered 1..N) are forming a l ...

  3. 洛谷P3043 [USACO12JAN]牛联盟Bovine Alliance

    P3043 [USACO12JAN]牛联盟Bovine Alliance 题目描述 Bessie and her bovine pals from nearby farms have finally ...

  4. 洛谷P3045 [USACO12FEB]牛券Cow Coupons

    P3045 [USACO12FEB]牛券Cow Coupons 71通过 248提交 题目提供者洛谷OnlineJudge 标签USACO2012云端 难度提高+/省选- 时空限制1s / 128MB ...

  5. 洛谷 P2949 [USACO09OPEN]工作调度Work Scheduling 题解

    P2949 [USACO09OPEN]工作调度Work Scheduling 题目描述 Farmer John has so very many jobs to do! In order to run ...

  6. 洛谷 P3048 [USACO12FEB]牛的IDCow IDs

    题目描述 Being a secret computer geek, Farmer John labels all of his cows with binary numbers. However, ...

  7. 洛谷P2853 [USACO06DEC]牛的野餐Cow Picnic

    题目描述 The cows are having a picnic! Each of Farmer John's K (1 ≤ K ≤ 100) cows is grazing in one of N ...

  8. [洛谷P3014][USACO11FEB]牛线Cow Line (康托展开)(数论)

    如果在阅读本文之前对于康托展开没有了解的同学请戳一下这里:  简陋的博客    百度百科 题目描述 N(1<=N<=20)头牛,编号为1...N,正在与FJ玩一个疯狂的游戏.奶牛会排成一行 ...

  9. 洛谷 P2951 [USACO09OPEN]捉迷藏Hide and Seek

    题目戳 题目描述 Bessie is playing hide and seek (a game in which a number of players hide and a single play ...

随机推荐

  1. ELK日志收集系统搭建

     架构图 ELK  架构图:其中es 是集群,logstash 是单节点(猜想除非使用nginx对log4j的网络输出分发),kibana是单机(用不着做成集群). 1.拓扑图 2.logstash ...

  2. 【linux】ubuntu16.04安装vncserver实现远程访问图形界面

    # 步骤 1 - 安装 X11VNC  sudo apt install x11vnc -y # 步骤 2 - 配置访问密码 sudo x11vnc -storepasswd /etc/x11vnc. ...

  3. web 全栈 学习 2 一个好的页面是如何炼成的

    第一章:Web页面内容的构成2.Web内容的分工一个Web页面可能的构成(视觉上看):①文字.链接.标题②交互入口(表单元素)③图片(哪些类型)④动画 Flash动画 HTML5 CSS3 动画⑤音视 ...

  4. ZOJ3228 Searching the String —— AC自动机 + 可重叠/不可重叠

    题目链接:https://vjudge.net/problem/ZOJ-3228 Searching the String Time Limit: 7 Seconds      Memory Limi ...

  5. html5手机网站需要加的那些meta标签,手机网站自适应

    的html5相关meta和标签    a.<!-- 强制让文档与设备的宽度保持1:1 -->    <meta name="viewport" content=& ...

  6. Dubbo之生产者

    环境步骤: 安装Zookeepr启动 创建Maven项目搭建生产者和消费者 安装DubboAdmin平台,实现监控 Dubbo注册中心采用的是Zookeeper.为什么采用Zookeeper呢? Zo ...

  7. python返回列表中指定内容的索引

    import numpy as npa=[2,10,2,3,4,10,10]ans = np.where(np.array(a)==10)print(ans) 结果是:(array([1, 5, 6] ...

  8. python之menu

    只有主菜单没有二级菜单的例子: from tkinter import * root=Tk() root.wm_title('同济大学财务管理系统') menubar=Menu(root)#指定菜单实 ...

  9. POSTGRESQL 导入导出

    安装postgresql yum install postgresql postgresql-server mysql占用端口3306 pgsql是5432 2 导入整个数据库 psql -U pos ...

  10. Linux_服务器_03_xxx is not in the sudoers file.This incident will be reported.的解决方法

    1.切换到root用户下,怎么切换就不用说了吧,不会的自己百度去. 2.添加sudo文件的写权限,命令是:chmod u+w /etc/sudoers 3.编辑sudoers文件vi /etc/sud ...