Codeforces Round #261 (Div. 2)459A. Pashmak and Garden(数学题)
题目链接:http://codeforces.com/problemset/problem/459/A
1 second
256 megabytes
standard input
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.
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.
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).
0 0 0 1
1 0 1 1
0 0 1 1
0 1 1 0
0 0 1 2
-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(数学题)的更多相关文章
- Codeforces Round #261 (Div. 2)459D. Pashmak and Parmida's problem(求逆序数对)
题目链接:http://codeforces.com/contest/459/problem/D D. Pashmak and Parmida's problem time limit per tes ...
- Codeforces Round #261 (Div. 2) B. Pashmak and Flowers 水题
题目链接:http://codeforces.com/problemset/problem/459/B 题意: 给出n支花,每支花都有一个漂亮值.挑选最大和最小漂亮值得两支花,问他们的差值为多少,并且 ...
- Codeforces Round #261 (Div. 2) E. Pashmak and Graph DP
http://codeforces.com/contest/459/problem/E 不明确的是我的代码为啥AC不了,我的是记录we[i]以i为结尾的点的最大权值得边,然后wa在第35 36组数据 ...
- Codeforces Round 261 Div.2 E Pashmak and Graph --DAG上的DP
题意:n个点,m条边,每条边有一个权值,找一条边数最多的边权严格递增的路径,输出路径长度. 解法:先将边权从小到大排序,然后从大到小遍历,dp[u]表示从u出发能够构成的严格递增路径的最大长度. dp ...
- 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). 解法:分别从左到右,由右到 ...
- 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预处理出 ...
- Codeforces Round #261 (Div. 2)[ABCDE]
Codeforces Round #261 (Div. 2)[ABCDE] ACM 题目地址:Codeforces Round #261 (Div. 2) A - Pashmak and Garden ...
- Codeforces Round #261 (Div. 2)——Pashmak and Buses
题目链接 题意: n个人,k个车,d天.每一个人每天能够坐随意一个车.输出一种情况保证:不存在两个人,每天都在同一辆车上 (1 ≤ n, d ≤ 1000; 1 ≤ k ≤ 109). 分析: 比赛中 ...
- Codeforces Round #261 (Div. 2)——Pashmak and Graph
题目链接 题意: n个点.m个边的有向图.每条边有一个权值,求一条最长的路径,使得路径上边值严格递增.输出路径长度 )) 分析: 由于路径上会有反复点,而边不会反复.所以最開始想的是以边为状态进行DP ...
随机推荐
- Android广播机制分析
1.1. 广播简单介绍 Android 广播与生活中的广播概念不同,它是指系统中产生事件后的通知. Android 广播不关心接收者是否收到处理或者怎样处理广播,能够说是一种单向的通知 ...
- [iOS翻译]《iOS7 by Tutorials》在Xcode 5里使用单元測试(上)
简单介绍: 单元測试是软件开发的一个重要方面.毕竟,单元測试能够帮你找到bug和崩溃原因,而程序崩溃是Apple在审查时拒绝app上架的首要原因. 单元測试不是万能的,但Apple把它作为开发工具包的 ...
- hdu(2846)Repository
Problem Description When you go shopping, you can search in repository for avalible merchandises by ...
- ASP.NET Core-组件:目录
ylbtech-ASP.NET Core-组件:目录 1.返回顶部 2.返回顶部 3.返回顶部 4.返回顶部 5.返回顶部 6.返回顶部 作者:ylbtech出处:http ...
- PHP中出现Notice: Undefined index的三种解决办法
前一段做的一个PHP程序在服务器运行正常,被别人拿到本机测试的时候总是出现“Notice: Undefined index:”这样的警告,这只是一个因为PHP版本不同而产生的警告(NOTICE或者WA ...
- Python学习历程之模块浅识
# =============================操作系统模块=======================# import os# 待续# ======================= ...
- HD-ACM算法专攻系列(16)——考试排名
问题描述: 源码: 主要要注意输出格式. #include"iostream" #include"iomanip" #include"algorith ...
- input上传文件检测文件大小
前几天在做 input[type='file'] 上传图片时,需要检测上传文件的内存大小,写了一个小demo,在此做一总结: <!DOCTYPE html> <html lang=& ...
- js判断传入时间和当前时间大小
//判断时间是否过期 function judgeTime(time){ var strtime = time.replace("/-/g", "/");//时 ...
- SQL Server死锁排查
1. 死锁原理 根据操作系统中的定义:死锁是指在一组进程中的各个进程均占有不会释放的资源,但因互相申请被其他进程所站用不会释放的资源而处于的一种永久等待状态. 死锁的四个必要条件:互斥条件(Mutua ...