-
Notifications
You must be signed in to change notification settings - Fork 2
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
aajjbb
committed
Jun 13, 2016
1 parent
8f4c6a9
commit f1ce923
Showing
17 changed files
with
250 additions
and
11 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,39 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
const int MAXN = 110; | ||
|
||
int T; | ||
int N, M; | ||
int P[MAXN][MAXN]; | ||
|
||
int main() { | ||
cin >> T; | ||
|
||
while (T--) { | ||
cin >> N >> M; | ||
|
||
for (int i= 0; i < N; i++) { | ||
for (int j = 0; j < M; j++) { | ||
cin >> P[i][j]; | ||
} | ||
} | ||
|
||
int ans = 0; | ||
|
||
for (int i = N - 1; i >= 0; i--) { | ||
for (int j = 0; j < M; j++) { | ||
int k = i; | ||
|
||
while (k + 1 < N && P[k][j] == 1 && P[k + 1][j] == 0) { | ||
swap(P[k][j], P[k + 1][j]); | ||
ans += 1; | ||
k++; | ||
} | ||
} | ||
} | ||
cout << ans << "\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,78 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
const int MAXN = 30030; | ||
|
||
int T, N; | ||
pair<double, double> P[MAXN]; | ||
|
||
double trap(pair<double, double> a, pair<double, double> b) { | ||
return (0.5*(b.first - a.first)*(b.second + a.second)); | ||
} | ||
|
||
double area(vector<pair<double, double> > vin) { | ||
int n = vin.size(); | ||
|
||
sort(vin.begin(), vin.end()); | ||
double ans = 0; | ||
|
||
do { | ||
double ret = 0.0; | ||
for(int i = 0; i < n; i++) { | ||
ret += trap(vin[i], vin[(i+1)%n]); | ||
} | ||
ans = max(ans, fabs(ret)); | ||
} while (next_permutation(vin.begin(), vin.end())); | ||
|
||
return fabs(ans); | ||
} | ||
|
||
double tryA(int base) { | ||
vector<pair<double, double> > vs; | ||
|
||
for (int i = 0; i < base; i++) { | ||
vs.push_back(P[i]); | ||
} | ||
|
||
for (int i = base; i < N; i++) { | ||
vector<pair<double, double> > buff = vs; | ||
double curr_area = area(buff); | ||
double best = 0; | ||
int id = -1; | ||
|
||
for (int j = 0; j < base; j++) { | ||
swap(buff[j], P[i]); | ||
if (area(buff) >= curr_area) { | ||
curr_area = area(buff); | ||
id = j; | ||
} | ||
swap(buff[j], P[i]); | ||
} | ||
if (id != -1) { | ||
vs = buff; | ||
buff[id] = P[i]; | ||
} | ||
vs = buff; | ||
} | ||
return area(vs); | ||
} | ||
|
||
int main() { | ||
cin >> T; | ||
|
||
while (T--) { | ||
cin >> N; | ||
|
||
for (int i = 0; i < N; i++) { | ||
cin >> P[i].first >> P[i].second; | ||
} | ||
|
||
sort(P, P + N); | ||
|
||
double ans = tryA(3); | ||
|
||
cout << fixed << setprecision(1) << ans << "\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,79 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
const int MAXN = 10005; | ||
|
||
const double EPS = 1e-9; | ||
|
||
int T, N, K; | ||
pair<double, double> P[MAXN]; | ||
|
||
int check(double rc) { | ||
int ans = 1, used = 0; | ||
double sum = 0.0; | ||
double s = INT_MAX; | ||
double l = INT_MIN; | ||
|
||
for (int i = 0; i < N; i++) { | ||
sum += P[i].second; | ||
used += 1; | ||
|
||
s = min(s, P[i].second); | ||
l = max(l, P[i].second); | ||
|
||
double pos_y = 0; | ||
|
||
pos_y = s + (l - s) / 2.0; | ||
|
||
//cout << fixed << setprecision(10) << i << " " << rc << " " << ans << " " << pos_y << " " << max(fabs(s - pos_y), fabs(l - pos_y)) << "\n"; | ||
|
||
|
||
if (max(fabs(s - pos_y), fabs(l - pos_y)) - EPS > rc) { | ||
|
||
ans += 1; | ||
|
||
s = P[i].second; | ||
l = P[i].second; | ||
used = 1; | ||
sum = P[i].second; | ||
} | ||
} | ||
|
||
return ans; | ||
} | ||
|
||
int main() { | ||
cin >> T; | ||
|
||
while (T--) { | ||
cin >> N >> K; | ||
|
||
for (int i = 0; i < N; i++) { | ||
cin >> P[i].first; | ||
cin >> P[i].second; | ||
} | ||
|
||
sort(P, P + N); | ||
|
||
double l = 0.0, h = 20000000000.0, m; | ||
double best = 0; | ||
|
||
for (int cnt = 0; cnt < 100; cnt++) { | ||
m = (l + h) / 2.0; | ||
|
||
int used = check(m); | ||
//cout << used << " " << m << "\n"; | ||
|
||
if (used <= K) { | ||
best = m; | ||
h = m; | ||
} else { | ||
l = m; | ||
} | ||
} | ||
|
||
cout << fixed << setprecision(1) << best << "\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,54 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
typedef long long Int; | ||
|
||
const int MAXN = 100005; | ||
|
||
int T, N; | ||
int A[MAXN]; | ||
int B[MAXN]; | ||
int P[MAXN]; | ||
Int bit[MAXN]; | ||
|
||
Int query(int pos) { | ||
Int ans = 0; | ||
|
||
for (int i = pos; i > 0; i -= (i & -i)) { | ||
ans += bit[i]; | ||
} | ||
|
||
return ans; | ||
} | ||
|
||
void update(int pos) { | ||
for (int i = pos; i <= N; i += (i & -i)) { | ||
bit[i] += 1; | ||
} | ||
} | ||
int main() { | ||
cin >> T; | ||
|
||
while (T--) { | ||
cin >> N; | ||
|
||
memset(bit, 0, sizeof(bit)); | ||
|
||
for (int i = 1; i <= N; i++) { | ||
cin >> A[i]; | ||
P[A[i]] = i; | ||
} | ||
|
||
Int ans = 0; | ||
|
||
for (int i = 1; i <= N; i++) { | ||
cin >> B[i]; | ||
B[i] = P[B[i]]; | ||
ans += (query(N) - query(B[i])); | ||
update(B[i]); | ||
} | ||
cout << ans << "\n"; | ||
} | ||
return 0; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.