Codeforces D Polyline
来源:互联网 发布:史丹利快报的淘宝店 编辑:程序博客网 时间:2024/03/29 18:03
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:
恩,开始以为有4的情况呢,后来仔细想了一下是木有的。
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<stack>#include<queue>using namespace std;struct Node{ int x,y;};Node node[3];bool cmp(Node a,Node b){ if(a.x!=b.x) return a.x<b.x; return a.y<b.y;}int main(){ int x1,y1,x2,y2,x3,y3; while(~scanf("%d%d%d%d%d%d",&node[0].x,&node[0].y,&node[1].x,&node[1].y,&node[2].x,&node[2].y)) { int sum; //sort(node,node+3,cmp); x1=node[0].x; y1=node[0].y; x2=node[1].x; y2=node[1].y; x3=node[2].x; y3=node[2].y; if((x1==x2&&x2==x3)||(y1==y2&&y2==y3)) sum=1; else if(x1==x2&&(y3>=max(y1,y2)||y3<=min(y1,y2))) sum=2; else if(x2==x3&&(y1>=max(y2,y3)||y1<=min(y2,y3))) sum=2; else if(x1==x3&&(y2>=max(y1,y3)||y2<=min(y1,y3))) sum=2; else if(y1==y2&&(x3>=max(x1,x2)||x3<=min(x1,x2))) sum=2; else if(y2==y3&&(x1>=max(x2,x3)||x1<=min(x2,x3))) sum=2; else if(y1==y3&&(x2>=max(x1,x3)||x2<=min(x1,x3))) sum=2; else sum=3; //printf("x1=%d y1=%d x2=%d y2=%d x3=%d y3=%d\n",x1,y1,x2,y2,x3,y3); /*if((x1==x2&&x2==x3)||(y1==y2&&y2==y3)) sum=1; else if(x1==x2&&(y3>=max(y1,y2)||y3<=min(y1,y2))) sum=2; else if(x2==x3&&(y1>=max(y2,y3)||y1<=min(y2,y3))) sum=2; else if(y1==y2&&(x3>=max(x1,x2)||x3<=min(x1,x2))) sum=2; else if(y2==y3&&(x1>=max(x2,x3)||x1<=min(x2,x3))) sum=2; else if(y1==y3&&(x2>=max(x1,x3)||x2<=min(x1,x3))) sum=2; else sum=3;*/ printf("%d\n",sum); } return 0;}
- Codeforces D Polyline
- Codeforces 617D Polyline 【枚举】
- Codeforces Round #340D - Polyline-水
- Codeforces Round #340 (Div. 2) D. Polyline
- CodeForces 617 D. Polyline(水~)
- Codeforces Round #340 (Div. 2)D. Polyline
- Codeforces 617D 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 #340 (Div. 2) D. Polyline 计算几何,折线
- 【打CF,学算法——一星级】CodeForces 617D Polyline(水题)
- 【Codeforces Round 340 (Div 2)D】【讨论题】Polyline 三点用最少数量连续不分叉线段连接
- codeforces 452B 4-point polyline
- Codeforces 452B 4-point polyline (暴力出奇迹)
- Codeforces Round #320 (Div. 2)C. A Problem about Polyline
- Codeforces 617C Watering Flowers 【暴力 数据范围】
- Java 包
- c中定义变量的内存分配顺序问题(极易错!!!)
- Codeforces 617A Elephant
- Codeforces 617B Chocolate
- Codeforces D Polyline
- C++链表
- HDOJ 5611 Baby Ming and phone number
- 咱码农为啥会(珍爱生命)远离企业应用开发
- HDOJ 5610 Baby Ming and Weight lifting
- UVa 489 Hangman Judge
- 领导喜欢什么样的人
- 前些日子读了《杜拉拉升职记》
- Leetcode - 261. Graph Valid Tree