A. Wilbur and Swimming Pool
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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.

Output

Print the area of the initial rectangle if it could be uniquely determined by the points remaining. Otherwise, print  - 1.

Sample test(s)
input
2
0 0
1 1
output
1
input
1
1 1
output
-1
Note

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.

水题、但是窝过的也很水、想复杂了、题目意思是一个矩形抹去了若干点、前提是这本身就是个矩形,可是窝刚理解为任意四点、、、题意啊!写的还那么复杂、、渣

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std; struct node {
int x, y;
}a[4]; int mianJi(int a1, int b1, int a2, int b2) {
return abs(a1-a2) * abs(b1-b2);
} int main() {
int n;
memset(a, 0, sizeof(a)); cin >> n;
for (int i = 0; i<n; i++)
cin >> a[i].x >> a[i].y;
if (n == 1)
cout << -1 << endl;
else {
if (n == 2) {
if (a[0].x != a[1].x && a[0].y != a[1].y)
cout <<mianJi(a[0].x, a[0].y, a[1].x, a[1].y)<< endl;
else
cout << -1 << endl;
}
else if (n == 3) {
int flag1 = 0;
int flag2 = 0;
for (int i = 0; i<3; i++) {
for (int j = i+1; j<3; j++) {
if (a[i].x == a[j].x)
flag1 = 1;
if (a[i].y == a[j].y)
flag2 = 1;
}
}
if (flag1 && flag2) {
for (int i = 0; i<3; i++) {
for (int j = i+1; j<3; j++) {
if (a[i].x != a[j].x && a[i].y != a[j].y)
cout << mianJi(a[i].x, a[i].y, a[j].x, a[j].y) << endl;
}
}
}
else
cout << -1 << endl;
}
else {
int flag3 = 0;
int flag4 = 0;
for (int i = 0; i<4; i++) {
for (int j = i+1; j<4; j++) {
if (a[i].x == a[j].x)
flag3 ++ ;
if (a[i].y == a[j].y)
flag4 ++ ;
}
}
if (flag3 == 2 && flag4 == 2) {
for (int i = 0; i<3; i++) {
for (int j = i+1; j<3; j++) {
if (a[i].x != a[j].x && a[i].y != a[j].y)
cout << mianJi(a[i].x, a[i].y, a[j].x, a[j].y) << endl;
}
}
}
else
cout << -1 << endl;
}
}
return 0;
}

一下附上经典代码吧、

#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std; int main()
{
int n;cin>>n;
int minx,maxx,miny,maxy;
cin>>minx>>miny;
maxx=minx,maxy=miny;
if(n==1)return puts("-1");
for(int i=1;i<n;i++)
{
int x,y;cin>>x>>y;
minx=min(minx,x);
maxx=max(maxx,x);
miny=min(miny,y);
maxy=max(maxy,y);
}
if((maxx==minx)||(maxy==miny))
return puts("-1");
printf("%d\n",(maxx-minx)*(maxy-miny));
}

多想多思考、看到题目不能脑海里浮现出思路就开始码代码,还要思考一下自己的想法是最优的或者可行与否、是否还存在更优的求解方案!??这样才会避免过多的wa!都这么长时间了还停留在div2的AB上也的确要反洗自己了、、、、

Codeforces Round #331 (Div. 2) _A. Wilbur and Swimming Pool的更多相关文章

  1. 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 ...

  2. Codeforce#331 (Div. 2) A. Wilbur and Swimming Pool(谨以此题来纪念我的愚蠢)

    C time limit per test 1 second memory limit per test 256 megabytes input standard input output stand ...

  3. 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 ...

  4. 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 ...

  5. 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/ ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. Codeforces Round #331 (Div. 2)

    水 A - Wilbur and Swimming Pool 自从打完北京区域赛,对矩形有种莫名的恐惧.. #include <bits/stdc++.h> using namespace ...

随机推荐

  1. iOS知识点、面试题 之二

    最近面试,与大家分享一下,分三文给大家: 当然Xcode新版本区别,以及iOS新特性 Xcode8 和iOS 10 在之前文章有发过,感兴趣的可以查阅: http://www.cnblogs.com/ ...

  2. 【Uva10559】Blocks(区间DP)

    Description 题意:有一排数量为N的方块,每次可以把连续的相同颜色的区间消除,得到分数为区间长度的平方,然后左右两边连在一起,问最大分数为多少. \(1\leq N\leq200\) Sol ...

  3. 使用CSS画图之三角形(一)

    简单的画一个三角形,代码如下: <!DOCTYPE html> <html lang="en"> <head> <meta charset ...

  4. prototype为对象添加属性和方法

    可以通过prototype来为已经定义好的的"类"添加属性和方法.这里来了解一下prototype的基础知识.prototype是"构造函数"的属性,不是实例的 ...

  5. Linux整合Apache和SVN

    1.安装APR-1.2.7和APR-util-1.2.7  (下载地址:http://apr.apache.org/) #tar zxvf  apr-1.2.7.tar.gz #cd   apr-1. ...

  6. 7、正确的赚钱方式 - CEO之公司管理经验谈

    创业者创办公司,最初的目的就是为了赚钱,而普通的员工来公司上班,为了生计,也是以赚钱为目的.今天我们就讲讲正确的赚钱方式. 一.去公司上班: 来公司上班是第一个主要的赚钱方式.不管是员工还是公司领导, ...

  7. Linux入门篇(一)——基本命令

    这一系列的Linux入门都是本人在<鸟哥的Linux私房菜>的基础上总结的基本内容,主要是记录下自己的学习过程,也方便大家简要的了解 Linux Distribution是Ubuntu而不 ...

  8. Java的按位操作符

    本文参考:Java的位操作符 Java的位操作符用来操作整数基本数据类型中的单个"比特"(bit),即代进制位.而我们知道比特就是0和1,那么,位操作就是对这些数据进行基本的操作. ...

  9. Python核心编程笔记--动态属性

    一.动态语言与静态语言 1.1 静态语言特点: a. 在定义变量时需要指定变量的类型,根据指定的类型来确定变量所占的内存空间 b. 需要经过编译才能运行 c. 在代码编译后,运行过程不能对代码进行操作 ...

  10. iOS获取各种数据方法整理以及IDFA与IDFV使用环境

    iOS获取APP版本号: NSString *AppVersion  =  [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBun ...