Skip to content

Commit

Permalink
aizu new COURSE volume
Browse files Browse the repository at this point in the history
  • Loading branch information
cielavenir committed Jul 10, 2013
1 parent 0342cce commit f1b2863
Show file tree
Hide file tree
Showing 8 changed files with 342 additions and 0 deletions.
File renamed without changes.
20 changes: 20 additions & 0 deletions tyama_aizuALDS1~10B.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// http://algorithms.blog55.fc2.com/blog-entry-66.html
#define M 100
int R[M+1],C[M][M],B[M][M];
D(i,j){
if(i==j)printf("M%d",i);
else printf("("),D(i,B[i][j]-1),D(B[i][j],j),printf(")");
}
main(N,i,j,k,c){
scanf("%d",&N);
for(i=0;i<N;i++)scanf("%d%d",R+i,&c);
R[i]=c;
memset(C,99,sizeof(C));
for(i=0;i<N;i++)C[i][i]=0;
for(j=1;j<N;j++)for(i=0;i<N-j;i++)for(k=i;k<i+j;k++)
if((c=C[i][k]+C[k+1][i+j]+R[i]*R[k+1]*R[i+j+1])<C[i][i+j])C[i][i+j]=c,B[i][i+j]=k;
printf("%d\n",C[0][N-1]);
//order(0,N);
//puts("");
exit(0);
}
43 changes: 43 additions & 0 deletions tyama_aizuCGL~1A.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <complex>
#include <vector>
#include <cstdio>
using namespace std;
const double EPS = 1e-8;
const double INF = 1e12;
typedef complex<double> P;
namespace std {
bool operator < (const P& a, const P& b) {
return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
}
}
double cross(const P& a, const P& b) {
return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
return real(conj(a)*b);
}

struct L : public vector<P> {
L(const P &a, const P &b) {
push_back(a); push_back(b);
}
};

typedef vector<P> G;

struct C {
P p; double r;
C(const P &p, double r) : p(p), r(r) { }
};

int main(){
double x,y;
int q;
scanf("%lf%lf",&x,&y);P p0(x,y);
scanf("%lf%lf%d",&x,&y,&q);P p1(x,y);
for(;q--;){
scanf("%lf%lf",&x,&y);P p(x,y);
P t=(p1-p0)*dot(p1-p0,p-p0)/norm(p1-p0)+p0;
printf("%.9f %.9f\n",real(t),imag(t));
}
}
44 changes: 44 additions & 0 deletions tyama_aizuCGL~1B.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <complex>
#include <vector>
#include <cstdio>
using namespace std;
const double EPS = 1e-8;
const double INF = 1e12;
typedef complex<double> P;
namespace std {
bool operator < (const P& a, const P& b) {
return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
}
}
double cross(const P& a, const P& b) {
return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
return real(conj(a)*b);
}

struct L : public vector<P> {
L(const P &a, const P &b) {
push_back(a); push_back(b);
}
};

typedef vector<P> G;

struct C {
P p; double r;
C(const P &p, double r) : p(p), r(r) { }
};

int main(){
double x,y;
int q;
scanf("%lf%lf",&x,&y);P p0(x,y);
scanf("%lf%lf%d",&x,&y,&q);P p1(x,y);
for(;q--;){
scanf("%lf%lf",&x,&y);P p(x,y);
P t=(p1-p0)*dot(p1-p0,p-p0)/norm(p1-p0)+p0;
P s=p+(t-p)*2.0;
printf("%.9f %.9f\n",real(s),imag(s));
}
}
52 changes: 52 additions & 0 deletions tyama_aizuCGL~1C.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include <complex>
#include <vector>
#include <cstdio>
using namespace std;
const double EPS = 1e-8;
const double INF = 1e12;
typedef complex<double> P;
namespace std {
bool operator < (const P& a, const P& b) {
return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
}
}
double cross(const P& a, const P& b) {
return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
return real(conj(a)*b);
}

struct L : public vector<P> {
L(const P &a, const P &b) {
push_back(a); push_back(b);
}
};

typedef vector<P> G;

struct C {
P p; double r;
C(const P &p, double r) : p(p), r(r) { }
};

int ccw(P a, P b, P c) {
b -= a; c -= a;
if (cross(b, c) > 0) return +1; // counter clockwise
if (cross(b, c) < 0) return -1; // clockwise
if (dot(b, c) < 0) return +2; // c--a--b on line
if (norm(b) < norm(c)) return -2; // a--b--c on line
return 0; // a--c--b on line
}

const char *z[]={"ONLINE_FRONT","CLOCKWISE","ON_SEGMENT","COUNTER_CLOCKWISE","ONLINE_BACK"};
int main(){
double x,y;
int q;
scanf("%lf%lf",&x,&y);P p0(x,y);
scanf("%lf%lf%d",&x,&y,&q);P p1(x,y);
for(;q--;){
scanf("%lf%lf",&x,&y);P p(x,y);
puts(z[ccw(p0,p1,p)+2]);
}
}
30 changes: 30 additions & 0 deletions tyama_aizuDSL~1A.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
struct UnionFind{
vector<int> data;
UnionFind(int size) : data(size, -1) {}
int unionSet(int x,int y){
x=root(x);y=root(y);
if(x==y)return 0;
if(data[y]<data[x])swap(x,y);
data[x]+=data[y],data[y]=x;
return 1;
}
bool findSet(int x,int y){
return root(x)==root(y);
}
int root(int x){
return data[x]<0 ? x : data[x]=root(data[x]);
}
int size(int x){
return -data[root(x)];
}
};
int main(){
int n,q,c,x,y;
scanf("%d%d",&n,&q);
UnionFind uf(n);
for(;q--;c?printf("%d\n",uf.findSet(x,y)):uf.unionSet(x,y))scanf("%d%d%d",&c,&x,&y);
}
77 changes: 77 additions & 0 deletions tyama_aizuGRL~3A.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#include <cstdio>
#include <vector>
#include <set>
#include <stack>
#include <algorithm>
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
using namespace std;

typedef int Weight;
struct Edge {
int src, dst;
Weight weight;
Edge(int src, int dst, Weight weight) :
src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

struct UndirectionalCompare {
bool operator() (const Edge& e, const Edge& f) const {
if (min(e.src,e.dst) != min(f.src,f.dst))
return min(e.src,e.dst) < min(f.src,f.dst);
return max(e.src,e.dst) < max(f.src,f.dst);
}
};
typedef set<Edge, UndirectionalCompare> Edgeset;
void visit(const Graph &g, int v, int u,
set<int>& art, vector<Edgeset>& bcomp,
stack<Edge>& S, vector<int>& num, vector<int>& low, int& time) {
low[v] = num[v] = ++time;
FOR(e, g[v]) {
int w = e->dst;
//if (num[w] < num[v]) S.push(*e); // for bcomps
if (num[w] == 0) {
visit(g, w, v, art, bcomp, S, num, low, time);
low[v] = min(low[v], low[w]);
if ((num[v] == 1 && num[w] != 2) || // for arts
(num[v] != 1 && low[w] >= num[v])) art.insert(v);
/*if (low[w] >= num[v]) { // for bcomps
bcomp.push_back(Edgeset());
while (1) {
Edge f = S.top(); S.pop();
bcomp.back().insert(f);
if (f.src == v && f.dst == w) break;
}
}*/
} else low[v] = min(low[v], num[w]);
}
}
void articulationPoint(const Graph& g,
set<int>& art, vector<Edgeset>& bcomp) {
const int n = g.size();
vector<int> low(n), num(n);
stack<Edge> S;
REP(u, n) if (num[u] == 0) {
int time = 0;
visit(g, u, -1, art, bcomp, S, num, low, time);
}
}

int main(){
int V,E,s,t;
scanf("%d%d",&V,&E);
Graph g(V);
set<int> art;
vector<Edgeset> bcomp;
for(;E--;)scanf("%d%d",&s,&t),g[s].push_back(Edge(s,t,0)),g[t].push_back(Edge(t,s,0));
articulationPoint(g,art,bcomp);
FOR(e, art)printf("%d\n",*e);
}
76 changes: 76 additions & 0 deletions tyama_aizuGRL~3B.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include <cstdio>
#include <vector>
#include <set>
#include <stack>
#include <algorithm>

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;

typedef int Weight;
struct Edge {
int src, dst;
Weight weight;
Edge(int src, int dst, Weight weight) :
src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

void visit(const Graph & g, int v, int u,
Edges& brdg, vector< vector<int> >& tecomp,
stack<int>& roots, stack<int>& S, vector<bool>& inS,
vector<int>& num, int& time) {
num[v] = ++time;
S.push(v); inS[v] = true;
roots.push(v);
FOR(e, g[v]) {
int w = e->dst;
if (num[w] == 0)
visit(g, w, v, brdg, tecomp, roots, S, inS, num, time);
else if (u != w && inS[w])
while (num[roots.top()] > num[w]) roots.pop();
}
if (v == roots.top()) {
brdg.push_back(Edge(u, v, 0));
tecomp.push_back(vector<int>());
while (1) {
int w = S.top(); S.pop(); inS[w] = false;
tecomp.back().push_back(w);
if (v == w) break;
}
roots.pop();
}
}
void bridge(const Graph& g, Edges& brdg, vector< vector<int> >& tecomp) {
const int n = g.size();
vector<int> num(n);
vector<bool> inS(n);
stack<int> roots, S;
int time = 0;
REP(u, n) if (num[u] == 0) {
visit(g, u, n, brdg, tecomp, roots, S, inS, num, time);
brdg.pop_back();
}
}

int main(){
int V,E,s,t;
scanf("%d%d",&V,&E);
Graph g(V);
Edges brdg;
vector<vector<int> > tecomp;
for(;E--;)scanf("%d%d",&s,&t),g[s].push_back(Edge(s,t,0)),g[t].push_back(Edge(t,s,0));
bridge(g,brdg,tecomp);
FOR(e, brdg)if(e->src>e->dst)swap(e->src,e->dst);
sort(ALL(brdg));
FOR(e, brdg)printf("%d %d\n",e->src,e->dst);
}

0 comments on commit f1b2863

Please sign in to comment.