Codeforces Round #340 (Div. 2) D. Polyline 计算几何,折线
来源:互联网 发布:淘宝联盟登录不了 编辑:程序博客网 时间:2024/04/29 02:53
There are three points marked on the coordinate plane. The goal is to make a simple polyline, without self-intersections and self-touches, such that it passes through all these points. Also, the polyline must consist of only segments parallel to the coordinate axes. You are to find the minimum number of segments this polyline may consist of.
Each of the three lines of the input contains two integers. The i-th line contains integers xi and yi ( - 109 ≤ xi, yi ≤ 109) — the coordinates of the i-th point. It is guaranteed that all points are distinct.
Print a single number — the minimum possible number of segments of the polyline.
1 -11 11 2
1
-1 -1-1 34 3
2
1 12 33 2
3
The variant of the polyline in the first sample:The variant of the polyline in the second sample:The variant of the polyline in the third sample:
Source
Codeforces Round #340 (Div. 2)
My Solution
几何,折线
题意 给出3个点的坐标, 用折线把3个点连起来,要求每个线段 parallel to the coordinate axes(平行于坐标轴),然后线段没有交叉 和 self-touches(可能是说不能成环), 求出需要的最小的线段个数
所以, 如果(x1 == x2 && x2 == x3) || (y1 == y2 && y2 == y3) 则可以一条线段
如果 (x1 == x2) || (x2 == x3) || (x1 == x3) || (y1 == y2) || (y2 == y3) || (y1 == y3) 则有2个点的x相等或者y相等,
则 如果第三个点如果在外面, 如下
point · point ·
point3 · · · · · · · · · · · ······
则 答案为 2, 否则 对于这些第三个点在里面的情况 则答案为 3
point · point ·
point3 · · · · · · ·
如果是没有2个点的x相等或者y相等, 则 答案为 3#include <iostream>#include <cstdio>using namespace std;typedef long long LL;const int maxn = 1e6 + 8;int main(){ #ifdef LOCAL freopen("d.txt", "r", stdin); //freopen("o.txt", "w", stdout); int T = 3; while(T--){ #endif // LOCAL ios::sync_with_stdio(false); cin.tie(0); int x1, y1, x2, y2, x3, y3; cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3; if((x1 == x2 && x2 == x3) || (y1 == y2 && y2 == y3)){ cout << 1 << endl; } else if((x1 == x2) || (x2 == x3) || (x1 == x3) || (y1 == y2) || (y2 == y3) || (y1 == y3)){ if(x1 == x2){ if(y3 >= max(y1, y2) || y3 <= min(y1, y2)) cout << 2 << endl; else cout << 3 << endl; } else if(x2 == x3){ if(y1 >= max(y3, y2) || y1 <= min(y3, y2)) cout << 2 << endl; else cout << 3 << endl; } else if(x1 == x3){ if(y2 >= max(y1, y3) || y2 <= min(y1, y3)) cout << 2 << endl; else cout << 3 << endl; } else if(y1 == y2){ if(x3 >= max(x1, x2) || x3 <= min(x1, x2)) cout << 2 << endl; else cout << 3 << endl; } else if(y2 == y3){ if(x1 >= max(x3, x2) || x1 <= min(x3, x2)) cout << 2 << endl; else cout << 3 << endl; } else if(y1 == y3){ if(x2 >= max(x1, x3) || x2 <= min(x1, x3)) cout << 2 << endl; else cout << 3 << endl; } } else{ cout << 3 << endl; } #ifdef LOCAL cout<<endl; } #endif // LOCAL return 0;}
Thank you!
------from ProLights
- Codeforces Round #340 (Div. 2) D. Polyline 计算几何,折线
- Codeforces Round #340 (Div. 2) D. Polyline
- Codeforces Round #340 (Div. 2)D. Polyline
- Codeforces Round #340 (Div. 2)-D. Polyline
- Codeforces 617D Polyline (Round #340 (Div. 2) D题)
- Codeforces Round #340 (Div. 2) D. Polyline(规律)
- Codeforces Round #340 (Div. 2) 617D Polyline(暴力)
- Codeforces Round #340 (Div. 2) D. Polyline (点之间关系)
- Codeforces Round #346 (Div. 2)(D)计算几何
- Codeforces Round #340D - Polyline-水
- Codeforces Round #409Div.2D. Volatile Kite(计算几何)
- Codeforces Round #409 (Div. 2) D. Volatile Kite 计算几何、凸多边形、线段类
- 【Codeforces Round 340 (Div 2)D】【讨论题】Polyline 三点用最少数量连续不分叉线段连接
- Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2) D (简单计算几何)
- 【计算几何】Codeforces Round #113 (Div. 2)-B. Polygons
- Codeforces Round #357 (Div. 2) E 计算几何
- Codeforces Round #365 (Div. 2) C 计算几何
- Educational Codeforces Round 11 D 计算几何
- c++primer笔记--2.4const限定符
- Android开发中Handler的经典总结
- 文章标题
- c++primer笔记--2.5处理类型
- Android Multimedia框架总结(三)MediaPlayer中创建到setDataSource过程
- Codeforces Round #340 (Div. 2) D. Polyline 计算几何,折线
- c++primer笔记--2.6自定义数据类型
- Django models.py编辑后更新
- 浅谈设计模式之简单工厂模式与策略模式
- 113. Path Sum II
- Leetcode 180. Consecutive Numbers
- Leetcode 181. Employees Earning More Than Their Managers
- 简单博弈 nyoj 取球游戏
- SSH中根据按钮value传递参数