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
#include <iostream> | |
using namespace std; | |
const int maxn = 1e5 + 100; | |
// Arrays para salvar os intervalos das faixas e os premios de cada intervalo | |
int a[maxn], f[maxn]; | |
//numero de faixas e de ogros cuja forca foi medida | |
int n, m; |
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
#include <bits/stdc++.h> | |
using namespace std; | |
// Tamanho maximo de uma dimensao do grid | |
const int maxn = 1e3 + 100; | |
// Infinito - se não entendeu olhe: https://pt.wikipedia.org/wiki/Sistema_de_numera%C3%A7%C3%A3o_hexadecimal | |
// Para escrever numeros hexadecimais primeiro adicionamos 0x e em seguida o numero no formato hexadecimal | |
const int inf = 0x3f3f3f3f; |
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
#include<bits/stdc++.h> | |
using namespace std; | |
int main() { | |
int dist; | |
cin >> dist; | |
// Retiramos os valores de antes e depois de entrar no ciclo | |
dist -= 5; | |
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
#include<bits/stdc++.h> | |
using namespace std; | |
// Definimos o valor máximo de n para criar o vetor de adjacência | |
constexpr int maxn = 5e4+10; | |
using pii = pair<int, int>; | |
// Criamos o vetor do grafo | |
vector<pii> g[maxn]; // pair = {vizinhos, cor da aresta} |
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
// Criamos os vetores saindo de a e checamos se o cross deles é igual a 0 | |
bool collinear(Pt a, Pt b, Pt c) { return (b-a) / (c-a) == 0; } |
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
// O ponto a é o primeiro ponto da reta | |
// O ponto b é o segundo ponto da reta | |
// O ponto c é o ponto que queremos checar | |
bool ccw(Pt a, Pt b, Pt c) { return (b-a) / (c-a) > 0; } // ccw representa counterclockwise, que significa sentido anti-horário | |
bool cw(Pt a, Pt b, Pt c) { return (b-a) / (c-a) < 0; } // cw representa clockwise, que significa sentido horário |
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
// Para evitar o uso de doubles o valor retornado pela função é a área do polígono multiplicada por 2 | |
long long area(vector<Pt> polygon) { | |
Pt base = polygon[0]; | |
long long area = 0; | |
for(int i = 1; i < (int)(polygon.size()) - 1; i++) | |
area += (polygon[i]-base) / (polygon[i+1]-base); | |
return abs(area); // lembrar-se de retornar o módulo da área, pois dependendo da maneira que o polígono foi dado, | |
} // ao realizarmos o cross o valor deles pode ser negativo ou positivo |
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
struct Pt { | |
int x, y; | |
Pt(int _x = 0, int _y = 0) : x(_x), y(_y) {} | |
Pt operator+(const Pt& o) { return Pt(x+o.x, y+o.y); } // soma de vetores | |
Pt operator-(const Pt& o) { return Pt(x-o.x, y-o.y); } // subtração de vetores | |
void operator+=(const Pt& o) { x += o.x, y += o.y; } // somar vetores com o operador += | |
void operator-=(const Pt& o) { x -= o.x, y -= o.y; } // subtrair vetores com o operador -= | |
long long operator*(const Pt& o) { return 1ll*x*o.x + 1ll*y*o.y; } // dot - produto escalar | |
long long operator/(const Pt& o) { return 1ll*x*o.y - 1ll*y*o.x; } // cross - produto vetorial | |
}; |
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
#include <cstdio> | |
const int maxn = 100010; | |
int n, dp[maxn]; | |
bool mark[maxn]; // inicialmente o vetor é preenchido com 0 | |
int fib(int x) { | |
// caso base | |
if(x <= 1) return 1; |
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
#include <cstdio> | |
#include <vector> | |
using namespace std; | |
int solve(vector<int> caminho, int n) { | |
int atual = caminho.back(), ans = 0; | |
if(atual + 1 <= n) { | |
caminho.push_back(atual+1); | |
ans += solve(caminho, n); | |
caminho.pop_back(); |
OlderNewer