题意:训练指南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. (5.5)mysql高可用系列——MySQL半同步复制(实践)

    关键词,mysql半同步复制 [0]实验环境 操作系统:CentOS linux 7.5 数据库版本:5.7.24 数据库架构:主从复制,主库用于生产,从库用于数据容灾和主库备机,采用默认传统的异步复 ...

  2. Fiddler-打断点(bpu)

    一.断点 1.为什么要打断点? 比如一个购买的金额输入框,输入框前端做了限制大于100,那么我们测试的时候,需要测试小于100的情况下.很显然前端只能输入大于100的.这时我们可以先抓到接口,修改请求 ...

  3. Python学习【day05】- Python文件处理

    一.打开文件 对文件的操作主要为三步:1.打开文件,得到文件句柄.2.通过句柄对文件进行操作.3.关闭文件 # 默认打开模式为r,encoding默认为系统文件编码 f=open('F:/Go.txt ...

  4. python 操作mongodb 文件相关

    https://api.mongodb.com/python/current/tutorial.html# 文档地址 from pymongo import MongoClientfrom gridf ...

  5. redis 单线程的理解

    单线程模型 Redis客户端对服务端的每次调用都经历了发送命令,执行命令,返回结果三个过程.其中执行命令阶段,由于Redis是单线程来处理命令的,所有每一条到达服务端的命令不会立刻执行,所有的命令都会 ...

  6. leecode刷题(23)-- 合并两个有序链表

    leecode刷题(23)-- 合并两个有序链表 合并两个有序链表 将两个有序链表合并为一个新的有序链表并返回.新链表是通过拼接给定的两个链表的所有节点组成的. 示例: 输入:1->2-> ...

  7. docker toolbox的redis 配置主从及哨兵模式保证高可用

    redis 的缓存中间件安装方法,简单举例如下: 环境: docker toolbox 一   主从模式1 搜索redis镜像  docker search redis2 拉取镜像docker pul ...

  8. 浅尝https

    HTTPS http超文本传输协议,所以的东西都是明文传输,容易被拦截,被攻击,我们希望能对通话内容进行加密,那么因此而生,出现了https https:在http的基础上新增加了SSL层 先放图 / ...

  9. 关于overflow的学习

    我在此记录一下我的学习到的东西,我自己不清楚所以要记录下来. overflow:hidden 但内元素的高度或宽度大于外元素的高度或宽度时,自动隐藏多余的部分,当然外元素设置了固定的高度或宽度. ov ...

  10. 2019-2020-1 20199319《Linux内核原理与分析》第八周作业

    可执行程序工作原理 ELF目标文件格式 1.目标文件(ABI,应用程序二进制接口):编译器生成的文件. 2.目标文件的格式:out格式.COFF格式.PE(windows)格式.ELF(Linux)格 ...