在C++中判断是否可以旋转页面
在这个问题中,我们得到了页面上三个点的坐标。我们的任务是 *判断是否可以旋转页面*。
页面的旋转方式是:'x'的新位置是'y'的旧位置,'y'的新位置是'z'的旧位置。根据旋转结果打印“Yes”或“No”。
让我们通过一个例子来理解这个问题:
输入:x = (0, 1), y = (1, 0), z = (0, -1)
输出:Yes
解释

我们可以将页面旋转90o。
解决方案:
如果满足某些条件,我们就可以旋转页面。
如果 *x和y之间的距离* 等于 *y和z之间的距离*,则可以旋转。此外,如果所有点都在同一条直线上,则无法旋转。
程序演示了我们解决方案的工作原理:
示例
#include<bits/stdc++.h>
using namespace std;
int possibleOrNot(int coordinates[3][2]){
long long dis1 = pow(coordinates[1][0] - coordinates[0][0], 2) + pow(coordinates[1][1] - coordinates[0][1], 2);
long long dis2 = pow(coordinates[2][0] - coordinates[1][0], 2) + pow(coordinates[2][1] - coordinates[1][1], 2);
if(dis1 != dis2)
return 0;
else if (coordinates[1][0] == ((coordinates[0][0] + coordinates[2][0]) / 2.0) && coordinates[1][1] == ((coordinates[0][1] + coordinates[2][1]) / 2.0))
return 0;
else
return 1;
}
int main() {
int coordinates[3][2] = {{0 , 1}, {1 , 0}, {0, -1} } ;
if ( possibleOrNot(coordinates))
cout<<"The rotation of page is possible";
else
cout<<"The rotation of page is not possible";
return 0;
}输出
The rotation of page is possible
广告
数据结构
网络
关系数据库管理系统(RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP