Codeforce#331 (Div. 2) A. Wilbur and Swimming Pool(谨以此题来纪念我的愚蠢)
1 second
256 megabytes
standard input
standard output
After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of the rectangle must be positive. Wilbur had all four vertices of the planned pool written on a paper, until his friend came along and erased some of the vertices.
Now Wilbur is wondering, if the remaining n vertices of the initial rectangle give enough information to restore the area of the planned swimming pool.
The first line of the input contains a single integer n (1 ≤ n ≤ 4) — the number of vertices that were not erased by Wilbur's friend.
Each of the following n lines contains two integers xi and yi ( - 1000 ≤ xi, yi ≤ 1000) —the coordinates of the i-th vertex that remains. Vertices are given in an arbitrary order.
It's guaranteed that these points are distinct vertices of some rectangle, that has positive area and which sides are parallel to the coordinate axes.
Print the area of the initial rectangle if it could be uniquely determined by the points remaining. Otherwise, print - 1.
2
0 0
1 1
1
1
1 1
-1
In the first sample, two opposite corners of the initial rectangle are given, and that gives enough information to say that the rectangle is actually a unit square.
In the second sample there is only one vertex left and this is definitely not enough to uniquely define the area.
题意:输入若干个点判断能否确定一个矩形的面积,矩形平行于坐标轴
开始正常写,提交WA,然后改,始终没能找到错误。最后才发现自己思维太不严谨了
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
int flag,n;
struct node
{
int x,y;
};
node a[];
int main()
{
while(scanf("%d", &n) != EOF)
{
flag = ;
int s;
for(int i = ; i < n; i++)
scanf("%d%d", &a[i].x, &a[i].y);
if(n < )
flag = ;
else
{
if(n == )
{
if(a[].x == a[].x || a[].y == a[].y)
{
flag = ;
}
else
{
s = abs(a[].x - a[].x) * abs(a[].y - a[].y);
}
}
else
{
if ((a[].x == a[].x || a[].y == a[].y) && (a[].x == a[].x || a[].y == a[].y) ) //就是落了这个判断条件。。。。。。
s = abs(a[].x - a[].x) * abs(a[].y - a[].y);
else
for(int i = ; i < n; i++)
{
if(a[].x == a[i].x || a[].y == a[i].y)
continue;
else
s = abs(a[].x - a[i].x) * abs(a[].y - a[i].y);
}
}
}
if(flag)
printf("-1\n");
else
printf("%d\n",s);
}
return ;
}
Codeforce#331 (Div. 2) A. Wilbur and Swimming Pool(谨以此题来纪念我的愚蠢)的更多相关文章
- Codeforces Round #331 (Div. 2) A. Wilbur and Swimming Pool 水题
		
A. Wilbur and Swimming Pool Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/conte ...
 - Codeforces Round #331 (Div. 2) _A. Wilbur and Swimming Pool
		
A. Wilbur and Swimming Pool time limit per test 1 second memory limit per test 256 megabytes input s ...
 - Codeforces Round #331 (Div. 2) C. Wilbur and Points
		
C. Wilbur and Points time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
 - Codeforces Round #331 (Div. 2) E. Wilbur and Strings dfs乱搞
		
E. Wilbur and Strings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/596 ...
 - Codeforces Round #331 (Div. 2) D. Wilbur and Trees 记忆化搜索
		
D. Wilbur and Trees Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/596/p ...
 - Codeforces Round #331 (Div. 2)C. Wilbur and Points 贪心
		
C. Wilbur and Points Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/596/ ...
 - Codeforces Round #331 (Div. 2) B. Wilbur and Array 水题
		
B. Wilbur and Array Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/596/p ...
 - Codeforces Round #331 (Div. 2) B. Wilbur and Array
		
B. Wilbur and Array time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
 - CodeForces 596A Wilbur and Swimming Pool
		
水题. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> u ...
 
随机推荐
- Android开发EditText属性
			
Android开发EditText属性 EditText继承关系:View-->TextView-->EditText EditText的属性很多,这里介绍几个:android:hint= ...
 - 14Spring_AOP编程(AspectJ)_环绕通知
			
在目标方法执行前后,进行代码增强 (阻止目标方法的执行 ) 环绕通知实现任何通知效果. 案例如下: 案例结构:
 - [2]Telerik Extensions for ASP.NET MVC 中文教程(2)
			
上一篇文章对Telerik MVC Extensions作了一个大概的介绍,这篇文章将介绍如何将Telerik MVC Extensions添加到项目中.有以下两种方式可以将Telerik MVC E ...
 - Performance Counter的使用——获取各类组件性能,获取CPU参数等
			
一 PerformanceCounter 基本介绍1 简单介绍表示 Windows NT 性能计数器组件 命名空间:System.Diagnostics程序集:System(在 system.dll ...
 - memcached协议
			
memcached协议 旧版:http://code.sixapart.com/svn/memcached/trunk/server/doc/protocol.txt 新版:https://githu ...
 - 网页音乐突破金币(RMB)下载限制
			
我平时有时间会跳跳舞 跳舞肯定要有音乐呀 于是在网上找音乐 好不容易找到了一个网站,里面有很多很全的音乐 正准备下载呢,尼玛居然要金币! 在这里解释一下,金币你可以通过回复帖子或者发帖子得到,但是数量 ...
 - 运用Java对微信公众平台二次开发技术——开发者模式接入
			
当初我在这碰到了很多问题,市面上以及网络上的资料特别少,所以当初碰了很多壁,所以现在跟大家分享一下,如何用Java,对微信公众平台进行二次开发. 一.开发预备知识: 最基本的JavaSE与JavaWe ...
 - 远程办公《Remote》读书笔记:中国程序员在家上班月入过六万不是梦
			
这不是一本新书,这是一本很值得中国程序员看的老书,所以我不是来做卖新书广告的:) 但它的确是一本好书,这本书在Amazon上3个business categories排第一.作者Jason Fried ...
 - 内置模块加载器(commonjs规范)的使用
			
index9.html <html><head> <title>模块加载器</title> <script src="jquery-1. ...
 - web前端开发教程系列-1 - 前端开发编辑器介绍
			
目录: 前言 一. Webstorm 1. 优点 2. 缺点 3. 教程 4. 插件 5. 技巧 二. SublimeText 1. 优点 2. 缺点 3. 教程 4. 插件 5. 技巧 前言 由于很 ...