ZOJ 2967 Colorful Rainbows
暴力。
先删掉一些边,平行的线只保留$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的更多相关文章
- ZOJ 2967 Colorful Rainbows 【Stack】
解决此题方法类似于凸包,先把所有直线按照斜率a由小到大排序 斜率相同取b较大的,扔掉b小的 (可以在遍历的时候忽视).于是所有直线斜率不同. 准备一个栈 (手动模拟), 栈里面存放上一次能看到的“最上 ...
- ZOJ 3967 Colorful Rainbows --栈的应用
题意:给出n条y=ai*x+bi的直线.对于这些直线,如果存在x使得该直线y大于其他任意一直线,那么这条直线可以被看见,问有多少条直线可以被看见. 做法什么的不讲了,参见:http://blog.cs ...
- ZOJ 2967计算几何+单调栈
ZOJ - 2967Colorful Rainbows 题目大意:给你道彩虹,每条彩虹有两个属性,a斜率和b截距,也就是彩虹描述为y=ax+b的直线,并且不存在垂直的彩虹以及一样的彩虹.然后就说明,如 ...
- 杭电ACM分类
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
- ZOJ 3435 Ideal Puzzle Bobble
ZOJ Problem Set - 3435 Ideal Puzzle Bobble Time Limit: 2 Seconds Memory Limit: 65536 KB Have yo ...
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
- ZOJ Problem Set - 1394 Polar Explorer
这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...
随机推荐
- HDU 5961 传递 BFS
题意:中文题,就是判断一个竞赛图拆成两个图,判断是否都传递 思路:分别BFS判深度即可,用这种方法注意要进行读入优化. /** @Date : 2016-11-18-20.00 * @Author : ...
- mysql 在查询结果中进行二次查询
第一次查询:查询身份证编号和出现次数 select cardid,count(cardid) as total from p_person_info group by cardid 在第一次查询结果进 ...
- 「6月雅礼集训 2017 Day11」tree
[题目大意] 给出一棵带权树,有两类点,一类黑点,一类白点. 求切断黑点和白点间路径的最小代价. $n \leq 10^5$ [题解] 直接最小割能过..但是树形dp明显更好写 设$f_{x,0/1/ ...
- Java 扑克牌发牌
今天看到这个算法题,http://www.cnblogs.com/xishuai/p/3392981.html ,忍不住自己用Java做了一个. 初始化很重要,所有的52张牌按顺序放入到容器里边,标志 ...
- Ubuntu中启用关闭Network-manager网络设置问题! 【Server版本】
在UbuntuServer版本中,因为只存有命令行模式,所以要想进行网络参数设置,只能通过修改/etc/network/interfaces.具体设置方法如下: (1) UbuntuServer 修改 ...
- git - 开发者电脑与服务器的配置
首先公司要有一台git服务器,现在一般都托管在github服务器上,在中国可能会托管到oschina上,oschina有一点好处就是可以免费托管私有项目,而在github上想要托管自己的项目是收费的, ...
- 使用Webpack搭建Vue项目
前提: 1. 借助Node.js环境里的npm来安装, 2. 设置好npm镜像, (比如淘宝的npm镜像:输入 引用 npm install -g cnpm –registry=https://r ...
- Android SDK更新 Connection to http://dl-ssl.google.com refused
问题: Failed to fetch URL https://dl-ssl.google.com/android/repository/repository-6.xml, reason: Conne ...
- spring mvc3+默认首页设置问题
web.xml配置: <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-patte ...
- hdu 1455(DFS+好题+经典)
Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...