CF459A Pashmak and Garden (水
Codeforces Round #261 (Div. 2)
|
A. Pashmak and Garden
time limit per test
1 second memory limit per test
256 megabytes input
standard input output
standard output Pashmak has fallen in love with an attractive girl called Parmida since one year ago... Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones. Input
The first line contains four space-separated x1, y1, x2, y2 ( - 100 ≤ x1, y1, x2, y2 ≤ 100) integers, where x1 and y1 are coordinates of the first tree and x2 and y2 are coordinates of the second tree. It's guaranteed that the given points are distinct. Output
If there is no solution to the problem, print -1. Otherwise print four space-separated integers x3, y3, x4, y4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them. Note that x3, y3, x4, y4 must be in the range ( - 1000 ≤ x3, y3, x4, y4 ≤ 1000). Sample test(s)
Input
0 0 0 1 Output
1 0 1 1 Input
0 0 1 1 Output
0 1 1 0 Input
0 0 1 2 Output
-1 |
题意:已知正方形的2个顶点的位置,求另外两个顶点的位置。(多解随意输出其中一种)
题解:认真考虑各种情况就好了。
主要看x差值和y差值,设dx=abs(x0-x1),dy=abs(y1-y0),考虑:
1.dx=dy=0的情况,不能成正方形。
2.dx=0,dy!=0的情况,怒成正方形,另外两个顶点就是把x移动dy就行。
3.dx!=0,dy=0,和2差不多。
3.dx!=0,dy!=0的情况,若dx!=dy则成不了正方形,若=,则可以成,另外两个点是(x1,y0) (x0,y1)
//#pragma comment(linker, "/STACK:102400000,102400000")
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
using namespace std;
#define ll long long
#define usll unsigned ll
#define mz(array) memset(array, 0, sizeof(array))
#define minf(array) memset(array, 0x3f, sizeof(array))
#define REP(i,n) for(i=0;i<(n);i++)
#define FOR(i,x,n) for(i=(x);i<=(n);i++)
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define WN(x) prllf("%d\n",x);
#define RE freopen("D.in","r",stdin)
#define WE freopen("1biao.out","w",stdout)
#define mp make_pair int a[],b[]; bool farm(){
if(a[]-a[]==){
if(b[]-b[]==)return ;
a[]=a[]+b[]-b[];
a[]=a[];
b[]=b[];
b[]=b[];
return ;
}else{
if(b[]-b[]==){
b[]=b[]+a[]-a[];
b[]=b[];
a[]=a[];
a[]=a[];
return ;
}
if(abs(b[]-b[])!=abs(a[]-a[]))return ;
a[]=a[];
a[]=a[];
b[]=b[];
b[]=b[];
return ;
}
} int main(){
scanf("%d%d%d%d",&a[],&b[],&a[],&b[]);
bool ans=farm();
if(ans)printf("%d %d %d %d\n",a[],b[],a[],b[]);
else puts("-1");
return ;
}
CF459A Pashmak and Garden (水的更多相关文章
- cf459A Pashmak and Garden
A. Pashmak and Garden time limit per test 1 second memory limit per test 256 megabytes input standar ...
- CodeForces 459A Pashmak and Garden(水~几何-给两点求两点组成正方形)
题目链接:http://codeforces.com/problemset/problem/459/A 题目大意: 给出两个点(在坐标轴中),求另外两个点从而构成一个正方形,该正方形与坐标轴平行. 如 ...
- Codeforces Round #261 (Div. 2)459A. Pashmak and Garden(数学题)
题目链接:http://codeforces.com/problemset/problem/459/A A. Pashmak and Garden time limit per test 1 seco ...
- Codeforce 459A - Pashmak and Garden (已知两点求另外两点构成正方形)
Pashmak has fallen in love with an attractive girl called Parmida since one year ago... Today, Pashm ...
- Codeforces Round #261 (Div. 2) B. Pashmak and Flowers 水题
题目链接:http://codeforces.com/problemset/problem/459/B 题意: 给出n支花,每支花都有一个漂亮值.挑选最大和最小漂亮值得两支花,问他们的差值为多少,并且 ...
- codeforces 459 A. Pashmak and Garden 解题报告
题目链接:http://codeforces.com/problemset/problem/459/A 题目意思:给出两个点的坐标你,问能否判断是一个正方形,能则输出剩下两点的坐标,不能就输出 -1. ...
- CF 459A(Pashmak and Garden-正方形给出2点求2点)
A. Pashmak and Garden time limit per test 1 second memory limit per test 256 megabytes input standar ...
- CF 459A && 459B && 459C && 459D && 459E
http://codeforces.com/contest/459 A题 Pashmak and Garden 化简化简水题,都告诉平行坐标轴了,数据还出了对角线,后面两个点坐标给的范围也不错 #in ...
- [codeforces] 暑期训练之打卡题(二)
每个标题都做了题目原网址的超链接 Day11<Given Length and Sum of Digits...> 题意: 给定一个数 m 和 一个长度 s,计算最大和最小在 s 长度下, ...
随机推荐
- Matlab的实时编辑器(Live Script)
Matlab的实时编辑器(Live Script) 看到伟哥换用了matlab2016a,里面集成了acf行人检测算法,感觉挺好的,索性也从matlab2014a跨越到matlab2016a. 安装后 ...
- jquery插件-表单验证插件-rules
ruels方法 1说明:查看.新增.移除一个表单控件的验证规则 2使用: 表单控件.rules(); 参数: rules() 返回元素的验证规则 rules('add',rules) 增加验证规则 r ...
- Ubuntu下root密码认证错误
1.默认root密码是随机的,即每次开机都有一个新的root密码.我们可以在终端输入命令 sudo passwd root,然后输入当前用户的密码,再输入要设置root的密码,我们一般设置成两个都一样 ...
- Cacti /graphs_new.php SQL Injection Vulnerability
catalogue . 漏洞描述 . 漏洞触发条件 . 漏洞影响范围 . 漏洞代码分析 . 防御方法 . 攻防思考 1. 漏洞描述 other SQL injection vulnerability ...
- Mysql Index、B Tree、B+ Tree、SQL Optimization
catalog . 引言 . Mysql索引 . Mysql B/B+ Tree . Mysql SQL Optimization . MySQL Query Execution Process 1. ...
- shell实现的守护进程
代码本来是别人那里拿来的,自己又改了下,给busybox用. #! /bin/sh PRO_PATH=/opt/myapp PROGRAM=packet_analyzer while true ; d ...
- 重新认识unicode和utf8编码
重新认识unicode和utf8编码 直到今天,准确的说是刚才,我才知道UTF-8编码和Unicode编码是不一样的,是有区别的囧 他们之间是有一定的联系的,看看他们的区别: UTF-8的长度是不一定 ...
- 【Alpha阶段】第7.5次Scrum例会
会议信息 时间:2016.10.31 21:30 时长:10min 地点:大运村1号公寓5楼楼道 类型:日常Scrum会议 NXT:2016.11.01 21:30 个人任务报告 姓名 今日已完成Is ...
- MySQL安装问题
win8.1安装mysql5.6时遇到问题,主要出现最后一步配置卡在了start server这一步会弹窗配置时间过长. 在网上查找方式并尝试之后都不能解决问题,尝试了卸载软件,清理注册表中的mysq ...
- HDU5671Matrix(矩阵行列交换)
有一个nn行mm列的矩阵(1 \leq n \leq 1000 ,1 \leq m \leq 1000 )(1≤n≤1000,1≤m≤1000),在这个矩阵上进行qq (1 \leq q \leq 1 ...