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 ...
随机推荐
- border透明
最近在写一表项目,需要边框透明,起初我以为没有办法实现,最近看一本书中找到办法,就是通过rgba实现,代码如下: border: 1px solid rgba(0, 0, 0, 0.7); 关于rgb ...
- 项目管理及自动构建工具Maven
项目管理及自动构建工具Maven 一.Maven安装.目录结构.cmd命令1.下载安装apache-maven-3.2.3-bin.zip下载:http://maven.apache.org/down ...
- DouNet学习_收发邮件
一.收发邮件 --->第一步:发邮件首先要有发送者的邮箱地址和登录的密码才能发送 这些都写在APP里 不要写死 --->第二步:发邮件就要有网络,要添加net.Mail命名空间 要发送的 ...
- c 按范围快速指定整数
以前用过octave, 和matlab类似的软件, 指定范围非常方便 i = 1:10:100; 就可以得到 10 20 30 ... 100 这一系列的数据, 但是在c里面, 必须手动写循环, 太 ...
- c++ struct 使用
typedef与结构结合使用 typedef struct tagMyStruct{ int iNum; long lLength;} MyStruct; 这语句实际上完成两个操作: 1) 定义一 ...
- 深入理解PHP Opcode缓存原理
什么是opcode缓存? 当解释器完成对脚本代码的分析后,便将它们生成可以直接运行的中间代码,也称为操作码(Operate Code,opcode).Opcode cache的目地是避免重复编译,减少 ...
- Sharding & IDs at Instagram(转)
英文原文:http://instagram-engineering.tumblr.com/post/10853187575/sharding-ids-at-instagram 译文:http://ww ...
- ACM 中常用的算法有哪些? 2014-08-21 21:15 40人阅读 评论(0) 收藏
ACM 中常用的算法有哪些?作者: 张俊Michael 网络上流传的答案有很多,估计提问者也曾经去网上搜过.所以根据自己微薄的经验提点看法. 我ACM初期是训练编码能力,以水题为主(就是没有任何算法, ...
- python知识点 07-11
python引用变量的顺序: 当前作用域局部变量->外层作用域变量->当前模块中的全局变量->python内置变量 python的 nonlocal关键字用来在函数或其他作用域中使用 ...
- 关于iTunes11.1 不能刷自制固件的解决方案
由于iTunes升级到11.1后, 苹果在程序里限制了不允许刷自制固件, 所以想刷自制固件暂时只能降级iTunes到11.1版本之前, 这里提供iTunes 11.0.5 的下载地址: Windows ...