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. c#扩展方法的使用

    "扩展方法使您能够向现有类型"添加"方法,而无需创建新的派生类型.重新编译或以其他方式修改原始类型." 1.为什么会有扩展方法 你一定很疑问什么是扩展方法!什么 ...

  2. [Mean of range in array]

    Given an array of n integers and q queries. Write a program to print floor value of mean in range l  ...

  3. SpringMVC底层数据传输校验的方案

    团队的项目正常运行了很久,但近期偶尔会出现BUG.目前观察到的有两种场景:一是大批量提交业务请求,二是生成批量导出文件.出错后,再执行一次就又正常了. 经过跟踪日志,发现是在Server之间进行jso ...

  4. <!--[if lte IE 8][endif] ]-->IE下判断IE版本的语句

    <!--[if lte IE 6]> <![endif]--> IE6及其以下版本可见 <!--[if lte IE 7]> <![endif]--> ...

  5. Java基础之引用(String,char[],Integer)总结

    1.String的引用: 下列代码执行后的结果为: public class Test { public static void main(String[] args) { StringBuffer  ...

  6. 为什么说Python 是大数据全栈式开发语言

    欢迎大家访问我的个人网站<刘江的博客和教程>:www.liujiangblog.com 主要分享Python 及Django教程以及相关的博客 交流QQ群:453131687 原文链接 h ...

  7. haslayout知多少

    我们都知道浏览器有bug,而IE的bug似乎比大多数浏览器都多.IE的表现与其他浏览器不同的原因之一就是,显示引擎使用一个称为布局(layout)的内部概念.   因为布局是专门针对显示引擎内部工作方 ...

  8. DevOps/TestOps概念

    天下大势分久必合合久必分,早期的软件开发只有软件工程师一人完成,为了提高效率逐渐实行分工模式:开发.测试.运维.不同角色担任不同的任务.分工越来越细之后带来了问题也越来越突出,那就是各角色之间的沟通成 ...

  9. MSSQLSERVER并行度

    Microsoft SQL Server最大并行度(MAXDOP) 配置选项控制并行计划用于执行查询的处理器的数目.此选项确定用于执行工作并行查询计划运算符的计算和线程资源.根据是否 SQL Serv ...

  10. 解决 react-router / react-router-dom v4 history不能访问的问题

    今天我把react-router 升级了一下, 在使用react-router-dom 是,子组件使用this.props.history 找不到了,看看官方文档,找了半天也没找到,因为我是在异步执行 ...