Created
September 4, 2016 14:42
-
-
Save rogerioagjr/303ef5fda54119bb32898bb9c3c805be to your computer and use it in GitHub Desktop.
Jardim de infância - F2P2 - OBI 2016
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Jardim de infância - F2P2 - OBI 2016 | |
// Rogério Júnior | |
// Complexidade: O(1) | |
#include "bits/stdc++.h" | |
using namespace std; | |
#define F first | |
#define S second | |
typedef long long ll; | |
typedef pair<ll,ll> ii; | |
ii p[10]; | |
// natureza de X | |
ll sinal(ll x){ | |
if(x>0) return 1; | |
if(x<0) return -1; | |
if(x==0) return 0; | |
} | |
// distância ao quadrado entre A e B | |
ll dist2(ii a, ii b){ | |
return (a.F-b.F)*(a.F-b.F)+(a.S-b.S)*(a.S-b.S); | |
} | |
// produto vetorial dos pontos A, B e C | |
ll cross(ii a, ii b, ii c){ | |
// defino X=B-A e Y=C-A | |
ii x=ii(b.F-a.F,b.S-a.S),y=ii(c.F-a.F,c.S-a.S); | |
// e retorno XxY | |
return (x.F*y.S)-(y.F*x.S); | |
} | |
// testa a colinearidade de A, B e C | |
bool col(ii a, ii b, ii c){ | |
return (cross(a,b,c)==0); | |
} | |
// Cada um dos checks do problema | |
bool check1(){ | |
return (dist2(p[1],p[2])+dist2(p[1],p[3])>dist2(p[2],p[3])); | |
} | |
bool check2(){ | |
return (dist2(p[1],p[2])==dist2(p[1],p[3])); | |
} | |
bool check3(){ | |
return (col(p[2],p[3],p[4]) and col(p[2],p[3],p[5])); | |
} | |
bool check4(){ | |
return (p[2].F+p[3].F==p[4].F+p[5].F and p[2].S+p[3].S==p[4].S+p[5].S); | |
} | |
bool check5(){ | |
return (dist2(p[2],p[3])>dist2(p[4],p[5])); | |
} | |
bool check6(){ | |
return(dist2(p[4],p[6])+dist2(p[4],p[2])==dist2(p[2],p[6]) and dist2(p[5],p[7])+dist2(p[5],p[3])==dist2(p[3],p[7])); | |
} | |
bool check7(){ | |
return (dist2(p[4],p[6])==dist2(p[5],p[7])); | |
} | |
bool check8(){ | |
return (sinal(cross(p[2],p[3],p[1]))*sinal(cross(p[2],p[3],p[6]))==-1); | |
} | |
// função que checa todos os checks | |
bool check(){ | |
return (check1() and check2() and check3() and check4() and check5() and check6() and check7() and check8()); | |
} | |
int main(){ | |
// leio as coordenadas dos pontos | |
for(int i=1;i<=7;i++) cin >> p[i].F >> p[i].S; | |
// e testo se todas as condições são atendidas | |
cout << char(check()?'S':'N') << "\n"; | |
// por fim, retorno zero | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment