gym 101081 E. Polish Fortress 几何
2.0 s
256 MB
standard input
standard output
The Malbork castle is the largest brick castle in the world. It was built in 1274 in honor to Holy Mary, and is located near the river Nogat, in Poland. During World War II it was totally destroyed. In this times it was discovered that the castle was actually built in many phases, and it was surrounded by a fortress and a wall centuries after it had began building.
In those times wall building was a very elaborate task. War tactics showed that it was convenient to build niches in the walls, that is, a recess on them. In these niches a soldier could stand in relative safety, since he could see all the area determined by the line segments in the niche without needing to turn his head (it was considered they field of vision of 180 degrees). The more niches a wall had, the safer the fortress was considered.
Your task in this problem is, given N points, the corners of the fortress, determine how many of them are niches as described above, in which soldiers could stand to protect the castle.
The first line has an integer N, the number of corners of the fortress. Each of the next N lines has two integers Xi and Yi, the coordinates of a fortress corner. The corners are given in clockwise or counterclockwise order. There are no three consecutive colinear points and the wall does not intersect itself.
Limits
- 3 ≤ N ≤ 105
- |X|, |Y| ≤ 1.8·104
Print a single integer, the number of niches in the fortress.
13
0 0
700 100
400 500
1300 600
700 400
1400 200
2200 1200
1500 2000
1500 1700
400 1700
400 2200
0 1900
10 1000
5
3
-32 45
2 19
-100 -3
0
The image shows the first example.

思路:判断多边形是否为逆时针输入(计算多边形面积),找有向面积小于0的连续三角形数目;
否则相反;
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<bitset>
#include<set>
#include<map>
#include<time.h>
using namespace std;
#define LL long long
#define pi (4*atan(1.0))
#define eps 1e-8
#define bug(x) cout<<"bug"<<x<<endl;
const int N=2e5+,M=1e6+,inf=1e9+;
const LL INF=1e18+,mod=1e9+; struct Point
{
double x, y ;
} p[N];
int n ;
double Area( Point p0, Point p1, Point p2 )// 求三角形面积公式//叉积
{
double area = ;
area = (p1.x-p0.x)*(p2.y-p0.y)-(p1.y-p0.y)*(p2.x-p0.x);
return area / ;
}
int ans1,ans2;
double xjhz1()
{
double sum_area = ;
for ( int i = ; i < n ; i++ )
{
double area = Area(p[],p[i-],p[i]) ;
sum_area += area ;
}
return sum_area;
}
void gans()
{
for (int i = ; i-<= n ; i++ )
{
double temp = Area(p[i-],p[i-],p[i]) ;
if(temp<0.0)ans1++;
else ans2++;
}
}
int main ()
{
scanf ( "%d", &n );
for(int i=; i<n; i++)
scanf ( "%lf%lf", &p[i].x, &p[i].y ),p[i+n]=p[i];
double sum=xjhz1();
gans();
if(sum>)printf("%d\n",ans1);
else printf("%d\n",ans2);
return ;
}
gym 101081 E. Polish Fortress 几何的更多相关文章
- gym 101081 gym F. Auction of Services 最小生成树+倍增LCA
F. Auction of Services time limit per test 2.0 s memory limit per test 256 MB input standard input o ...
- Gym 100531J Joy of Flight (几何)
题意:你从开始坐标到末尾坐标,要经过 k 秒,然后给你每秒的风向,和飞机的最大速度,问能不能从开始到末尾. 析:首先这个风向是不确定的,所以我们先排除风向的影响,然后算出,静风是的最小速度,如果这都大 ...
- 【Gym - 101124A】The Baguette Master (数学,几何)
BUPT2017 wintertraining(15) #4F Gym - 101124A 题意 给定画框宽度,画的四边和一个对角线长度,求画框外沿周长. 题解 过顶点做画框的垂线,每个角都得到两个全 ...
- On the way to the park Gym - 101147I 几何
http://codeforces.com/gym/101147/problem/I I. On the way to the park time limit per test 5 seconds m ...
- Gym - 100783G:Playing With Geometry (几何 离散化 )
pro:给定规则的多边形,规则是指顶点都在整点上,而且是相互垂直的边的交点. 现在给定两个多边形A,B,问A,B缩小,旋转后是否可以变为同一个图形. sol:缩小的话,直接离散化即可,就可以去掉没用的 ...
- gym 100531 三维几何+搜索
精度有点毒, 其实可以不用double, 因为A, B必定在其中一个在三角形上,可以投影到只有x,y轴的地方叉积比较. #include<bits/stdc++.h> #define LL ...
- D - Keiichi Tsuchiya the Drift King Gym - 102028D (几何)
题目链接:https://cn.vjudge.net/contest/275150#problem/D 题目大意: 问你能满足那个矩形可以顺利通过的条件,然后求出最小的w 具体思路:首先,我们应该将情 ...
- Gym - 101673:B Craters (几何,求凸包)
题意:给定几个圆,求最短的围合,把这几个包围起来,而且到圆的距离都不小于10. 思路:把每个圆的半径+10,边等分5000份,然后求凸包即可. #include<bits/stdc++.h> ...
- Codeforce Gym 100015I Identity Checker 暴力
Identity Checker 题目连接: http://codeforces.com/gym/100015/attachments Description You likely have seen ...
随机推荐
- php(面向对象的基本介绍)
面向对象思想介绍 OOP:Object Oriented Program面向对象编程. 面向对象三大特性 封装 继承 多态 类与对象 类:是用于描述“某一些具有共同特征”的物体的概念,是某一类 ...
- 转 python测试框架最全资源汇总
转自: http://www.testclass.net/list/python_list_1/ xUnit frameworks(单元测试框架) frameworks 框架 unittest - p ...
- 使用 EF Core 的 EnableRetryOnFailure 解决短暂的数据库连接失败问题
阿里云服务器有时会出现短暂的连接不上数据库服务器(RDS)的问题,之前由于没有启用 Entity Framework Core 的失败重试功能(默认是禁用的),短暂的连接失败立马会引发下面的异常从而出 ...
- Web开发——JavaScript基础(JSON教程)
参考: JSON:JavaScript 对象表示法(JavaScript Object Notation). JSON 是存储和交换文本信息的语法.类似 XML. JSON 比 XML 更小.更快,更 ...
- 14.0-uC/OS-III挂起队列
1.当任务等待信号量. mutex.事件标志组.消息队列时,该任务会被放入挂起队列. 挂起队列是一个OS_PEND_LIST类型的数据结构,它包含了三部分内容. .NbrEntries 挂起队列中有几 ...
- 4、Flutter 采坑记录篇二_依赖库不兼容
1.报错信息 Because every version of flutter_test from sdk depends on package_resolver 1.0.4 which depend ...
- 加壳工具-Virbox Protector Standalone
深思数盾自动保护工具Virbox Protector Standalone,是深思数盾科技股份有限公司经过多年技术深耕开发的一款高强度自动保护(加密)工具. 该工具集混淆.虚拟化.外壳加密.数据加密于 ...
- react 中的return 什么时候用小括号,什么时候用大括号啊
return( <div>....</div> ) return( <Component/> ) return{...} 1:html 2:react 组件 3:j ...
- laravel框架基础(1)---入门与介绍
1.安装laravel5.7 (composer )2018-12-28 11:59:02 [作者:struggler] Php的版本要求:php>=7.1.3 打开php OpenSSL扩展 ...
- 前端学习历程--localstroge
一. localstorage的特性 1.需要ie8+ 2.浏览器中都会把localStorage的值类型限定为string类型,这个在对我们日常比较常见的JSON对象类型需要一些转换 3.local ...