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#中MessageBox用法大全(附效果图)

    1.最简单的,只显示提示信息 2. 可以给消息框加上标题. 3. "确定"和"取消" 4. 给MessageBox加上一个Icon,.net提供常见的Icon共 ...

  2. 使用Libmicrohttpd搭建内嵌(本地)服务器

    Libmicrohttpd简介 GNU Libmicrohttpd是一个用来在项目中内嵌http服务器的C语言库,它具有以下几个非常鲜明的特点: C语言库,小而快. API非常简单,且都是可重入的. ...

  3. ArcGIS API for JavaScript 4.2学习笔记[25] 官方第八章Analysis(空间查询)概览与解释

    开森,最关注的空间分析章节终于到了,在空间查询那节逻辑性的代码简直要命(呵呵,空间分析的代码也要命...). 上目录截图: [Geodesic buffers(GeometryEngine)] 使用G ...

  4. 4、公司经营的业务来源 - CEO之公司管理经验谈

    公司经营的业务来源为公司的运作资金提供了帮助,一般来说,整个公司的领导层为公司的经营做管理,而业务员就为公司的业务提供来源,然后建设部为业务开展做建设. 一.总经理: 公司的总经理主要负责公司运作经营 ...

  5. DBCC page 数据页 堆 底层数据分布大小计算

    1.行的总大小: Row_Size = Fixed_Data_Size + Variable_Data_Size + Null_Bitmap + 4(4是指行标题开销) 开销定义: Fixed_Dat ...

  6. APP网络测试要点和弱网模拟

    当前APP网络环境比较复杂,网络制式有2G.3G.4G网络,还有越来越多的公共Wi-Fi.不同的网络环境和网络制式的差异,都会对用户使用app造成一定影响.另外,当前app使用场景多变,如进地铁.上公 ...

  7. 3.移植uboot-使板卡支持nor、nand

    在上一章,我们添加了nor,nand启动后,uboot启动出如下图所示: 上面的Flash: *** failed *** 是属于uboot第二阶段函数board_init_r()里的代码, 代码如下 ...

  8. Nginx集群之基于Redis的WebApi身份验证

    目录 1       大概思路... 1 2       Nginx集群之基于Redis的WebApi身份验证... 1 3       Redis数据库... 2 4       Visualbox ...

  9. JS输出26个英文大小写字母

    JS中可以利用ASCII值 for(var i=0;i<26;i++){ console.log(String.fromCharCode(65+i));//输出A-Z 26个大写字母 } for ...

  10. JS CKEditor使用setData后绑定click事件

    CKEditor使用setData()时会自动丢失初始时绑定的时间,在百度时发现有很多方法都不对. 近期在做项目的时候,由于客户需要,将原来的文本格式的textarea标签更改成富文本编辑器--CKE ...