题目链接: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
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

题意:

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

PS:

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

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

代码例如以下:

#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
const double eps = 1e-9;
#define INF 1e18
//typedef long long LL;
//typedef __int64 LL;
int main()
{
int x1,x2,y1,y2;
int x3,y3,x4,y4; while(~scanf("%d%d%d%d",&x1,&y1,&x2,&y2))
{
int t;
if(x1 == x2 )
{
t = y1-y2;
if(t < 0)
t = -t;
x3 = x1+t,x4 = x2+t;
y3 = y1, y4 = y2;
printf("%d %d %d %d\n",x3,y3,x4,y4);
continue;
}
if(y1 == y2)
{
t = x1-x2;
if(t < 0)
t = -t;
y3 = y1+t,y4 = y2+t;
x3 = x1, x4 = x2;
printf("%d %d %d %d\n",x3,y3,x4,y4);
continue;
}
//if((y2-y1) == (x2-x1))//斜率为1
if((y2-y1) == (x2-x1) ||(y2-y1) == -(x2-x1))//斜率为1或者-1
{
x3 = x1, y3 = y2;
x4 = x2, y4 = y1;
printf("%d %d %d %d\n",x3,y3,x4,y4);
continue;
} printf("-1\n");
}
return 0;
}

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. MySQL具体解释(8)----------MySQL线程池总结(二)

    这篇文章是对上篇文章的一个补充,主要环绕下面两点展开.one-connection-per-thread的实现方式以及线程池中epoll的使用. one-connection-per-thread 依 ...

  2. [Golang] 从零開始写Socket Server(3): 对长、短连接的处理策略(模拟心跳)

    通过前两章,我们成功是写出了一套凑合能用的Server和Client,并在二者之间实现了通过协议交流.这么一来,一个简易的socket通讯框架已经初具雏形了,那么我们接下来做的.就是想办法让这个框架更 ...

  3. lightoj--1410--Consistent Verdicts(技巧)

    Consistent Verdicts Time Limit: 5000MS   Memory Limit: 32768KB   64bit IO Format: %lld & %llu Su ...

  4. 剑指offer——03从尾至头打印列表(Python3)

    思路:相当于数据结构中的链表就地逆置,可以使用头插法来实现. 代码: class Solution:     # 返回从尾部到头部的列表值序列,例如[1,2,3]     def printListF ...

  5. ubuntu16.04 安装 docker-compose

    下载安装 docker-composecurl -L https://github.com/docker/compose/releases/download/1.15.0/docker-compose ...

  6. 浅谈SpringCloud (三) Ribbon负载均衡

    什么是负载均衡 当一台服务器的单位时间内的访问量越大时,服务器压力就越大,大到超过自身承受能力时,服务器就会崩溃.为了避免服务器崩溃,让用户有更好的体验,我们通过负载均衡的方式来分担服务器压力. 我们 ...

  7. usaco No Change, 2013 Nov 不找零(二分查找+状压dp)

    Description 约翰带着 N 头奶牛在超市买东西,现在他们正在排队付钱,排在第 i 个位置的奶牛需要支付 Ci 元.今天说好所有东西都是约翰请客的,但直到付账的时候,约翰才意识到自己没带钱,身 ...

  8. 基于XMPP利用openfire简单的即时通讯

    功能的实现结果:能够使自己编写客户端与spark客户端信息通讯,将接受到的信息更新到textview上. 1.下载openfire并安装.设置域名,添加用户 2.下载安装spark客户端 3.jar包 ...

  9. Linux部署之NFS方式安装系统

    1.         让客户端从网络启动并且选择第二项   2.         选择语言   3.         选择键盘布局   4.         选择安装方式为NFS   5.       ...

  10. Eclipse中执行Ant脚本出现Could not find the main class的问题及解

    试过了:https://blog.csdn.net/bookroader/article/details/2300337 但是不管用,偶然看到这篇没有直接关系的 https://blog.csdn.n ...