Robot Race UVALive - 7020(几何数学 判断钝角)
2017-08-24 20:45
393 查看
题目链接:https://vjudge.net/problem/UVALive-7020
题意:按顺序给定n个点的坐标,问有没有一个点到第三个点的距离小于第二个点到那第三个点的距离,切第二个点在第一个点之后,有存在输出Unfair,反之输出Fair。
思路:判断相邻点与他们后面其他点之间会不会组成钝角,若会则Unfair,反之Fair。
代码如下:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<cstdlib>
#include<sstream>
#include<deque>
#include<stack>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double eps = 1e-9;
const int maxn = 10000 + 20;
const int maxt = 300 + 10;
const int mod = 10;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const int Dis[] = {-1, 1, -5, 5};
const double inf = 0x3f3f3f3f;
const int MOD = 1000;
const double PI = acos(-1.0);
struct node{
ll x, y;
}num[maxn];
bool judge(node a, node b, node c){
return (b.x - a.x) * (c.x - b.x) + (b.y - a.y) * (c.y - b.y) >= 0;
}
int main(){
int n;
while(~scanf("%d", &n) && n){
memset(num, 0, sizeof num);
for(int i = 0; i < n; ++i){
scanf("%lld%lld", &num[i].x, &num[i].y);
}
bool ok = true;
for(int i = 0; i < n - 2; ++i){
for(int j = i + 2; j < n; ++j){
if(!judge(num[i], num[i + 1], num[j])){
ok = false;
break;
}
}
if(!ok) break;
}
printf("%s\n", ok ? "Fair" : "Unfair");
}
return 0;
}
题意:按顺序给定n个点的坐标,问有没有一个点到第三个点的距离小于第二个点到那第三个点的距离,切第二个点在第一个点之后,有存在输出Unfair,反之输出Fair。
思路:判断相邻点与他们后面其他点之间会不会组成钝角,若会则Unfair,反之Fair。
代码如下:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<cstdlib>
#include<sstream>
#include<deque>
#include<stack>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double eps = 1e-9;
const int maxn = 10000 + 20;
const int maxt = 300 + 10;
const int mod = 10;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const int Dis[] = {-1, 1, -5, 5};
const double inf = 0x3f3f3f3f;
const int MOD = 1000;
const double PI = acos(-1.0);
struct node{
ll x, y;
}num[maxn];
bool judge(node a, node b, node c){
return (b.x - a.x) * (c.x - b.x) + (b.y - a.y) * (c.y - b.y) >= 0;
}
int main(){
int n;
while(~scanf("%d", &n) && n){
memset(num, 0, sizeof num);
for(int i = 0; i < n; ++i){
scanf("%lld%lld", &num[i].x, &num[i].y);
}
bool ok = true;
for(int i = 0; i < n - 2; ++i){
for(int j = i + 2; j < n; ++j){
if(!judge(num[i], num[i + 1], num[j])){
ok = false;
break;
}
}
if(!ok) break;
}
printf("%s\n", ok ? "Fair" : "Unfair");
}
return 0;
}
相关文章推荐
- Robot Race UVALive - 7020几何暴力
- Collision UVALive - 6613 (数学几何)
- Save the Students! UVALive - 5984 (几何判断点在三角形、圆、矩形)
- UVALive 7004(计算几何 判断点与多边形的关系)
- UVaLive 7359 Sum Kind Of Problem (数学,水题)
- UVa 754 Treasure Hunt <计算几何(相交判断)>
- UVALive-7351-The Agglomerator(计算几何)
- UVA 10609 数学 几何 递推
- UVALive 7004 Inside, Outside or On(判断点在多边形边上/内部/外部)
- HDU1046 POJ1450 UVALive2334 ZOJ1037 Gridland【数学计算+水题】
- UVALive 7040 Color (容斥原理 + 组合数学递推公式 + 求逆元 + 基础数论)
- UVALive 5878 - Shortest Leash 【计算几何】
- UVALive 7267 Mysterious Antiques in Sackler Museum (判断长方形)
- UVALive 3351 Easy and Not Easy Sudoku Puzzles 位运算~判断简单数独
- uva 11800 基础几何的图形判断
- UVALive 6582 Magical GCD (数学+数据结构) -- 解题报告
- UVALive-3263 That Nice Euler Circuit (几何欧拉定理)
- UVALive 7461 Separating Pebbles (计算几何)
- UVALive 3263 That Nice Euler Circuit 计算几何欧拉定理
- UVALive2287 POJ1047 HDU1313 ZOJ1073 Round and Round We Go【大数+数学计算+水题】