软件世界网 购物 网址 三丰软件 | 小说 美女秀 图库大全 游戏 笑话 | 下载 开发知识库 新闻 开发 图片素材
多播视频美女直播
↓电视,电影,美女直播,迅雷资源↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
移动开发 架构设计 编程语言 Web前端 互联网
开发杂谈 系统运维 研发管理 数据库 云计算 Android开发资料
  软件世界网 -> 编程语言 -> CodeforcesRound#346(Div.2) -> 正文阅读

[编程语言]CodeforcesRound#346(Div.2)


D. Bicycle Race
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Maria participates in a bicycle race.
The speedway takes place on the shores of Lake Lucerne, just repeating its contour. As you know, the lake shore consists only of straight sections, directed to the north, south, east or west.
Let's introduce a system of coordinates, directing the Ox axis from west to east, and the Oy axis from south to north. As a starting position of the race the southernmost point of the track is selected (and if there are several such points, the most western among them). The participants start the race, moving to the north. At all straight sections of the track, the participants travel in one of the four directions (north, south, east or west) and change the direction of movement only in bends between the straight sections. The participants, of course, never turn back, that is, they do not change the direction of movement from north to south or from east to west (or vice versa).
Maria is still young, so she does not feel confident at some turns. Namely, Maria feels insecure if at a failed or untimely turn, she gets into the water. In other words, Maria considers the turn dangerous if she immediately gets into the water if it is ignored.
Help Maria get ready for the competition — determine the number of dangerous turns on the track.
Input
The first line of the input contains an integer n (4?≤?n?≤?1000) — the number of straight sections of the track.
The following (n?+?1)-th line contains pairs of integers (xi,?yi) (?-?10?000?≤?xi,?yi?≤?10?000). The first of these points is the starting position. The i-th straight section of the track begins at the point (xi,?yi) and ends at the point (xi?+?1,?yi?+?1).
It is guaranteed that:
  • the first straight section is directed to the north;
  • the southernmost (and if there are several, then the most western of among them) point of the track is the first point;
  • the last point coincides with the first one (i.e., the start position);
  • any pair of straight sections of the track has no shared points (except for the neighboring ones, they share exactly one point);
  • no pair of points (except for the first and last one) is the same;
  • no two adjacent straight sections are directed in the same direction or in opposite directions.

Output
Print a single integer — the number of dangerous turns on the track.
Examples
Input
6
0 0
0 1
1 1
1 2
2 2
2 0
0 0

Output
1

Input
16
1 1
1 5
3 5
3 7
2 7
2 9
6 9
6 7
5 7
5 3
4 3
4 4
3 4
3 2
5 2
5 1
1 1

Output
6

Note
The first sample corresponds to the picture:
[img]http://codeforces.com/predownloaded/9a/1c/9a1c7b0e5fc0dd840fc91bbc2450e00e2f607a07.png
The picture shows that you can get in the water under unfortunate circumstances only at turn at the point (1,?1). Thus, the answer is 1.


题意:给出一个多边形的所有点坐标(按顺序给),某人求顺时针走一圈有多少条边使他走进多边形内。
分析:叉积轻松搞定,水~


<span style="font-size:18px;">#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
const double eps = 1e-6;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int MOD = 1000000007;
#define ll long long
#define CL(a,b) memset(a,b,sizeof(a))
#define lson (i<<1)
#define rson ((i<<1)|1)
#define MAXN 100010

struct node
{
    int x,y;
}s[1010];

int chaji(node A, node B, node C)
{
    return (A.x-B.x)*(C.y-B.y)-(C.x-B.x)*(A.y-B.y);
}

int main()
{
    int n;
    while(scanf("%d",&n)==1)
    {
        for(int i=0; i<=n; i++)
            cin>>s[i].x>>s[i].y;
        s[n+1].x = s[1].x;
        s[n+1].y = s[1].y;
        int ans = 0;
        for(int i=1; i<=n; i++)
        {
            if(chaji(s[i-1], s[i], s[i+1]) < 0)
                ans++;
        }
        cout<<ans<<endl;
    }
    return 0;
}
</span>


......显示全文...
    点击查看全文


上一篇文章      下一篇文章      查看所有文章
2016-04-03 20:43:25  
编程语言 最新文章
Java面试题(1)
ReactiveX序列——RxSwift
C++STL之ACM相关知识大全
c++中vector向量几种情况的总结(向量指针,
SSH框架整合demo
JAX
UVA
curl备忘(1)
C#机房重构——万事开头难(二)
OJ刷题
360图书馆 论文大全 母婴/育儿 软件开发资料 网页快照 文字转语音 购物精选 软件 美食菜谱 新闻中心 电影下载 小游戏 Chinese Culture
生肖星座解梦 人民的名义 人民的名义在线看 三沣玩客 拍拍 视频 开发 Android开发 站长 古典小说 网文精选 搜图网 天下美图
中国文化英文 多播视频 装修知识库
2017-7-22 4:51:01
多播视频美女直播
↓电视,电影,美女直播,迅雷资源↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  软件世界网 --