暴力。

先删掉一些边,平行的线只保留$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. #应用openxml读写excel代码

    这个例子比较简单,没有考虑格式之类的问题. using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Spreadshe ...

  2. 任务调度 Quartz 学习(三) CronTrigger 表达式

    CronTrigger CronTriggers往往比SimpleTrigger更有用,如果您需要基于日历的概念,而非SimpleTrigger完全指定的时间间隔,复发的发射工作的时间表. CronT ...

  3. 51Nod 1082 | 模拟

    Input示例 5 4 5 6 7 8 Output示例 30 55 91 91 155 模拟 #include "bits/stdc++.h" using namespace s ...

  4. 删除windows上特定目录下以*.rar后缀名的python脚本

    import os,fnmatch,datetime,time def all_files(root,pattern='*',single_level=False,yield_folders=Fals ...

  5. Large Class--过大的类--要重构的信号

    如果想利用单个类做太多事情,其内往往就会出现太多实例变量.一旦如此,Duplicated Code也就接踵而至.     解决方法:     1.将类内彼此相关的变量,将它们放在一起.使用Extrac ...

  6. Item 6 消除过期的对象引用

    过期对象引用没有清理掉,会导致内存泄漏.对于没有用到的对象引用,可以置空,这是一种做法.而最好的做法是,把保存对象引用的变量清理掉,多用局部变量.   什么是内存泄漏? 在Java中,对象的内存空间回 ...

  7. 【bzoj1572-工作安排】贪心

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1572 题意: 约翰接到了N份工作,每份工作恰好占用一天的时间.约翰从第一天开始工作,他可以任意 ...

  8. div圆角

    div{    -moz-border-radius: 10px;    -webkit-border-radius: 10px;    border-radius: 10px;}

  9. 利用itext将html转为pdf

    亲测代码没有问题,需要注意细节已经标注:需要jar包:iText-2.0.8.jar:core-renderer-R8.jar: core-renderer-R8.jar下载地址:http://cen ...

  10. 【Python学习笔记】Coursera课程《Using Databases with Python》 密歇根大学 Charles Severance——Week4 Many-to-Many Relationships in SQL课堂笔记

    Coursera课程<Using Databases with Python> 密歇根大学 Week4 Many-to-Many Relationships in SQL 15.8 Man ...