Codeforces Round #340 (Div. 2) D. Polyline 水题
D. Polyline
题目连接:
http://www.codeforces.com/contest/617/problem/D
Descriptionww.co
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.
Sample Input
-1 -1
-1 3
4 3
Sample Output
2
Hint
题意
给你3个点,然后问你能够用多少条平行于坐标轴的线段来穿过这三个点
这些线段是连接在一起的,并且只能在端点处相交
题解:
显然答案只会有1 2 3 这三种
答案为1的,就是这三个点某一维是一样的
答案为2的,就是这三个点有两个点的某一维是相同的,而另外一个点的另外一维是在这个点之外(画个图就懂了
剩下的就是答案为3的
数据:
1 1
1 3
0 2
代码
#include<bits/stdc++.h>
using namespace std;
pair<int,int> P[3];
int check(int x,int y,int z)
{
if(x==y)return 0;
if(y==z)return 0;
if(x==z)return 0;
if(P[x].first==P[y].first)
{
if(P[x].second<P[y].second)
{
if(P[z].second<=P[x].second||P[z].second>=P[y].second)
return 1;
}
}
if(P[x].second==P[y].second)
{
if(P[x].first<P[y].first)
{
if(P[z].first<=P[x].first||P[z].first>=P[y].first)
return 1;
}
}
return 0;
}
int main()
{
for(int i=0;i<3;i++)
cin>>P[i].first>>P[i].second;
if(P[0].first == P[1].first && P[1].first == P[2].first)
return puts("1");
if(P[0].second == P[1].second && P[1].second == P[2].second)
return puts("1");
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
for(int k=0;k<3;k++)
if(check(i,j,k))
return puts("2");
return puts("3");
}
Codeforces Round #340 (Div. 2) D. Polyline 水题的更多相关文章
- Codeforces Round #340 (Div. 2) B. Chocolate 水题
B. Chocolate 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co Bob loves everyt ...
- Codeforces Round #340 (Div. 2) A. Elephant 水题
A. Elephant 题目连接: http://www.codeforces.com/contest/617/problem/A Descriptionww.co An elephant decid ...
- Codeforces Round #185 (Div. 2) B. Archer 水题
B. Archer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/312/problem/B D ...
- Codeforces Round #360 (Div. 2) A. Opponents 水题
A. Opponents 题目连接: http://www.codeforces.com/contest/688/problem/A Description Arya has n opponents ...
- Codeforces Round #190 (Div. 2) 水果俩水题
后天考试,今天做题,我真佩服自己... 这次又只A俩水题... orz各路神犇... 话说这次模拟题挺多... 半个多小时把前面俩水题做完,然后卡C,和往常一样,题目看懂做不出来... A: 算是模拟 ...
- Codeforces Round #256 (Div. 2/A)/Codeforces448A_Rewards(水题)解题报告
对于这道水题本人觉得应该应用贪心算法来解这道题: 下面就贴出本人的代码吧: #include<cstdio> #include<iostream> using namespac ...
- Codeforces Round #338 (Div. 2) A. Bulbs 水题
A. Bulbs 题目连接: http://www.codeforces.com/contest/615/problem/A Description Vasya wants to turn on Ch ...
- Codeforces Round #282 (Div. 1) A. Treasure 水题
A. Treasure Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/494/problem/A ...
- Codeforces Round #327 (Div. 2) B. Rebranding 水题
B. Rebranding Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/problem ...
随机推荐
- 使用Ajax在javascript中调用后台C#函数
使用Ajax在javascript中调用后台C#函数 最近一段时间在紧跟一个网站的项目,数据库中用户表的UserName要求是唯一的,所以当用户选定一个用户名进行注册时要首先检查该用户名是否已被占用, ...
- ansible服务模块和组模块使用
本篇文章主要是介绍ansible服务模块和组模块的使用. 主要模块为ansible service module和ansible group moudle,下面的内容均是通过实践得到,可以直接运行相关 ...
- 笔记:C语言数据类型在32位与64位机器上的字节数
读<深入理解计算机系统> 第二章 信息的表示与处理 32位与64位的典型值,单位字节 声明 32位机器 64位机器 char 1 1 short int int 4 4 long int ...
- C++ 容器一些细节
今天学习是看到了讲解C++容器的一些细节用法,故记之!参考:http://www.cnblogs.com/answeryi/archive/2011/12/16/2289811.html: 目录 == ...
- sql统计重复数据
sql代码如下: 统计重复的数据 select MingCheng from tabShouFeiGongShi group by MingCheng having count(MingCheng) ...
- MapReduce阅读
1.mongodb权威指南6.4章 2.百科:http://baike.baidu.com/link?url=fl9FwgNq7gtFLwJ-GuKsJ25Uk-wnhgDjEwkKd8-5hoIkh ...
- LCA of a Binary Tree
236. Lowest Common Ancestor of a Binary Tree /** * 基础版 * 给定p,q都是在树中 * 有两种情况: * 1. p和q分布在LCA的两侧 * 2. ...
- 解决SQL Server Always 日志增大的问题-摘自网络
配置了Alwayson之后,因为没有只能使用完全恢复模式,不能使用简单或大容量日志模式,所以日志不断增长,不能使用改变恢复模式的方式清空日志 手动操作收缩或截断日志也无效 读了一些文章后发现,有人使用 ...
- jxse2.6在jdk8下,JxtaMulticastSocket存在的问题
JxtaMulticastSocket覆写了java.net.MulticastSocket的bind方法: @Override public void bind(SocketAddress addr ...
- (翻译)异步编程之Promise(1):初见魅力
原文:https://www.promisejs.org/ by Forbes Lindesay 异步编程系列教程: (翻译)异步编程之Promise(1)--初见魅力 异步编程之Promise(2) ...