LA 3263 好看的一笔画 欧拉几何+计算几何模板
题意:训练指南260
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std; struct Point {
double x, y;
Point(double x = 0, double y = 0) : x(x) , y(y) { }
}; typedef Point Vector; Vector operator + (Vector A, Vector B) { return Vector(A.x+B.x, A.y+B.y); }
Vector operator - (Vector A, Vector B) { return Vector(A.x-B.x, A.y-B.y); }
Vector operator * (Vector A, double p) { return Vector(A.x*p, A.y*p); }
Vector operator / (Vector A, double p) { return Vector(A.x/p, A.y/p); } bool operator < (const Point& a, const Point& b) {
return a.x < b.x || (a.x == b.x && a.y < b.y);
} const double eps = 1e-10;
int dcmp(double x) {
if(fabs(x) < eps) return 0; else return x < 0 ? -1 : 1;
} bool operator == (const Point& a, const Point& b) {
return dcmp(a.x - b.x) == 0 && dcmp(a.y - b.y) == 0;
} double Dot(Vector A, Vector B) { return A.x*B.x + A.y*B.y; }
double Length(Vector A) { return sqrt(Dot(A, A)); }
double Angle(Vector A, Vector B) { return acos(Dot(A, B) / Length(A) / Length(B)); } double Cross(Vector A, Vector B) { return A.x*B.y - A.y*B.x; }
double Area2(Point A, Point B, Point C) { return Cross(B-A, C-A); } Vector Rotate(Vector A, double rad) {
return Vector(A.x*cos(rad) - A.y*sin(rad), A.x*sin(rad)+A.y*cos(rad) );
} Vector Normal(Vector A) {
double L = Length(A);
return Vector(-A.y/L, A.x/L);
} Point GetLineIntersection(Point P, Vector v, Point Q, Vector w) {
Vector u = P - Q;
double t = Cross(w, u) / Cross(v, w);
return P + v * t;
} double DistanceToLine(Point P, Point A, Point B) {
Vector v1 = B-A, v2 = P - A;
return fabs(Cross(v1,v2) / Length(v1));
} double DistanceToSegment(Point P, Point A, Point B) {
if(A==B) return Length(P-A);
Vector v1 = B - A, v2 = P - A, v3 = P - B;
if(dcmp(Dot(v1, v2)) < 0) return Length(v2);
else if(dcmp(Dot(v1, v3)) > 0) return Length(v3);
else return fabs(Cross(v1, v2)) / Length(v1);
} Point GetLineProjection(Point P, Point A, Point B) {
Vector v = B - A;
return A + v * ( Dot(v, P-A) / Dot(v, v) );
} bool SegmentProperIntersection(Point a1, Point a2, Point b1, Point b2) {
double c1 = Cross(a2 - a1, b1 - a1), c2 = Cross(a2 - a1, b2 - a1),
c3 = Cross(b2 - b1, a1 - b1), c4 = Cross(b2 - b1, a2 - b1);
return dcmp(c1) * dcmp(c2) < 0 && dcmp(c3) * dcmp(c4) < 0;
} bool OnSegment(Point p, Point a1, Point a2) {
return dcmp(Cross(a1 - p, a2 - p)) == 0 && dcmp(Dot(a1 - p, a2 - p)) < 0;
} double ConvexPolygonArea(Point* p, int n) {
double area = 0;
for(int i = 1; i < n-1; i++)
area += Cross(p[i] - p[0], p[i + 1] - p[0]);
return area / 2;
} const int maxn = 300 + 10;
Point P[maxn], V[maxn*maxn]; Point p[305],v[305*305];
int main()
{
int n,cas=0;
while(~scanf("%d",&n)&&n)
{
cas++;
for(int i=1;i<=n;i++)
{
scanf("%lf %lf",&p[i].x,&p[i].y);
v[i]=p[i];
}
n--; int cnt=n+1;
for(int i=1;i<=n;i++)
for(int j=i+1;j<=n;j++)
if(SegmentProperIntersection(p[i],p[i+1],p[j],p[j+1]))
v[++cnt]=GetLineIntersection(p[i],p[i+1]-p[i],p[j],p[j+1]-p[j]); sort(v+1,v+cnt+1);
int vnum=unique(v+1,v+cnt+1)-(v+1);
//for(int i=1;i<=vnum;i++)
// printf("v %d:%f %f\n",i,v[i].x,v[i].y);
int e=n;
//cout<<"ori "<<e<<endl;
for(int i=1;i<=vnum;i++)
for(int j=1;j<=n;j++)
if(OnSegment(v[i],p[j],p[j+1]))
e++;
//cout<<"vnum:"<<vnum<<" e:"<<e<<endl;
printf("Case %d: There are %d pieces.\n",cas,e+2-vnum);
}
return 0;//v+f-e=2;
}
LA 3263 好看的一笔画 欧拉几何+计算几何模板的更多相关文章
- nyoj 42 一笔画 欧拉通路
http://acm.nyist.net/JudgeOnline/problem.php?pid=42 一笔画问题 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 zyc ...
- B - GuGuFishtion(莫比乌斯 欧拉函数 预处理mu函数的欧拉函数的模板)
题目链接:https://cn.vjudge.net/contest/270608#problem/B 题目大意:题目中说,就是对欧拉函数的重新定义的一种函数的求和. 证明方法: AC代码: #inc ...
- 欧拉函数:HDU1787-GCD Again(欧拉函数的模板)
GCD Again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- HDU - 2824 The Euler function 欧拉函数筛 模板
HDU - 2824 题意: 求[a,b]间的欧拉函数和.这道题卡内存,只能开一个数组. 思路: ϕ(n) = n * (p-1)/p * ... 可利用线性筛法求出所有ϕ(n) . #include ...
- 牛客OI测试赛 F 子序列 组合数学 欧拉降幂公式模板
链接:https://www.nowcoder.com/acm/contest/181/F来源:牛客网 题目描述 给出一个长度为n的序列,你需要计算出所有长度为k的子序列中,除最大最小数之外所有数的乘 ...
- 欧拉函数&筛法 模板
https://blog.csdn.net/Lytning/article/details/24432651 记牢通式 =x((p1-1)/p1) * ((p2-1)/p2)....((pn-1 ...
- poj 2478 Farey Sequence(欧拉函数是基于寻求筛法素数)
http://poj.org/problem?id=2478 求欧拉函数的模板. 初涉欧拉函数,先学一学它主要的性质. 1.欧拉函数是求小于n且和n互质(包含1)的正整数的个数. 记为φ(n). 2. ...
- POJ 2407 Relatives【欧拉函数】
<题目链接> 题目大意: Given n, a positive integer, how many positive integers less than n are relativel ...
- hdu1286 找新朋友 欧拉函数模板
首先这一题用的是欧拉函数!!函数!!不是什么欧拉公式!! 欧拉函数求的就是题目要求的数. 关于欧拉函数的模板网上百度一下到处都是,原理也容易找,这里要介绍一下另一个强势模板. 在这一题的讨论里看到的. ...
随机推荐
- ABC136E Max GCD
Thinking about different ways of thinking. --- LzyRapx 题目 思路比较容易想到. Observations: 每次操作过后和不变. 枚举和的因子 ...
- Sql Server 常见的几种分页方式
⒈offset fetch next方式[SqlServer2012及以上版本支持][推荐] select * from T_User order by id offset rows /*(页数-1) ...
- C++学习 之 类中的特殊函数和this指针(笔记)
1.构造函数 构造函数是一种特殊的函数,它在对象被创建时被调用,与类同名无返回类型,可以被重载.构造函数的可以在类内实现也可以在类外实现. 构造函数的声明类似于下面的代码: class Human { ...
- javaScript的Array方法
仅个人总结 声明方法: var arr = new Array(); var arr = new Array(1,2,3,4,5); var arr = new array(size);//当为一个参 ...
- MYSQL中的UNION和UNION ALL
SQL UNION 操作符 UNION 操作符用于合并两个或多个 SELECT 语句的结果集. 请注意,UNION 内部的 SELECT 语句必须拥有相同数量的列.列也必须拥有相似的数据类型.同时,每 ...
- Robot Framework(一)安装笔记
参考网址:https://www.cnblogs.com/yinrw/p/5837828.html因为自己安装了py,网上教程都是统一安装py2.7开始的. 所以这里总结下安装笔记:cmd命令界面进行 ...
- arcgisJs之底图切换插件
arcgisJs之底图切换插件 底图切换插件在arcgis中有两种表现,如下: 1.两张底图切换 2.多张底图切换 一.两张地图切换 let basemapToggle = new BasemapTo ...
- 本人亲测-Setup Factory打包教程(整理并优化)
Setup Factory 9 总结 一:安装完毕立刻启动 result = Shell.Execute(SessionVar.Expand("%AppFolder%\\消息助手.exe&q ...
- Redis总结1
一.Redis安装(Linux) 1.在官网上下载Linux版本的Redis(链接https://redis.io/download) 2.在Linux的/usr/local中创建Redis文件夹mk ...
- 1.什么是bat文件
bat文件是dos下的批处理文件.批处理文件是无格式的文本文件,它包含一条或多条命令.它的文件扩展名为 .bat 或 .cmd. 在命令提示下输入批处理文件的名称,或者双击该批处理文件,系统就会调用c ...