博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CF459A Pashmak and Garden (水
阅读量:7288 次
发布时间:2019-06-30

本文共 2999 字,大约阅读时间需要 9 分钟。

 

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)

1 //#pragma comment(linker, "/STACK:102400000,102400000") 2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include
11 #include
12 using namespace std;13 #define ll long long14 #define usll unsigned ll15 #define mz(array) memset(array, 0, sizeof(array))16 #define minf(array) memset(array, 0x3f, sizeof(array))17 #define REP(i,n) for(i=0;i<(n);i++)18 #define FOR(i,x,n) for(i=(x);i<=(n);i++)19 #define RD(x) scanf("%d",&x)20 #define RD2(x,y) scanf("%d%d",&x,&y)21 #define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)22 #define WN(x) prllf("%d\n",x);23 #define RE freopen("D.in","r",stdin)24 #define WE freopen("1biao.out","w",stdout)25 #define mp make_pair26 27 int a[10],b[10];28 29 bool farm(){30 if(a[1]-a[0]==0){31 if(b[1]-b[0]==0)return 0;32 a[2]=a[0]+b[1]-b[0];33 a[3]=a[2];34 b[2]=b[0];35 b[3]=b[1];36 return 1;37 }else{38 if(b[1]-b[0]==0){39 b[2]=b[0]+a[1]-a[0];40 b[3]=b[2];41 a[2]=a[0];42 a[3]=a[1];43 return 1;44 }45 if(abs(b[1]-b[0])!=abs(a[1]-a[0]))return 0;46 a[2]=a[0];47 a[3]=a[1];48 b[2]=b[1];49 b[3]=b[0];50 return 1;51 }52 }53 54 int main(){55 scanf("%d%d%d%d",&a[0],&b[0],&a[1],&b[1]);56 bool ans=farm();57 if(ans)printf("%d %d %d %d\n",a[2],b[2],a[3],b[3]);58 else puts("-1");59 return 0;60 }
View Code

 

转载于:https://www.cnblogs.com/yuiffy/p/3916005.html

你可能感兴趣的文章
strtol详解
查看>>
mysql部分参数注解
查看>>
Powershell常用命令总结
查看>>
HAProxy+Keepalived实现Web服务器负载均衡
查看>>
apache动静态编译
查看>>
导出到Excal表格
查看>>
nginx Rewrite 规则
查看>>
周珍:浅析百度调整的几大猜想
查看>>
微软异想天开!居然想让电脑厂商为它生产VR眼镜
查看>>
Linux Mint和LMDE将开发新版
查看>>
Django框架下admin.py的中文修改+xadmin中文修改
查看>>
Linux CentOS 7 设置开机运行级别为3(文本多用户级别)
查看>>
“WPF老矣,尚能饭否”—且说说WPF今生未来(上):担心
查看>>
利用jpinyin将汉字转化成拼音
查看>>
Python之第一个程序
查看>>
习题总结(二)——禁ctrl+alt+delete,禁普通用户登录,禁ping
查看>>
localStorage只能存储字符串
查看>>
【Spring Boot】11.使用docker安装常见服务
查看>>
原子操作的实现
查看>>
HashMap实现原理及源码分析
查看>>