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
Showing
19 changed files
with
947 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,41 @@ | ||
#include <cstdio> | ||
#include <cstring> | ||
|
||
using namespace std; | ||
|
||
long long memo[201][200]; | ||
|
||
long long solve(int n, int have){ | ||
if(n == 0){ | ||
if(have) return 0; | ||
return 1; | ||
} | ||
|
||
long long &ret = memo[n][have]; | ||
|
||
if(ret == -1){ | ||
ret = 0; | ||
|
||
for(int i = 0;i * n <= have;++i) | ||
ret += solve(n - 1,have - i * n); | ||
} | ||
|
||
return ret; | ||
} | ||
|
||
int main(){ | ||
int N,K; | ||
|
||
memset(memo,-1,sizeof memo); | ||
|
||
while(true){ | ||
scanf("%d %d",&N,&K); | ||
if(N == 0) break; | ||
|
||
N -= K; | ||
|
||
printf("%lld\n",solve(K,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,58 @@ | ||
#include <cstdio> | ||
#include <vector> | ||
|
||
using namespace std; | ||
|
||
vector<int> L[20001]; | ||
int N,balance[20001],dp[20001]; | ||
|
||
void dfs(int cur, int p){ | ||
dp[cur] = 1; | ||
balance[cur] = 0; | ||
|
||
for(int i = L[cur].size() - 1,to;i >= 0;--i){ | ||
to = L[cur][i]; | ||
|
||
if(to != p){ | ||
dfs(to,cur); | ||
dp[cur] += dp[to]; | ||
balance[cur] = max(balance[cur],dp[to]); | ||
} | ||
} | ||
|
||
if(cur != 1) balance[cur] = max(balance[cur],N - dp[cur]); | ||
} | ||
|
||
int main(){ | ||
int T; | ||
|
||
scanf("%d",&T); | ||
|
||
while(T--){ | ||
scanf("%d",&N); | ||
|
||
for(int i = 1;i <= N;++i) | ||
L[i].clear(); | ||
|
||
for(int i = 1,u,v;i < N;++i){ | ||
scanf("%d %d",&u,&v); | ||
L[u].push_back(v); | ||
L[v].push_back(u); | ||
} | ||
|
||
dfs(1,0); | ||
|
||
int best = N + 1,ans = 0; | ||
|
||
for(int i = 1;i <= N;++i){ | ||
if(balance[i] < best){ | ||
best = balance[i]; | ||
ans = i; | ||
} | ||
} | ||
|
||
printf("%d %d\n",ans,best); | ||
} | ||
|
||
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,30 @@ | ||
#include <cstdio> | ||
#include <algorithm> | ||
|
||
using namespace std; | ||
|
||
int main(){ | ||
int T,n,a[1000]; | ||
|
||
scanf("%d",&T); | ||
|
||
while(T--){ | ||
scanf("%d",&n); | ||
|
||
for(int i = 0;i < n;++i) | ||
scanf("%d",&a[i]); | ||
|
||
a[n++] = 0; | ||
|
||
sort(a,a + n); | ||
|
||
int ans = 0; | ||
|
||
for(int i = n - 2;i >= 0;i -= 2) | ||
ans ^= (a[i + 1] - a[i] - 1); | ||
|
||
puts(ans == 0? "Bob will win" : "Georgia will win"); | ||
} | ||
|
||
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,33 @@ | ||
#include <cstdio> | ||
#include <algorithm> | ||
|
||
using namespace std; | ||
|
||
int main(){ | ||
int n,a[10]; | ||
|
||
while(true){ | ||
scanf("%d",&n); | ||
if(n == 0) break; | ||
|
||
for(int i = 0;i < n;++i) | ||
scanf("%d",&a[i]); | ||
|
||
sort(a,a + n); | ||
|
||
bool win = false; | ||
|
||
for(int i = 0;i < n;){ | ||
int e = i; | ||
|
||
while(e < n && a[e] == a[i]) ++e; | ||
|
||
if((e - i) & 1) win = true; | ||
i = e; | ||
} | ||
|
||
puts(win? "1" : "0"); | ||
} | ||
|
||
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,47 @@ | ||
#include <cstdio> | ||
#include <set> | ||
#include <map> | ||
|
||
using namespace std; | ||
|
||
int main(){ | ||
int n; | ||
int x[1000],y[1000]; | ||
set< pair<int, int> > S; | ||
|
||
while(true){ | ||
scanf("%d",&n); | ||
|
||
if(n == 0) break; | ||
|
||
S.clear(); | ||
|
||
for(int i = 0;i < n;++i){ | ||
scanf("%d %d",&x[i],&y[i]); | ||
S.insert(make_pair(x[i],y[i])); | ||
} | ||
|
||
int ans = 0; | ||
|
||
for(int i = 0;i < n;++i){ | ||
for(int j = i + 1;j < n;++j){ | ||
int vx = x[j] - x[i]; | ||
int vy = y[j] - y[i]; | ||
|
||
int x1 = 2 * x[i] + vx - vy,y1 = 2 * y[i] + vy + vx; | ||
int x2 = 2 * x[i] + vx + vy,y2 = 2 * y[i] + vy - vx; | ||
|
||
if(x1 % 2 == 0 && y1 % 2 == 0 && y1 % 2 == 0 && y2 % 2 == 0){ | ||
x1 /= 2; y1 /= 2; | ||
x2 /= 2; y2 /= 2; | ||
|
||
if(S.find(make_pair(x1,y1)) != S.end() && S.find(make_pair(x2,y2)) != S.end()) ++ans; | ||
} | ||
} | ||
} | ||
|
||
printf("%d\n",ans / 2); | ||
} | ||
|
||
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,69 @@ | ||
#include <cstdio> | ||
#include <algorithm> | ||
#include <queue> | ||
|
||
using namespace std; | ||
|
||
struct cow{ | ||
int h,w,val; | ||
|
||
cow(){} | ||
}a[1000]; | ||
|
||
bool cmp1(cow x, cow y){ | ||
return x.val < y.val; | ||
} | ||
|
||
int main(){ | ||
int N,A,B,C; | ||
|
||
scanf("%d %d %d %d",&N,&A,&B,&C); | ||
|
||
int h[N],w[N]; | ||
|
||
for(int i = 0;i < N;++i){ | ||
scanf("%d %d",&a[i].h,&a[i].w); | ||
a[i].val = A * a[i].h + B * a[i].w - C; | ||
h[i] = a[i].h; | ||
w[i] = a[i].w; | ||
} | ||
|
||
sort(a,a + N,cmp1); | ||
|
||
sort(h,h + N); | ||
int M1 = unique(h,h + N) - h; | ||
|
||
sort(w,w + N); | ||
int M2 = unique(w,w + N) - w; | ||
|
||
int ans = 0; | ||
|
||
for(int i = 0;i < M1;++i){ | ||
int pos1 = 0,aux = 0; | ||
priority_queue<int, vector<int>, greater<int> > Q; | ||
|
||
for(int j = 0,pos2 = 0;j < M2;++j){ | ||
int maxval = A * h[i] + B * w[j]; | ||
|
||
while(pos1 < N && a[pos1].val <= maxval){ | ||
if(a[pos1].h >= h[i]){ | ||
Q.push(a[pos1].w); | ||
++aux; | ||
} | ||
|
||
++pos1; | ||
} | ||
|
||
while(!Q.empty() && Q.top() < w[j]){ | ||
Q.pop(); | ||
--aux; | ||
} | ||
|
||
ans = max(ans,aux); | ||
} | ||
} | ||
|
||
printf("%d\n",ans); | ||
|
||
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,60 @@ | ||
#include <cstdio> | ||
#include <algorithm> | ||
#include <queue> | ||
|
||
using namespace std; | ||
|
||
int main(){ | ||
int N,C,F; | ||
|
||
scanf("%d %d %d",&N,&C,&F); | ||
|
||
pair<int,int> P[C]; | ||
|
||
for(int i = 0;i < C;++i) | ||
scanf("%d %d",&P[i].first,&P[i].second); | ||
|
||
sort(P,P + C); | ||
|
||
int bestL[C],bestR[C]; | ||
priority_queue<int> Ql,Qr; | ||
int sum = 0; | ||
|
||
for(int i = 0;i < C;++i){ | ||
bestL[i] = sum; | ||
|
||
Ql.push(P[i].second); | ||
sum += P[i].second; | ||
|
||
if(i + 1 > N / 2){ | ||
int x = Ql.top(); | ||
sum -= x; | ||
Ql.pop(); | ||
} | ||
} | ||
|
||
sum = 0; | ||
|
||
for(int i = C - 1;i >= 0;--i){ | ||
bestR[i] = sum; | ||
|
||
Qr.push(P[i].second); | ||
sum += P[i].second; | ||
|
||
if(C - i > N / 2){ | ||
int x = Qr.top(); | ||
sum -= x; | ||
Qr.pop(); | ||
} | ||
} | ||
|
||
int ans = -1; | ||
|
||
for(int i = N / 2;C - 1 - i >= N / 2;++i) | ||
if(bestL[i] + bestR[i] + P[i].second <= F) | ||
ans = P[i].first; | ||
|
||
printf("%d\n",ans); | ||
|
||
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,38 @@ | ||
#include <cstdio> | ||
#include <cstring> | ||
|
||
using namespace std; | ||
|
||
int memo[201][201]; | ||
|
||
int solve(int w, int h){ | ||
int &ret = memo[w][h]; | ||
|
||
if(ret == -1){ | ||
ret = 0; | ||
|
||
bool have[400]; | ||
memset(have,false,sizeof have); | ||
|
||
for(int i = 2;i < w - 1;++i) | ||
have[solve(i,h) ^ solve(w - i,h)] = true; | ||
|
||
for(int i = 2;i < h - 1;++i) | ||
have[solve(w,i) ^ solve(w,h - i)] = true; | ||
|
||
while(have[ret]) ++ret; | ||
} | ||
|
||
return ret; | ||
} | ||
|
||
int main(){ | ||
int W,H; | ||
|
||
memset(memo,-1,sizeof memo); | ||
|
||
while(scanf("%d %d",&W,&H) == 2) | ||
puts(solve(W,H) == 0? "LOSE" : "WIN"); | ||
|
||
return 0; | ||
} |
Oops, something went wrong.