题目链接:http://codeforces.com/problemset/problem/459/A

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
  1. 0 0 0 1
output
  1. 1 0 1 1
input
  1. 0 0 1 1
output
  1. 0 1 1 0
input
  1. 0 0 1 2
output
  1. -1

题意:

给出两个点的坐标,问再补充两个点是否能形成正方形,能则输出其余两点的坐标。否则输出-1。

PS:

昨晚手贱了(做题的姿势不太对,),本来是一道非常easy的题。做得太急忘了考虑斜率为-1的情况(当时居然过了);最后就被别人Hack了,无语的是当时我已经锁了这题。仅仅能眼睁睁的看着被Hack。这还是第一次被别人Hack掉。真是智商捉急啊。

被别人一个案例3 5 5 3直接打屎!

代码例如以下:

  1. #include <cstdio>
  2. #include <cmath>
  3. #include <cstring>
  4. #include <string>
  5. #include <cstdlib>
  6. #include <iostream>
  7. #include <algorithm>
  8. using namespace std;
  9. const double eps = 1e-9;
  10. #define INF 1e18
  11. //typedef long long LL;
  12. //typedef __int64 LL;
  13. int main()
  14. {
  15. int x1,x2,y1,y2;
  16. int x3,y3,x4,y4;
  17.  
  18. while(~scanf("%d%d%d%d",&x1,&y1,&x2,&y2))
  19. {
  20. int t;
  21. if(x1 == x2 )
  22. {
  23. t = y1-y2;
  24. if(t < 0)
  25. t = -t;
  26. x3 = x1+t,x4 = x2+t;
  27. y3 = y1, y4 = y2;
  28. printf("%d %d %d %d\n",x3,y3,x4,y4);
  29. continue;
  30. }
  31. if(y1 == y2)
  32. {
  33. t = x1-x2;
  34. if(t < 0)
  35. t = -t;
  36. y3 = y1+t,y4 = y2+t;
  37. x3 = x1, x4 = x2;
  38. printf("%d %d %d %d\n",x3,y3,x4,y4);
  39. continue;
  40. }
  41. //if((y2-y1) == (x2-x1))//斜率为1
  42. if((y2-y1) == (x2-x1) ||(y2-y1) == -(x2-x1))//斜率为1或者-1
  43. {
  44. x3 = x1, y3 = y2;
  45. x4 = x2, y4 = y1;
  46. printf("%d %d %d %d\n",x3,y3,x4,y4);
  47. continue;
  48. }
  49.  
  50. printf("-1\n");
  51. }
  52. return 0;
  53. }

Codeforces Round #261 (Div. 2)459A. Pashmak and Garden(数学题)的更多相关文章

  1. Codeforces Round #261 (Div. 2)459D. Pashmak and Parmida&#39;s problem(求逆序数对)

    题目链接:http://codeforces.com/contest/459/problem/D D. Pashmak and Parmida's problem time limit per tes ...

  2. Codeforces Round #261 (Div. 2) B. Pashmak and Flowers 水题

    题目链接:http://codeforces.com/problemset/problem/459/B 题意: 给出n支花,每支花都有一个漂亮值.挑选最大和最小漂亮值得两支花,问他们的差值为多少,并且 ...

  3. Codeforces Round #261 (Div. 2) E. Pashmak and Graph DP

    http://codeforces.com/contest/459/problem/E 不明确的是我的代码为啥AC不了,我的是记录we[i]以i为结尾的点的最大权值得边,然后wa在第35  36组数据 ...

  4. Codeforces Round 261 Div.2 E Pashmak and Graph --DAG上的DP

    题意:n个点,m条边,每条边有一个权值,找一条边数最多的边权严格递增的路径,输出路径长度. 解法:先将边权从小到大排序,然后从大到小遍历,dp[u]表示从u出发能够构成的严格递增路径的最大长度. dp ...

  5. Codeforces Round 261 Div.2 D Pashmak and Parmida's problem --树状数组

    题意:给出数组A,定义f(l,r,x)为A[]的下标l到r之间,等于x的元素数.i和j符合f(1,i,a[i])>f(j,n,a[j]),求有多少对这样的(i,j). 解法:分别从左到右,由右到 ...

  6. Codeforces Round #261 (Div. 2) D. Pashmak and Parmida's problem (树状数组求逆序数 变形)

    题目链接 题意:给出数组A,定义f(l,r,x)为A[]的下标l到r之间,等于x的元素数.i和j符合f(1,i,a[i])>f(j,n,a[j]),求i和j的种类数. 我们可以用map预处理出  ...

  7. Codeforces Round #261 (Div. 2)[ABCDE]

    Codeforces Round #261 (Div. 2)[ABCDE] ACM 题目地址:Codeforces Round #261 (Div. 2) A - Pashmak and Garden ...

  8. Codeforces Round #261 (Div. 2)——Pashmak and Buses

    题目链接 题意: n个人,k个车,d天.每一个人每天能够坐随意一个车.输出一种情况保证:不存在两个人,每天都在同一辆车上 (1 ≤ n, d ≤ 1000; 1 ≤ k ≤ 109). 分析: 比赛中 ...

  9. Codeforces Round #261 (Div. 2)——Pashmak and Graph

    题目链接 题意: n个点.m个边的有向图.每条边有一个权值,求一条最长的路径,使得路径上边值严格递增.输出路径长度 )) 分析: 由于路径上会有反复点,而边不会反复.所以最開始想的是以边为状态进行DP ...

随机推荐

  1. SYN-Flood防御方法之一Synproxy

    SYN-Flood攻击: 攻击者发送大量的SYN给服务器. 服务器必须针对每一个SYN请求回送一个SYN-ACK 应答包,此时服务器就必须保持一条半开放的连接,直到接收到一个对应的ACK应答包为止. ...

  2. Ubuntu16.04系统安装搜狗输入法

    前言:正常双击.deb软件包安装搜狗输入法会有bug,需要按照下面操作进行消除错误. 一.下载搜狗输入法Linux版软件包 下载地址为:http://pinyin.sogou.com/linux/ , ...

  3. 什么是CNN--Convolutional Neural Networks

    是近些年在机器视觉领域很火的模型,最先由 Yan Lecun 提出. 如果想学细节可以看 Andrej Karpathy 的 cs231n . How does it work? 给一张图片,每个圆负 ...

  4. 使用jquery获取ul中当前正在点击的li的索引

    <ul class="list"> <li>哈哈</li> <li>呵呵</li> <li>嘻嘻</l ...

  5. R 连接DB2数据库

    1.odbc文件下载 教程: http://dasapp.oregon.gov/datamart/files/IBM_DB2_9.7_Run_Time_client_Notes.pdf 驱动地址: h ...

  6. Guitar Pro中文版下载,你想要的,都在这啦!

    我的音乐我做主!Guitar Pro7中文版的发布为更多音乐爱好者带来更多更优质的体验!为帮助所有吉他爱好者学习.绘谱.创作而设计的音乐空间!为前所未有的音乐盛听而震撼,音乐才子,等的就是你! Gui ...

  7. zabbix部署监控端(server)以及页面优化

    实验环境准备 172.20.10.2 server.zabbix.com 172.20.10.3 agent.zabbix.com 172.20.10.8 windows10 Server 端 [ro ...

  8. 《Exception》第八次团队作业:Alpha冲刺(第二天)

    一.项目基本介绍 项目 内容 这个作业属于哪个课程 任课教师博客主页链接 这个作业的要求在哪里 作业链接地址 团队名称 Exception 作业学习目标 1.掌握软件测试基础技术.2.学习迭代式增量软 ...

  9. Vue学习之路第四篇:v-html指令

    上一篇我们讲解了两种方式,把Vue对象的数据展示在页面上: 1.插值表达式 2.v-text指令 但是如果我们展示的数据包含元素标签或者样式,我们想展示标签或样式所定义的属性作用,该怎么进行渲染,比如 ...

  10. BZOJ 3675 [Apio2014]序列分割 (斜率优化DP)

    洛谷传送门 题目大意:让你把序列切割k次,每次切割你能获得 这一整块两侧数字和的乘积 的分数,求最大的分数并输出切割方案 神题= = 搞了半天也没有想到切割顺序竟然和答案无关...我太弱了 证明很简单 ...