【打CF,学算法——一星级】CodeForces 617D Polyline(水题)
2016-07-08 19:36
381 查看
【CF简介】
提交链接:CF 617D
题面:
D. Polyline
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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.
Input
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.
Output
Print a single number — the minimum possible number of segments of the polyline.
Examples
Input
Output
Input
Output
Input
Output
Note
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:
题意:
给定三个点的位置,问最少需要几条线段,可以一笔画成。
解题:
1.三点一线,1条线段。
2.两点共线,另外一点在两点之间,2条线段。
3.两点共线,另外一点在两点之外,3条线段。
4.其他情况,3条线段。
提交链接:CF 617D
题面:
D. Polyline
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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.
Input
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.
Output
Print a single number — the minimum possible number of segments of the polyline.
Examples
Input
1 -1 1 1 1 2
Output
1
Input
-1 -1-1 34 3
Output
2
Input
1 12 33 2
Output
3
Note
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:
题意:
给定三个点的位置,问最少需要几条线段,可以一笔画成。
解题:
1.三点一线,1条线段。
2.两点共线,另外一点在两点之间,2条线段。
3.两点共线,另外一点在两点之外,3条线段。
4.其他情况,3条线段。
#include <iostream> #include <string> #include <cstdio> #define cal1(a,b,c) x[a]==x[b]&&(y[c]<min(y[a],y[b])||y[c]>max(y[a],y[b])) #define cal2(a,b,c) y[a]==y[b]&&(x[c]<min(x[a],x[b])||x[c]>max(x[a],x[b])) using namespace std; int main() { int x[3],y[3],a=0,b=0,ans; for(int i=0;i<3;i++) scanf("%d%d",&x[i],&y[i]); for(int i=0;i<2;i++) for(int j=i+1;j<3;j++) { if(x[i]==x[j]) a++; if(y[i]==y[j]) b++; } if(a==3||b==3) ans=1; else if(a==1&&b==1) ans=2; else if(a==1) { if(cal1(0,1,2)||cal1(0,2,1)||cal1(1,2,0)) ans=2; else ans=3; } else if(b==1) { if(cal2(0,1,2)||cal2(1,2,0)||cal2(0,2,1)) ans=2; else ans=3; } else ans=3; printf("%d\n",ans); return 0; }
相关文章推荐
- 自制 Python小工具 将markdown文件转换成Html文件
- 添加下拉刷新
- 【CF 609E】Street
- 自制 Python小工具 将markdown文件转换成Html文件
- hdu 2111 Saving HDU
- 组播Multicast 2 PIM
- 5-13 畅通工程之最低成本建设问题 (30分)(这个是补上去的7月5号)
- Android3D画廊总结整理
- linux学习记录———rsync
- BabeLua配置
- 垂直居中
- 即时作图新工具—ProcessOn【推荐】
- Mysql5.6 online ddl
- Quartz应用与集群原理分析
- 搭建Spring mvc环境
- 组播Multicast 1 overview
- 标杆
- 2016年上半年信息系统监理师考试感想
- QOS-7 总结及WAN链路有效性
- 根据两点经纬度计算两点距离...工具类