题意:训练指南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 好看的一笔画 欧拉几何+计算几何模板的更多相关文章

  1. nyoj 42 一笔画 欧拉通路

    http://acm.nyist.net/JudgeOnline/problem.php?pid=42 一笔画问题 时间限制:3000 ms  |  内存限制:65535 KB 难度:4 描述 zyc ...

  2. B - GuGuFishtion(莫比乌斯 欧拉函数 预处理mu函数的欧拉函数的模板)

    题目链接:https://cn.vjudge.net/contest/270608#problem/B 题目大意:题目中说,就是对欧拉函数的重新定义的一种函数的求和. 证明方法: AC代码: #inc ...

  3. 欧拉函数:HDU1787-GCD Again(欧拉函数的模板)

    GCD Again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  4. HDU - 2824 The Euler function 欧拉函数筛 模板

    HDU - 2824 题意: 求[a,b]间的欧拉函数和.这道题卡内存,只能开一个数组. 思路: ϕ(n) = n * (p-1)/p * ... 可利用线性筛法求出所有ϕ(n) . #include ...

  5. 牛客OI测试赛 F 子序列 组合数学 欧拉降幂公式模板

    链接:https://www.nowcoder.com/acm/contest/181/F来源:牛客网 题目描述 给出一个长度为n的序列,你需要计算出所有长度为k的子序列中,除最大最小数之外所有数的乘 ...

  6. 欧拉函数&筛法 模板

    https://blog.csdn.net/Lytning/article/details/24432651    记牢通式 =x((p1-1)/p1) * ((p2-1)/p2)....((pn-1 ...

  7. poj 2478 Farey Sequence(欧拉函数是基于寻求筛法素数)

    http://poj.org/problem?id=2478 求欧拉函数的模板. 初涉欧拉函数,先学一学它主要的性质. 1.欧拉函数是求小于n且和n互质(包含1)的正整数的个数. 记为φ(n). 2. ...

  8. POJ 2407 Relatives【欧拉函数】

    <题目链接> 题目大意: Given n, a positive integer, how many positive integers less than n are relativel ...

  9. hdu1286 找新朋友 欧拉函数模板

    首先这一题用的是欧拉函数!!函数!!不是什么欧拉公式!! 欧拉函数求的就是题目要求的数. 关于欧拉函数的模板网上百度一下到处都是,原理也容易找,这里要介绍一下另一个强势模板. 在这一题的讨论里看到的. ...

随机推荐

  1. 3. Linux的shell编程

    Shell 是一个用 C 语言编写的程序, 通过 Shell 用户可以访问操作系统内核服务.它类似于 DOS 下的 command 和后来的 cmd.exe.Shell 既是一种命令语言,又是一种程序 ...

  2. Go语言流程控制(六)

    go语言的流程控制主要有if , for和switch. if else(分支结构) go语言的if判断: func main() { score:=65 if score>=90{ fmt.P ...

  3. CSUST 2012 一个顶俩 (本校OJ题)(思维+树链剖分)

    (点击这里查看原题,不保证可以进去....外网可能比较卡) Description A:一心一意 B:一个顶俩 最近QQ更新后那个成语接龙好像挺火的?但我只知道图论里一条边是一个顶俩个点的emm. 如 ...

  4. MySQL_入手<二>之删--改--查

    接上 上篇文章继续 查询 # 比较运算 # 根据WHERE条件查找数据: = > < >= <= != select * from t_hero where age < ...

  5. 生成ini文件

    setProfileString是无法直接生成ini文件的,如果不存在这个ini文件需要先创建,然后再setProfileString.示例代码//保存连接参数到配置文件if not FileExis ...

  6. solr学习笔记-增加mmesg4J中文分词

    solr版本6.1.centos6.7.mmesg4j版本2.30 solr安装目录:/usr/local/solr-6.1.0 1.下载mmesg4j包: 地址:https://github.com ...

  7. button标签与input type=button标签使用的差异

    button标签和input type=button标签都是html文档中用来表示按钮属性的元素,不过他们在布局和实际使用功能中存在一些差异. 下面将项目中遇到的一些总结如下: 1.属性和布局差异. ...

  8. 关于redis的几件小事(八)缓存与数据库双写时的数据一致性

    1.Cache aside pattern 这是最经典的 缓存+数据库 读写模式,操作如下: ①读的时候,先读缓存,缓存没有就读数据库,然后将取出的数据放到缓存,同时返回请求响应. ②更新的时候,先删 ...

  9. Vue的nextTick是什么?

    公司做之前项目的时候,遇到了一些比较困惑的问题,后来研究明白了nextTick的用法. 我们先看两种情况: 第一种: export default { data () { return { msg: ...

  10. 解决stackoverflow加载慢的插件

    浏览stackoverflow的时候,比较慢,网上找到一个大神写的小工具 挺管用,给推荐下. gitthub地址: https://github.com/justjavac/ReplaceGoogle ...