暴力。

先删掉一些边,平行的线只保留$b$最大的。然后暴力,每次放入第$i$条边,和还没有被完全覆盖的边都算一遍,更新一下。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<ctime>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0);
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c = getchar();
x = ;
while(!isdigit(c)) c = getchar();
while(isdigit(c))
{
x = x * + c - '';
c = getchar();
}
}
double INF=999999999999999.0;
#define eps 1e-8
#define zero(x) (((x)>0?(x):-(x))<eps) struct point
{
double x,y;
}; struct line
{
point a,b;
double K,B;
double ll,rr;
} L[],tmp[]; int T,n;
int f[]; bool cmp(line a,line b)
{
if(a.K!=b.K) return a.K>b.K;
return a.B>b.B;
} point intersection(point u1,point u2,point v1,point v2)
{
point ret=u1;
double t=((u1.x-v1.x)*(v1.y-v2.y)-(u1.y-v1.y)*(v1.x-v2.x))
/((u1.x-u2.x)*(v1.y-v2.y)-(u1.y-u2.y)*(v1.x-v2.x));
ret.x+=(u2.x-u1.x)*t;
ret.y+=(u2.y-u1.y)*t;
return ret;
} int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d",&n); for(int i=; i<n; i++) scanf("%lf%lf",&tmp[i].K,&tmp[i].B);
sort(tmp,tmp+n,cmp); int sz=;
L[sz++]=tmp[];
for(int i=; i<n; i++)
{
if(abs(L[sz-].K-tmp[i].K)<eps) continue;
L[sz++]=tmp[i];
} for(int i=; i<sz; i++)
{
point p1;
p1.x=;
p1.y=L[i].K*+L[i].B;
point p2;
p2.x=-;
p2.y=L[i].K*(-)+L[i].B; L[i].a=p1, L[i].b=p2;
L[i].ll=-INF, L[i].rr=INF;
} memset(f,,sizeof f); for(int i=; i<sz; i++)
{
for(int j=; j<i; j++)
{
if(f[j]) continue; point jiao = intersection(L[i].a,L[i].b,L[j].a,L[j].b); if(L[i].K>=&&L[i].K>L[j].K)
{
L[i].ll=max(L[i].ll,jiao.x);
L[j].rr=min(L[j].rr,jiao.x);
} else if(L[i].K>=&&L[i].K<L[j].K)
{
L[i].rr=min(L[i].rr,jiao.x);
L[j].ll=max(L[j].ll,jiao.x);
} else if(L[i].K<&&L[j].K>L[i].K)
{
L[i].rr=min(L[i].rr,jiao.x);
L[j].ll=max(L[j].ll,jiao.x);
} else if(L[i].K<&&L[j].K<L[i].K)
{
L[i].ll=max(L[i].ll,jiao.x);
L[j].rr=min(L[j].rr,jiao.x);
} if(L[i].rr<=L[i].ll+eps) f[i]=;
if(L[j].rr<=L[j].ll+eps) f[j]=; }
} int ans=;
for(int i=; i<sz; i++) if(f[i]==) ans++;
printf("%d\n",ans);
}
return ;
}

ZOJ 2967 Colorful Rainbows的更多相关文章

  1. ZOJ 2967 Colorful Rainbows 【Stack】

    解决此题方法类似于凸包,先把所有直线按照斜率a由小到大排序 斜率相同取b较大的,扔掉b小的 (可以在遍历的时候忽视).于是所有直线斜率不同. 准备一个栈 (手动模拟), 栈里面存放上一次能看到的“最上 ...

  2. ZOJ 3967 Colorful Rainbows --栈的应用

    题意:给出n条y=ai*x+bi的直线.对于这些直线,如果存在x使得该直线y大于其他任意一直线,那么这条直线可以被看见,问有多少条直线可以被看见. 做法什么的不讲了,参见:http://blog.cs ...

  3. ZOJ 2967计算几何+单调栈

    ZOJ - 2967Colorful Rainbows 题目大意:给你道彩虹,每条彩虹有两个属性,a斜率和b截距,也就是彩虹描述为y=ax+b的直线,并且不存在垂直的彩虹以及一样的彩虹.然后就说明,如 ...

  4. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  5. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

  6. ZOJ 3435 Ideal Puzzle Bobble

    ZOJ Problem Set - 3435 Ideal Puzzle Bobble Time Limit: 2 Seconds      Memory Limit: 65536 KB Have yo ...

  7. ZOJ People Counting

    第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ  3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...

  8. ZOJ 3686 A Simple Tree Problem

    A Simple Tree Problem Time Limit: 3 Seconds      Memory Limit: 65536 KB Given a rooted tree, each no ...

  9. ZOJ Problem Set - 1394 Polar Explorer

    这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...

随机推荐

  1. Matlab 工具箱介绍

    Toolbox工具箱 序号 工具箱 备注 数学.统计与优化 1 Symbolic Math Toolbox 符号数学工具箱 2 Partial Differential Euqation Toolbo ...

  2. JavaScript之typedof,instanceof,Array.isArray()

    typedof value检测对象类型. value instanceof Array检测a对象是否由b对象类型 Array.isArray(value)在两个框架中判断是否为数组类型.

  3. django自带分页代码

    django分页 {% if is_paginated %} <div class="pagination-simple"> <!-- 如果当前页还有上一页,显示 ...

  4. PHP 练习1:新闻发布

    1.新闻发布主页面 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://w ...

  5. 深入分析Spring 与 Spring MVC容器(山东数漫江湖)

    1 Spring MVC WEB配置 Spring Framework本身没有Web功能,Spring MVC使用WebApplicationContext类扩展ApplicationContext, ...

  6. word 宏,脚本编程

    '脚本方式新建word 再新建文档,文档中输入字符串"你好" Dim wdapp As Word.Application Dim wddoc As Word.Document Se ...

  7. “adb server is out of date.

    今天,久未出现的著名的“adb server is out of date.  killing”又发生了,在此,将解决方法记下,以便日后查看. 1. 错误信息: C:\Users\lizy>ad ...

  8. linux arm的存储分布那些事之一

    转自:http://blog.csdn.net/xiaojsj111/article/details/11724081   linux arm 内存分布总览   上图是linux的arm的虚拟地址分布 ...

  9. 手机User-Agent

    iPhone  6(IOS 8.1.2):Mozilla/5.0 (iPhone; CPU iPhone OS 8_1_2 like Mac OS X) AppleWebKit/600.1.4 (KH ...

  10. hadoop-Rpc使用实例

    代码:https://github.com/xufeng79x/hadoop-common-rpc-demo 1. 简介 hadoop中使用rpc机制来进行分布式进程间的通信,被封装进了hadoop- ...