목록C++ (119)
레야몬
#include #include #include #define FOR(i, k, N) for(int i=k; i> N >> M; FOR(i, 1, N) cin >> num[i]; tr.resize(MAX_N*4); } pair init(int s, int e, int no) //세그먼트 트리 { if(s==e) { tr[no].X = tr[no].Y = num[s]; return tr[no]; } int m = (s+e)/2; pair lres = init(s, m, no*2); pair rres = init(m+1, e, no*2+1); return tr[no] = {max(lres.X, rres.X), min(lres.Y, rres.Y)}; //최댓값과 최솟값을 반환 } pair sum(int s, ..
#include #include #include #include #define MAX_V 10001 using namespace std; int V, E; //정점의 개수 V, 간선의 개수 E int vs[MAX_V], scc[MAX_V]; //visited 방문했는가? 이미 scc에 들어갔는가? int cnt; //bfs로 탐색된 순서 stack st; vector res, gr; //result, graph bool cmp(vector x, vector y) //벡터 정렬 { return x[0] > V >> E; gr.resize(V+1); for(int i=0; i> a >> b; gr[a].push_back(b); } } int dfs(int..
#include #include #define FOR(i, k, N) for(int i=k; i> N >> M >> K; FOR(i, 1, N) cin >> num[i]; } ll init(ll s, ll e, ll no) { if(s==e) return tr[no]=num[s]; ll m = (s+e)/2; return tr[no] = init(s, m, no*2) + init(m+1, e, no*2+1); } ll sum(ll s, ll e, ll no, ll l, ll r) { if(l>e || r> b >> c; if(a-1) cout
#include #include #include using namespace std; int cnt; string text, pattern; vector Fail() { int m = pattern.length(); vector pi(m); pi[0]=0; for(int i=1, j=0; i0 && pattern[i]!=pattern[j]) j=pi[j-1]; if(pattern[i] == pattern[j]) pi[i] = ++j; } return pi; } vector KMP() { int m = pattern.length(); int n = text.length(); vector pos; vector pi = Fail(); for(int i=0, j=0; i0 && text[i]!=pattern[j..
#include #include #include #define LOOP(i, N) for(int i=1; i> N; LOOP(i, N) { int x, y; cin >> x >> y; p[i] = VEC(x, y); } } bool compare(const VEC &a, const VEC &b) { if(1LL*a.q*b.p != 1LL*a.p*b.q) return 1LL*a.q*b.p < 1LL*a.p*b.q; if(a.y!=b.y) return a.y < b.y; return a.x < b.x; } ll CCW(VEC &a, VEC &b, VEC &c) { return 1LL*(a.x*b.y + b.x*c.y + c.x*a.y - a.x*c.y - b.x*a.y - c.x*b.y); } int mai..
#include #define LOOP(i, N) for(int i=1; i> N >> S >> E >> T; LOOP(i, N*5) { if(!((i-1)%5)) { LOOP(j, N) { int x; char tmp; cin >> tmp; x = tmp-'0'; if(x) pma[i][5*(j-1)+x]=ma[i][5*(j-1)+x]=1; //가중치가 0이 아니면 } } else pma[i][i-1]=ma[i][i-1]=1; } } void multiple(ll ma1[MAX_N*5+1][MAX_N*5+1], ll ma2[MAX_N*5+1][MAX_N*5+1]) //행렬 곱 { ll num[MAX_N*5+1][MAX_N*5+1]={}; //행렬 곱 후 값 LOOP(k, 5*N) { LOOP(i, 5*..
#include #include #include typedef long long int ll; char N[15]; //자연수 N ll num[10]; int main() { int n=-1; scanf("%s", N); for(int i=0; N[i]; i++) n++; //자릿수 세기 //앞에 있는 숫자 num[0]+=(n-1)*(ll)pow(10, n-1) - ((ll)pow(10, n-1)-1)/9 - n*(ll)pow(10, n-1); for(int i=0; i
먼저 이를 이해하려면 행렬과 백터를 알고 있어야 되는데.... https://jordano-jackson.tistory.com/27 [Algorithm] 선분교차(Line-segment intersection) 판정 알고리즘 • Line-segment intersection 판별 알고리즘의 필요성 Line-segment의 교차 판정은 PS에서 흔히 다뤄지는 문제이다. 예컨대 네 점 이 주어졌다고 하자. 이 때 다음과 같은 두 선분을 생각할 수 있다. 이때 두 jordano-jackson.tistory.com 여기에 알고리즘이 자세히 적혀있다. 많은 조건 분기라는 알고리즘이 있어서 찾아봤는데 아무것도 안나와서 뭐지 했는데 풀어보면서 알았다. 선분의 케이스가 많아서 모두다 고려해야 됬던 거다. 케이스를 다 ..