forked from marioyc/Online-Judge-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
marioyc
committed
Sep 24, 2010
1 parent
fecffd1
commit c70f4d8
Showing
1,035 changed files
with
161,113 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
#include <cstdio> | ||
#include <cstring> | ||
#include <climits> | ||
#include <vector> | ||
#include <queue> | ||
#include <algorithm> | ||
|
||
using namespace std; | ||
|
||
#define MAX_V 1+2*1500 | ||
#define MAX_E 2*1500 | ||
#define NIL 0 | ||
|
||
int E,to[MAX_E],next[MAX_E],last[MAX_V]; | ||
|
||
void init(){ | ||
fill(last,last+MAX_V,-1); | ||
E = 0; | ||
} | ||
|
||
void add_edge(int u, int v){ | ||
to[E] = v, next[E] = last[u]; last[u] = E; ++E; | ||
to[E] = u, next[E] = last[v]; last[v] = E; ++E; | ||
} | ||
|
||
int n,m,match[MAX_V],dist[MAX_V]; | ||
int head,tail,q[MAX_V]; | ||
|
||
bool BFS(){ | ||
head = tail = 0; | ||
|
||
for(int i = 1;i<=n;++i){ | ||
if(match[i]==NIL){ | ||
q[tail] = i; ++tail; | ||
dist[i] = 0; | ||
} | ||
else dist[i] = INT_MAX; | ||
} | ||
|
||
dist[NIL] = INT_MAX; | ||
|
||
int u,v; | ||
|
||
while(head<tail) { | ||
u = q[head]; ++head; | ||
|
||
for(int e = last[u];e!=-1;e = next[e]){ | ||
v = to[e]; | ||
|
||
if(dist[match[v]]==INT_MAX){ | ||
dist[match[v]] = dist[u]+1; | ||
|
||
if(match[v]!=NIL){ | ||
q[tail] = match[v]; | ||
++tail; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return dist[NIL]!=INT_MAX; | ||
} | ||
|
||
bool DFS(int u) { | ||
if(u!=NIL){ | ||
for(int e = last[u];e!=-1;e = next[e]){ | ||
int v = to[e]; | ||
|
||
if(dist[match[v]]==dist[u]+1) { | ||
if(DFS(match[v])) { | ||
match[v] = u; | ||
match[u] = v; | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
dist[u] = INT_MAX; | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
int hopcroft_karp() { | ||
int ret = 0; | ||
fill(match,match+(n+m+1),NIL); | ||
|
||
while(BFS()) | ||
for(int i=1;i<=n;++i) | ||
if(match[i]==NIL && DFS(i)) | ||
++ret; | ||
|
||
return ret; | ||
} | ||
|
||
int main(){ | ||
bool visited[1500],V1[1500]; | ||
|
||
while(scanf("%d",&n)==1){ | ||
vector<int> L[n]; | ||
|
||
for(int i = 0;i<n;++i){ | ||
int u,v,e; | ||
scanf("%d:(%d)",&u,&e); | ||
|
||
for(int j = 0;j<e;++j){ | ||
scanf("%d",&v); | ||
L[u].push_back(v); | ||
L[v].push_back(u); | ||
} | ||
} | ||
|
||
memset(visited,false,sizeof(visited)); | ||
memset(V1,false,sizeof(V1)); | ||
|
||
for(int i = 0;i<n;++i){ | ||
if(!visited[i]){ | ||
queue<int> Q; | ||
Q.push(i); | ||
visited[i] = true; | ||
V1[i] = true; | ||
|
||
while(!Q.empty()){ | ||
int aux = Q.front(); | ||
Q.pop(); | ||
|
||
for(int j = L[aux].size()-1;j>=0;--j){ | ||
int v = L[aux][j]; | ||
|
||
if(!visited[v]){ | ||
Q.push(v); | ||
visited[v] = true; | ||
V1[v] = !V1[aux]; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
m = n; | ||
init(); | ||
|
||
for(int i = 0;i<n;++i){ | ||
if(V1[i]){ | ||
for(int j = L[i].size()-1;j>=0;--j){ | ||
int v = L[i][j]; | ||
if(!V1[v]) add_edge(1+i,1+n+v); | ||
} | ||
} | ||
} | ||
|
||
printf("%d\n",hopcroft_karp()); | ||
} | ||
|
||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include <cstdio> | ||
#include <vector> | ||
#include <cstring> | ||
|
||
using namespace std; | ||
|
||
const int MAXV1 = 100; | ||
const int MAXV2 = 300; | ||
|
||
vector<int> L[MAXV1]; | ||
bool visited[MAXV2]; | ||
int V1,V2,match[MAXV2]; | ||
|
||
bool dfs(int u){ | ||
for(int i=L[u].size()-1;i>=0;--i){ | ||
int v = L[u][i]; | ||
|
||
if(!visited[v]){ | ||
visited[v] = true; | ||
if(match[v]==-1 || dfs(match[v])){ | ||
match[v] = u; | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
int maximum_matching(){ | ||
int ans = 0; | ||
memset(match,-1,sizeof(match)); | ||
|
||
for(int i=0;i<V1;++i){ | ||
memset(visited,false,sizeof(visited)); | ||
ans += dfs(i); | ||
} | ||
|
||
return ans; | ||
} | ||
|
||
int main(){ | ||
int T,m,s; | ||
scanf("%d",&T); | ||
|
||
while(T--){ | ||
scanf("%d %d",&V1,&V2); | ||
|
||
for(int i=0;i<V1;++i) L[i].clear(); | ||
|
||
for(int i=0;i<V1;++i){ | ||
scanf("%d", &m); | ||
while(m--){ | ||
scanf("%d",&s); | ||
L[i].push_back(s-1); | ||
} | ||
} | ||
|
||
if(maximum_matching()==V1) printf("YES\n"); | ||
else printf("NO\n"); | ||
} | ||
|
||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include<iostream> | ||
|
||
using namespace std; | ||
|
||
int main(){ | ||
int t,x,y; | ||
|
||
cin>>t; | ||
|
||
for(int i=0;i<t;i++){ | ||
cin>>x>>y; | ||
|
||
if(y>=0) | ||
if(x==y) | ||
if(x%2==0) cout<<2*x<<endl; | ||
else cout<<2*x-1<<endl; | ||
else if(x==y+2) | ||
if(x%2==0) cout<<2*x-2<<endl; | ||
else cout<<2*x-3<<endl; | ||
else cout<<"No Number"<<endl; | ||
else cout<<"No Number"<<endl; | ||
} | ||
|
||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <cstdio> | ||
|
||
using namespace std; | ||
|
||
int main(){ | ||
int N,h1,m1,h2,m2,sum; | ||
|
||
while(scanf("%d",&N)==1){ | ||
sum=0; | ||
|
||
for(int i=0;i<N;i++){ | ||
scanf("%d %d %d %d",&h1,&m1,&h2,&m2); | ||
|
||
if(h2==h1+1){ | ||
m2+=60; | ||
sum+=m2-m1; | ||
}else if(m2>m1) sum+=m2-m1; | ||
} | ||
|
||
printf("%d\n",sum/N); | ||
} | ||
|
||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include<iostream> | ||
#include<iomanip> | ||
|
||
using namespace std; | ||
|
||
bool primo[1000000]; | ||
|
||
int root(int &N){ | ||
if(primo[N]) return N; | ||
|
||
int sum; | ||
|
||
while(N>9){ | ||
sum=0; | ||
while(N!=0){ | ||
sum+=N%10; | ||
N/=10; | ||
} | ||
|
||
N=sum; | ||
|
||
if(primo[N]) return N; | ||
} | ||
|
||
return -1; | ||
}; | ||
|
||
int main(){ | ||
int N,aux; | ||
|
||
for(int i=0;i<1000000;i++) primo[i]=true; | ||
|
||
primo[0]=primo[1]=false; | ||
|
||
for(int i=2;i<1000000;i++) | ||
if(primo[i]) | ||
for(int j=2;j*i<1000000;j++) primo[j*i]=false; | ||
|
||
while(1){ | ||
cin>>N; | ||
if(N==0) break; | ||
|
||
cout<<setw(7)<<N<<" "; | ||
|
||
aux=root(N); | ||
|
||
if(aux==-1) cout<<setw(7)<<"none"<<endl; | ||
else cout<<setw(7)<<aux<<endl; | ||
} | ||
|
||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include<iostream> | ||
#include<vector> | ||
#include<string> | ||
|
||
using namespace std; | ||
|
||
int main(){ | ||
freopen("in.txt","r",stdin); | ||
freopen("out.txt","w",stdout); | ||
|
||
vector<string> complex; | ||
vector<string> map; | ||
|
||
int B1,B2,D1,D2,cont; | ||
string s; | ||
bool ok; | ||
|
||
while(1){ | ||
cin>>B1>>B2; | ||
if(B1==0 && B2==0) break; | ||
|
||
complex.clear(); | ||
map.clear(); | ||
|
||
for(int i=0;i<B1;i++){ | ||
cin>>s; | ||
complex.push_back(s); | ||
} | ||
|
||
cin>>D1>>D2; | ||
|
||
for(int i=0;i<D1;i++){ | ||
cin>>s; | ||
map.push_back(s); | ||
} | ||
|
||
cont=0; | ||
|
||
for(int i=0;i+B1-1<D1;i++){ | ||
for(int j=0;j+B2-1<D2;j++){ | ||
ok=true; | ||
|
||
for(int I=0;I<B1 && ok;I++) | ||
for(int J=0;J<B2 && ok;J++) | ||
if(complex[I][J]=='#' && map[I+i][J+j]=='.') ok=false; | ||
|
||
if(ok) cont++; | ||
} | ||
} | ||
|
||
cout<<cont<<endl; | ||
} | ||
|
||
return 0; | ||
} |
Oops, something went wrong.