Codeforces Round #331 (Div. 2)-Wilbur and Swimming Pool(模拟)
2015-11-16 09:16
302 查看
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.
这题注意一下2个点的情况是x,y都不能存在相等的就行了。。
AC代码:
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.
这题注意一下2个点的情况是x,y都不能存在相等的就行了。。
AC代码:
#include<iostream> #include<algorithm> #include<cstring> #include<string> #include<vector> #include<cstdio> #include<cmath> using namespace std; #define CRL(a) memset(a,0,sizeof(a)) typedef unsigned __int64 ll; #define T 10005 #define mod 1000000007 int main() { #ifdef zsc freopen("input.txt","r",stdin); #endif int n,m,k,i,j; int x[4],y[4]; while(~scanf("%d",&n)) { for(i=0;i<n;++i){ scanf("%d%d",&x[i],&y[i]); } if(n==1){ printf("-1\n"); } else if(n==3||n==4){ int tmpx,tmpy; for(i=0;i<n;++i){ for(j=0;j<n;++j){ if(j==i)continue; if(x[i]==x[j]){ tmpy = y[i]-y[j]; if(tmpy<0)tmpy=-tmpy; } if(y[i]==y[j]){ tmpx = x[i]-x[j]; if(tmpx<0)tmpx=-tmpx; } } } printf("%d\n",tmpy*tmpx); } else { if(x[0]==x[1]||y[0]==y[1]){ printf("-1\n");continue; } int tmpx = x[0]-x[1],tmpy=y[0]-y[1]; if(tmpx<0)tmpx=-tmpx; if(tmpy<0)tmpy=-tmpy; printf("%d\n",tmpy*tmpx); } } return 0; }
相关文章推荐
- Transformation 能将 Windows XP/Server 2003 操作系统,完美地模拟成 Windows Vista 的软件
- 用javascript和css模拟select的脚本
- PHP模拟asp.net的StringBuilder类实现方法
- javascript用层模拟可移动的小窗口
- 自编jQuery插件实现模拟alert和confirm
- PHP模拟asp中response类实现方法
- 模拟Spring的简单实现
- javascript 模拟点击广告
- JQuery中模拟image的ajaxPrefilter与ajaxTransport处理
- php实现模拟post请求用法实例
- JavaScript实现MIPS乘法模拟的方法
- 模拟xcopy的函数
- JS模拟实现Select效果代码
- php模拟服务器实现autoindex效果的方法
- C# SendInput 模拟鼠标操作的实现方法
- PHP模拟登陆163邮箱发邮件及获取通讯录列表的方法
- JS模拟并美化的表单控件完整实例
- php模拟登陆的实现方法分析
- php模拟用户自动在qq空间发表文章的方法
- php 模拟 asp.net webFrom 按钮提交事件实例