CodeForces 459A Pashmak and Garden(水~几何-给两点求两点组成正方形)
题目链接:http://codeforces.com/problemset/problem/459/A
题目大意:
给出两个点(在坐标轴中),求另外两个点从而构成一个正方形,该正方形与坐标轴平行。
如果给的点构不成与坐标轴平行的正方形,则输出 -1.
两点范围: x1, y1, x2, y2 ( - 100 ≤ x1, y1, x2, y2 ≤ 100) 。所求两点范围: x3, y3, x4, y4 ( - 1000 ≤ x3, y3, x4, y4 ≤ 1000).
解题思路:
给出两个点,那么这两个有三种关系,
1. 两个点横坐标相等。 2.两个点纵坐标相等。 3.两个点对角。在坐标找“相对位置”的点即可。
if(x1==x2)
printf("%d %d %d %d\n", x1-abs(y1-y2),y1,x2-abs(y1-y2),y2);
上两行代码解释:
如果x1==x2,则两个点在同一列,求剩余两个点的位置,则剩余两个点的y可以从已知的两个点中得出【不明白可以在纸上画画】,则求两个点的“相对给出点的” x 的位置.
先求 x3 距离 x1(x1 对应 x3) 的绝对距离,然后让 x1-绝对距离(也可以是 x1+绝对距离),即可得到相对于x1的 x3 的位置,则第三个点的位置就有了,x3,y3(y3=y1).
同样在求x4,y4即可。
y1==y2 同样的思路不在解释。
如果给出的两个点为对角【if(abs(y1-y2)==abs(x1-x2))条件满足可以构成正方形】,则直接可以得出剩余两个点的位置【不明白纸上画画】。
AC Code:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int x1,x2,y1,y2;
while(scanf("%d%d%d%d",&x1,&y1,&x2,&y2)!=EOF)
{
if(x1==x2)
printf("%d %d %d %d\n", x1-abs(y1-y2),y1,x2-abs(y1-y2),y2);
else if(y1==y2)
printf("%d %d %d %d\n",x1,y1-abs(x1-x2),x2,y2-abs(x1-x2));
else if(abs(x1-x2)==abs(y1-y2))
printf("%d %d %d %d\n",x1,y2,x2,y1);
else
printf("-1\n");
}
return ;
}
CodeForces 459A Pashmak and Garden(水~几何-给两点求两点组成正方形)的更多相关文章
- Codeforces Round #261 (Div. 2)459A. Pashmak and Garden(数学题)
题目链接:http://codeforces.com/problemset/problem/459/A A. Pashmak and Garden time limit per test 1 seco ...
- Codeforce 459A - Pashmak and Garden (已知两点求另外两点构成正方形)
Pashmak has fallen in love with an attractive girl called Parmida since one year ago... Today, Pashm ...
- CF459A Pashmak and Garden (水
Pashmak and Garden Codeforces Round #261 (Div. 2) A. Pashmak and Garden time limit per test 1 second ...
- cf459A Pashmak and Garden
A. Pashmak and Garden time limit per test 1 second memory limit per test 256 megabytes input standar ...
- CF 459A(Pashmak and Garden-正方形给出2点求2点)
A. Pashmak and Garden time limit per test 1 second memory limit per test 256 megabytes input standar ...
- codeforces 459D - Pashmak and Parmida's problem【离散化+处理+逆序对】
题目:codeforces 459D - Pashmak and Parmida's problem 题意:给出n个数ai.然后定义f(l, r, x) 为ak = x,且l<=k<=r, ...
- Codeforces 459E Pashmak and Graph(dp+贪婪)
题目链接:Codeforces 459E Pashmak and Graph 题目大意:给定一张有向图,每条边有它的权值,要求选定一条路线,保证所经过的边权值严格递增,输出最长路径. 解题思路:将边依 ...
- 蓝桥杯 算法训练 Torry的困惑(基本型)(水题,筛法求素数)
算法训练 Torry的困惑(基本型) 时间限制:1.0s 内存限制:512.0MB 问题描述 Torry从小喜爱数学.一天,老师告诉他,像2.3.5.7……这样的数叫做质数.Torry突 ...
- Codeforces Round #261 (Div. 2) B. Pashmak and Flowers 水题
题目链接:http://codeforces.com/problemset/problem/459/B 题意: 给出n支花,每支花都有一个漂亮值.挑选最大和最小漂亮值得两支花,问他们的差值为多少,并且 ...
随机推荐
- Jenkins+svn+maven
首先我们在我们的服务器上安装好svn和maven 这里在前两步骤基本上没有啥问题,主要就是在Jenkins的步骤我弄了好长时间,这里记录一下 Jenkins的问题我是在这个网址解决的:http://b ...
- [转]JSON 入门指南
原文地址:http://www.ibm.com/developerworks/cn/web/wa-lo-json/ 尽管有许多宣传关于 XML 如何拥有跨平台,跨语言的优势,然而,除非应用于 Web ...
- 犀牛书的实例代码:给对象添加freeze, hide, 查询descriptors
/* * Define a properties() method in Object.prototype that returns an * object representing the name ...
- Hibernate @Formula 注解方式
1.Formula的作用 Formula的作用就是用一个查询语句动态的生成一个类的属性 就是一条select count(*)...构成的虚拟列,而不是存储在数据库里的一个字段.用比较标准的说法就是: ...
- Web前端性能优化教程03:添加Expires头
本文是Web前端性能优化系列文章中的第三篇,主要讲述添内容:加Expires头.完整教程可查看:Web前端性能优化 什么是Expires头? Expires存储的是一个用来控制缓存失效的日期.当浏览器 ...
- 【POJ 2342】Anniversary party(入门树形dp)
dp[i][0..1]表示i不来/来参加的最大总高兴值. 则dp[i][1]+=dp[v][0](v是i的所有直接下属) dp[i][0]+=max(dp[v][0],dp[v][1]) 没有告诉你树 ...
- html5标签figure、figcaption
figure.figcaption,这俩个标签都是定义图文的 常常用到一种图片列表,图片+标题或者图片+标题+简单描述.以前的常规写法: <li> <img src="te ...
- Extract Fasta Sequences Sub Sets by position
cut -d " " -f 1 sequences.fa | tr -s "\n" "\t"| sed -s 's/>/\n/g' & ...
- ECIF OCRM ACRM关系
ECIF :Enterprise Customer Information Facility 企业客户信息工厂: CRM:Customer Relationship Management 客户关系管 ...
- Linux安装后的基本配置
1.换源 http://mirrors.zju.edu.cn http://mirrors.aliyun.com http://mirrors.ustc.edu.cn ubuntu替换/etc/apt ...