codeforces 459 A. Pashmak and Garden 解题报告
题目链接:http://codeforces.com/problemset/problem/459/A
题目意思:给出两个点的坐标你,问能否判断是一个正方形,能则输出剩下两点的坐标,不能就输出 -1。
这题更傻了,在考虑对角线的两点时,少考虑了一种情况:两个点分属不同象限:这时需要用到绝对值函数 abs !
最近集训不知道是不是搞傻左,反正CF的题目打了几场,结果都很惨,有一点点恐惧感,怕跌回以前不堪的rating。唉~~~继续努力吧!!!
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std; int main()
{
int x1, y1, x2, y2;
while (scanf("%d%d%d%d", &x1, &y1, &x2, &y2) != EOF)
{
// 两点平行,绝对有解
if (x1 == x2 && y1 != y2) // x 坐标相同
{
if (x1 + (y1-y2) >= - && x1 + (y1-y2) <= ) // 这是为了严谨起见,可能会超出给定范围
printf("%d %d %d %d\n", x1 + (y1-y2), y1, x2 + (y1-y2), y2);
else
printf("%d %d %d %d\n", x1 + (y2-y1), y1, x2 + (y2-y1), y2);
}
else if (y1 == y2 && x1 != x2) // y 坐标相同
{
if ((x1-x2) + y1 >= - && (x1-x2) + y1 <= )
printf("%d %d %d %d\n", x1, (x1-x2) + y1, x2, (x1-x2) + y2);
else
printf("%d %d %d %d\n", x1, (x2-x1) + y1, x2, (x2-x1) + y2);
}
// 对角线情况不一定有解
else if (abs(x1 - x2) == abs(y1 - y2)) // 对角线
{
printf("%d %d %d %d\n", x1, y2, x2, y1);
}
else
{
printf("-1\n");
}
}
return ;
}
codeforces 459 A. Pashmak and Garden 解题报告的更多相关文章
- codeforces 459 B.Pashmak and Flowers 解题报告
题目链接:http://codeforces.com/problemset/problem/459/B 题目意思:有 n 朵 flowers,每朵flower有相应的 beauty,求出最大的beau ...
- codeforces 459C Pashmak and Buses 解题报告
题目链接:http://codeforces.com/problemset/problem/459/C 题目意思:有 n 个 students,k 辆 buses.问是否能对 n 个students安 ...
- codeforces C1. The Great Julya Calendar 解题报告
题目链接:http://codeforces.com/problemset/problem/331/C1 这是第一次参加codeforces比赛(ABBYY Cup 3.0 - Finals (onl ...
- codeforces B. Eugeny and Play List 解题报告
题目链接:http://codeforces.com/problemset/problem/302/B 题目意思:给出两个整数n和m,接下来n行给出n首歌分别的奏唱时间和听的次数,紧跟着给出m个时刻, ...
- codeforces 433C. Ryouko's Memory Note 解题报告
题目链接:http://codeforces.com/problemset/problem/433/C 题目意思:一本书有 n 页,每页的编号依次从 1 到 n 编排.如果从页 x 翻到页 y,那么| ...
- codeforces 459 E. Pashmak and Graph(dp)
题目链接:http://codeforces.com/contest/459/problem/E 题意:给出m条边n个点每条边都有权值问如果两边能够相连的条件是边权值是严格递增的话,最长能接几条边. ...
- codeforces 459 D. Pashmak and Parmida's problem(思维+线段树)
题目链接:http://codeforces.com/contest/459/problem/D 题意:给出数组a,定义f(l,r,x)为a[]的下标l到r之间,等于x的元素数.i和j符合f(1,i, ...
- codeforces 459 C. Pashmak and Buses(思维)
题目链接:http://codeforces.com/problemset/problem/459/C 题意:有n个人,k辆车,d天要求没有两个人在d天都坐在一起.输出坐的方法. 题解:这题很有意思, ...
- codeforces 556B. Case of Fake Numbers 解题报告
题目链接:http://codeforces.com/problemset/problem/556/B 题目意思:给出 n 个齿轮,每个齿轮有 n 个 teeth,逆时针排列,编号为0 ~ n-1.每 ...
随机推荐
- HDU4768:Flyer [ 二分的奇妙应用 好题 ]
传送门 Flyer Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- @OneToMany
实体关系之@OneToMany 博客分类: hibernate & ejb SQL Order.java package com.entity; import java.io.Seriali ...
- java.nio.ByteBuffer 以及flip,clear及rewind区别
Buffer 类 定义了一个可以线性存放primitive type数据的容器接口.Buffer主要包含了与类型(byte, char…)无关的功能. 值得注意的是Buffer及其子类都不是线程安全的 ...
- Java8期间及持续时间
原文:http://www.yiibai.com/java8/java8_periodduration.html 使用Java8,两个专门类引入来处理时间差. Period - 处理有关基于时间的日期 ...
- mini-uboot 启动过程简单分析
单片机有最小系统,所谓最小系统,就是单片机能正常工作所需要的最少外设.对于Uboot来说,同样有个最小系统,因为Uboot最主要的功能就是引导内核.下面我们通过一个简单的Mini-Uboot来分析Ub ...
- Android Studio 2.0 Beta 5公布,修复几个与即时执行相关的严重BUG.
Android Studio 2.0 Beta 5公布,修复几个与即时执行相关的严重BUG. This build fixes a couple of important bugs related t ...
- LeetCode 3_Longest Substring Without Repeating Characters
LeetCode 3_Longest Substring Without Repeating Characters 题目描写叙述: Given a string, find the length of ...
- gulp - sass 插件一直安装不好?
1.没有sass,只存在与scss 任务 gulp.task('scss', function() { return gulp.src(app.srcPath + '/sass/*.scss') .p ...
- IOS UIPickView+sqlite 选择中国全部城市案例
1.案例简单介绍 通过读取文件.将中国全部城市写入sqlite数据库中,现通过UIPickView实现中国全部城市的选择,效果图例如以下所看到的 2.城市对象模型 中国全部城市数据请看http://b ...
- 2014牡丹江 现场赛 F zoj 3824 Fiber-optic Network
首先赞一下题目, 好题 题意: Marjar University has decided to upgrade the infrastructure of school intranet by us ...