Codeforces Round #331 (Div. 2) _A. Wilbur and Swimming Pool
2015-11-16 13:20
465 查看
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
output
input
output
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.
水题、但是窝过的也很水、想复杂了、题目意思是一个矩形抹去了若干点、前提是这本身就是个矩形,可是窝刚理解为任意四点、、、题意啊!写的还那么复杂、、渣
一下附上经典代码吧、
多想多思考、看到题目不能脑海里浮现出思路就开始码代码,还要思考一下自己的想法是最优的或者可行与否、是否还存在更优的求解方案!??这样才会避免过多的wa!都这么长时间了还停留在div2的AB上也的确要反洗自己了、、、、
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
11 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上也的确要反洗自己了、、、、
相关文章推荐
- 简单易做,朴实好吃——小在在家的200个家常菜
- php session 登录退出验证
- hive大数据倾斜总结
- 弧度与角度的转化公式
- Linux 偏门接口速记
- Vmware + Bridge
- jenkins发布项目到远程主机上,配置两台linux如何使用SSH免密码登录
- user-agent解析工具
- U盘使用MBR分区安装win8/8.1/10
- django 带表名的查询
- 安卓、苹果日历同步
- Java内存
- 安卓、苹果手机备忘录同步
- 友盟统计平台
- Windows 10操作系统非常垃圾的一个设计,居然还没有改过来???难怪黑客总能找到一堆安全漏洞
- WebViewJavascriptBridge使用
- hive数据倾斜的解决方案【常见】
- 博客迁移
- 今天是我的生日,祝我生日快乐!~~
- 一直在用的HashMap