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代码及总结这道题目的总结 题目要求 ...
随机推荐
- MongoDB入门(8)- c#通过操作MongoDB GridFS实现文件的数据库存储
GridFS介绍 GridFS是MongoDB中的一个内置功能,可以用于存放大量小文件. GridFS GridFS长啥样 /* 1 */ { "_id" : ObjectId(& ...
- 51Nod 1090 3个数之和
Input示例 7 -3 -2 -1 0 1 2 3 Output示例 -3 0 3 -3 1 2 -2 -1 3 -2 0 2 -1 0 1 #include "bits/stdc++.h ...
- sqlserver xml转表 及(cross apply与outer apply)
一. 需求是需要把','分割的字符串转为表,便于做关联查询,于是发现可以通过xml转为表,如下: declare @XXX xml set @XXX = ' <v> <aa>1 ...
- 【BZOJ】1609: [Usaco2008 Feb]Eating Together麻烦的聚餐
[算法]动态规划 [题解]DP有个特点(递推的特点),就是记录所有可能状态然后按顺序转移. 最优化问题中DP往往占据重要地位. f[i][j]表示前i头奶牛,第i头改为号码j的最小改动数字,这样每头奶 ...
- Codeforces Round #484 (Div. 2)
题目链接:http://codeforces.com/contest/982 A. Row time limit per test:1 second memory limit per test:256 ...
- 2017-2018-1 20179205《Linux内核原理与设计》第二周作业
<Linux内核原理与分析>第二周作业 本周视频学习情况: 通过孟老师的视频教程,大致对风诺依曼体系结构有了一个初步的认识,视频从硬件角度和程序员角度对CPU和Main Memory(内存 ...
- Vuex 基本概念
Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式.它采用集中式存储管理应用的所有组件的状态,并以相应的规则保证状态以一种可预测的方式发生变化. 每一个 Vuex 应用的核心就是 stor ...
- device tree property ---- interrupt-names
device tree source 的 interrupt-names property 會對應到 pltform_get_irq_byname() 的第二個參數. .dtsi or .dts in ...
- MySQL多线程复制故障(slave_pending_jobs_size_max)
MySQL多线程复制故障(slave_pending_jobs_size_max) http://www.xuchanggang.cn/archives/1079.html
- canvas制作柱形图/折线图/饼状图,Konva写动态饼状图
制作饼状图 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...