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 ...
随机推荐
- ftp虚拟账号登陆
配置使用虚拟用户登录的FTP服务器,可以避免使用操作系统帐号作为FTP用户带来的一些安全问题,也便于通过数据库或其它程序来进行管理.废话不多说,这里记录下ftp虚拟账号登陆的部署过程及其中遇到的问题: ...
- C语言 文件操作5--文件的常用函数
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> //stdin:标准输入文件指针,系统 ...
- MVC出错案例之一:主外键映射失败
今天在编写DomainModel和DomainMapper,最后放到OnModelCreating中运行的时候,给我抛出了如下错误: One or more validation errors wer ...
- [CareerCup] 8.8 Othello Game 黑白棋游戏
8.8 Othello is played as follows: Each Othello piece is white on one side and black on the other. Wh ...
- LeetCode 笔记26 Single Number II
Given an array of integers, every element appears three times except for one. Find that single one. ...
- 实践2.4 ELF文件格式分析
实践2.4 ELF文件格式分析 1.ELF文件头 查看/usr/include/elf.h文件: #define EI_NIDENT (16) typedef struct { unsigned ch ...
- Linux及安全课程——相关链接总结
附录:学习笔记链接总结 MOOC课程学习笔记与实验: 第一周:计算机是如何工作的 第二周:操作系统是怎么工作的 -- 一个简单的时间片轮转多道程序内核代码及分析 第三周:构造一个简单的Linux系统M ...
- Sea.js & Require.js
Sea.js 追求简单.自然的代码书写和组织方式,具有以下核心特性: 简单友好的模块定义规范:Sea.js 遵循 CMD 规范,可以像 Node.js 一般书写模块代码. 自然直观的代码组织方式:依赖 ...
- EF实体框架之CodeFirst六
上午的时候把复杂类型学习了一下,想着趁着周六日把Code First学习完,所以下午还是把Code First中的关系学习下.在数据库中最重要的恐怕就是E-R图了,E-R体现了表与表直接的关系.使用C ...
- 使用Nginx解决IIS绑定域名导致应用程序重启的问题
在将多个站点迁移到一个站点(Tenant Feature)的时候碰到了一个棘手的问题,用户需要绑定自定义域名,但IIS绑定域名的时候会导致这个站点重启,那么只要一个用户绑定了一个域名则会导致这个应用上 ...