题目链接: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(水~几何-给两点求两点组成正方形)的更多相关文章

  1. 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 ...

  2. Codeforce 459A - Pashmak and Garden (已知两点求另外两点构成正方形)

    Pashmak has fallen in love with an attractive girl called Parmida since one year ago... Today, Pashm ...

  3. CF459A Pashmak and Garden (水

    Pashmak and Garden Codeforces Round #261 (Div. 2) A. Pashmak and Garden time limit per test 1 second ...

  4. cf459A Pashmak and Garden

    A. Pashmak and Garden time limit per test 1 second memory limit per test 256 megabytes input standar ...

  5. 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 ...

  6. codeforces 459D - Pashmak and Parmida&#39;s problem【离散化+处理+逆序对】

    题目:codeforces 459D - Pashmak and Parmida's problem 题意:给出n个数ai.然后定义f(l, r, x) 为ak = x,且l<=k<=r, ...

  7. Codeforces 459E Pashmak and Graph(dp+贪婪)

    题目链接:Codeforces 459E Pashmak and Graph 题目大意:给定一张有向图,每条边有它的权值,要求选定一条路线,保证所经过的边权值严格递增,输出最长路径. 解题思路:将边依 ...

  8. 蓝桥杯 算法训练 Torry的困惑(基本型)(水题,筛法求素数)

    算法训练 Torry的困惑(基本型) 时间限制:1.0s   内存限制:512.0MB      问题描述 Torry从小喜爱数学.一天,老师告诉他,像2.3.5.7……这样的数叫做质数.Torry突 ...

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

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

随机推荐

  1. 创建模型,设置id

    /** * 创建模型,设置id */ Ext.onReady(function(){ Ext.define('Person',{ extend:'Ext.data.Model', idProperty ...

  2. Android Material Design 控件常用的属性

    android:fitsSystemWindows="true" 是一个boolean值的内部属性,让view可以根据系统窗口(如status bar)来调整自己的布局,如果值为t ...

  3. java进程CPU飙高

    因为这段时间一直在弄监控,但是工作还是在进行中 因为机器不多,所以今天早上巡检了一下,看到一台生产机器上的CPU飙高 top

  4. 去掉iPhone、iPad的默认按钮样式 去掉高光样式:

    input[type="button"], input[type="submit"], input[type="reset"] { -web ...

  5. 自定义jstl标签库

    开发环境:Spring+SpringMVC +Maven +Mybatis JSTL 标签库的配置: 导入对应的 jstl.jar 和 standard.jar ,我使用的配置如下: <prop ...

  6. MVC3缓存之一:使用页面缓存

    MVC3缓存之一:使用页面缓存 在MVC3中要如果要启用页面缓存,在页面对应的Action前面加上一个OutputCache属性即可. 我们建一个Demo来测试一下,在此Demo中,在View的Hom ...

  7. iOS开发基础知识碎片

    1:contentSize.contentInset和contentOffset区别 contentSize 是scrollview中的一个属性,它代表scrollview中的可显示区域,假如有一个s ...

  8. IOS开发中UI编写方式——code vs. xib vs.StoryBoard

    最近接触了几个刚入门的iOS学习者,他们之中存在一个普遍和困惑和疑问,就是应该如何制作UI界面.iOS应用是非常重视用户体验的,可以说绝大多数的应用成功与否与交互设计以及UI是否漂亮易用有着非常大的关 ...

  9. Leetcode 98. Validate Binary Search Tree

    Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as ...

  10. 【BZOJ-3308】九月的咖啡店 最大费用最大流 + 线性筛素数

    3308: 九月的咖啡店 Time Limit: 30 Sec  Memory Limit: 128 MBSubmit: 159  Solved: 56[Submit][Status][Discuss ...