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 ...
随机推荐
- hbm.xml支持的类型
- JAVA 锁
JAVA 锁 锁的概念 Java中的锁是控制资源访问的一种方式.它弥补了synchronized的可操作性不强的不足. Java的锁都实现了Lock接口.Lock结构定义了锁的基本操作. 函数 解释 ...
- LR之性能分析基础
1.判断测试结果有效性 2.分析要点提示 3.Analysis主要提供的6大类分析图 4.分析流程
- 一个DataTable赋值给另一个DataTable的常用方法
DataView view = new DataView();view.Table = DataTableA;view.RowFilter = "itemType = 'book'" ...
- openGl从零开始之添加颜色
OpenGL 支持两种颜色模式:一种是 RGBA模式,一种是 颜色索引模式.无论哪种颜色模式,计算机都必须为每一个像素保存一些数据,即通过每一个像素的颜色,来改变整体图形的颜色.不同的是, RGBA ...
- 重新安装python
1. 在上次进行安装python的时候,很多东西不能用,例如后退键,删除键,都是不能在命令行中使用,主要原因是在编译python的时候,相关的安装包没有进行安装,从而导致出现乱码,在编译最新版本的py ...
- [转载]字典树(trie树)、后缀树
(1)字典树(Trie树) Trie是个简单但实用的数据结构,通常用于实现字典查询.我们做即时响应用户输入的AJAX搜索框时,就是Trie开始.本质上,Trie是一颗存储多个字符串的树.相邻节点间的边 ...
- Command Line Tools uninstall
sudo rm -rf /Library/Developer/CommandLineTools
- cookie一些简单的操作
cookie 保存数据 document.cookie=name+'='+value+';expires='+date; //name=shiyou ;expires=Tue Mar 08 ...
- Sharding & IDs at Instagram(转)
英文原文:http://instagram-engineering.tumblr.com/post/10853187575/sharding-ids-at-instagram 译文:http://ww ...