Skip to content

Commit

Permalink
Adding some more judges, here and there.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrés Mejía committed Oct 27, 2011
1 parent df668a3 commit 5559cbb
Show file tree
Hide file tree
Showing 1,890 changed files with 5,179,744 additions and 0 deletions.
Binary file not shown.
Binary file not shown.
74 changes: 74 additions & 0 deletions COCI/2009-2010/Contest #7 - 24.04.2010/bakice/bakice.2.cpp
@@ -0,0 +1,74 @@
#include <iostream>
#include <algorithm>
#include <vector>
#include <cassert>

#define D(x) cout << #x " = " << (x) << endl
using namespace std;

const int MAXN = 105;

int dist(int x1, int y1, int x2, int y2){
int dx = x1 - x2;
int dy = y1 - y2;
return dx * dx + dy * dy;
}

char mat[MAXN][MAXN];
typedef pair<int, int> point;

int rows, cols;
vector<point> people, chairs;

int chairFor[MAXN];
vector<int> peopleFor[MAXN];

int dist(int guy, int chair){
return dist(people[guy].first, people[guy].second, chairs[chair].first, chairs[chair].second);
}

int main(){
cin >> rows >> cols;
for (int i = 0; i < rows; ++i){
for (int j = 0; j < cols; ++j){
cin >> mat[i][j];
if (mat[i][j] == 'X') people.push_back(point(i, j));
if (mat[i][j] == 'L') chairs.push_back(point(i, j));
}
}

for (int i = 0; i < people.size(); ++i){
chairFor[i] = -1;
}

vector<pair<int, pair<int, int> > > options;
for (int i = 0; i < people.size(); ++i){
for (int j = 0; j < chairs.size(); ++j){
options.push_back(make_pair(dist(i, j), make_pair(i, j)));
}
}

sort(options.begin(), options.end());
for (int k = 0; k < options.size(); ++k){
int d = options[k].first;
int guy = options[k].second.first;
int chair = options[k].second.second;
if (chairFor[guy] != -1) continue; //already seated
if (peopleFor[chair].size() == 0 ||
dist(peopleFor[chair][0], chair) == d){
chairFor[guy] = chair;
peopleFor[chair].push_back(guy);
}
}

// for (int i = 0; i < people.size(); ++i){
// D(chairFor[i]);
// }

int ans = 0;
for (int c = 0; c < chairs.size(); ++c){
ans += (peopleFor[c].size() > 1);
}
cout << ans << endl;
return 0;
}
66 changes: 66 additions & 0 deletions COCI/2009-2010/Contest #7 - 24.04.2010/bakice/bakice.cpp
@@ -0,0 +1,66 @@
#include <iostream>
#include <vector>
#include <cassert>

#define D(x) cout << #x " = " << (x) << endl
using namespace std;

const int MAXN = 105;

int dist(int x1, int y1, int x2, int y2){
int dx = x1 - x2;
int dy = y1 - y2;
return dx * dx + dy * dy;
}


char mat[MAXN][MAXN];
int sits[MAXN];
typedef pair<int, int> point;

int rows, cols;
vector<point> people, chairs;

int someoneCloser(int guy, int chair){
int D = dist(people[guy].first, people[guy].second, chairs[chair].first, chairs[chair].second);
for (int i = 0; i < people.size(); ++i){
if (i == guy) continue;
int d = dist(people[i].first, people[i].second, chairs[chair].first, chairs[chair].second);
if (d < D) return true;
}
return false;
}

int main(){
cin >> rows >> cols;
for (int i = 0; i < rows; ++i){
for (int j = 0; j < cols; ++j){
cin >> mat[i][j];
if (mat[i][j] == 'X') people.push_back(point(i, j));
if (mat[i][j] == 'L') chairs.push_back(point(i, j));
}
}

for (int i = 0; i < people.size(); ++i){
//figure out in what chair this guy sits
vector<pair<int, int> > options;
for (int j = 0; j < chairs.size(); ++j){
options.push_back(make_pair(dist(people[i].first, people[i].second, chairs[j].first, chairs[j].second), j));
}
sort(options.begin(), options.end());
sits[i] = -1; //no chair, yet
for (int j = 0; j < options.size(); ++j){
if (someoneCloser(i, j)) continue;
else{
sits[i] = options[j].second;
break;
}
}
}

for (int i = 0; i < people.size(); ++i){
cout << sits[i] << endl;
}

return 0;
}
5 changes: 5 additions & 0 deletions COCI/2009-2010/Contest #7 - 24.04.2010/bakice/bakice.in.1
@@ -0,0 +1,5 @@
4 4
.LX.
.X..
....
.L..
5 changes: 5 additions & 0 deletions COCI/2009-2010/Contest #7 - 24.04.2010/bakice/bakice.in.2
@@ -0,0 +1,5 @@
4 4
.XLX
.X..
...L
.X..
8 changes: 8 additions & 0 deletions COCI/2009-2010/Contest #7 - 24.04.2010/bakice/bakice.in.3
@@ -0,0 +1,8 @@
7 7
...X..X
XL....L
.......
...L...
.....XL
.......
...X...
102 changes: 102 additions & 0 deletions COCI/2009-2010/Contest #7 - 24.04.2010/bakice/bakice.in.4
@@ -0,0 +1,102 @@
100 100
....................................................................................................
.............................................XX.L.XX................................................
....................................................................................................
................................................L...................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

1 change: 1 addition & 0 deletions COCI/2009-2010/Contest #7 - 24.04.2010/bakice/bakice.out.1
@@ -0,0 +1 @@
1
1 change: 1 addition & 0 deletions COCI/2009-2010/Contest #7 - 24.04.2010/bakice/bakice.out.2
@@ -0,0 +1 @@
2
1 change: 1 addition & 0 deletions COCI/2009-2010/Contest #7 - 24.04.2010/bakice/bakice.out.3
@@ -0,0 +1 @@
1
Binary file not shown.
Binary file not shown.
31 changes: 31 additions & 0 deletions COCI/2009-2010/Contest #7 - 24.04.2010/cokolada/cokolada.2.cpp
@@ -0,0 +1,31 @@
#include <iostream>
#include <cassert>

#define D(x) cout << #x " = " << (x) << endl
using namespace std;

int main(){
int k;
cin >> k;

int p = 1;
while (p < k){
p <<= 1;
}


cout << p << " ";

int need = k, steps = 0, have = p;
while (need > 0){
if (have <= need){
need -= have;
}
have /= 2;
steps++;
}

cout << steps - 1 << endl;

return 0;
}
34 changes: 34 additions & 0 deletions COCI/2009-2010/Contest #7 - 24.04.2010/cokolada/cokolada.cpp
@@ -0,0 +1,34 @@
#include <iostream>
#include <cassert>

#define D(x) cout << #x " = " << (x) << endl
using namespace std;

int main(){
int k;
cin >> k;

int p = 1;
while (p < k){
p <<= 1;
}


cout << p << " ";

int s = 1;
while (!(k & s)){
s <<= 1;
}
// s = smallest power of two in k

int ans = 0;
while (p > s){
p >>= 1;
ans++;
}
assert(p == s);
cout << ans << endl;

return 0;
}
@@ -0,0 +1 @@
6
@@ -0,0 +1 @@
7
@@ -0,0 +1 @@
5
@@ -0,0 +1 @@
10
@@ -0,0 +1 @@
8 2
@@ -0,0 +1 @@
8 3
@@ -0,0 +1 @@
8 3
8 changes: 8 additions & 0 deletions COCI/2009-2010/Contest #7 - 24.04.2010/cokolada/run.rb
@@ -0,0 +1,8 @@
#! /usr/bin/ruby
1000.times do
x = rand(1000000) + 1
system "echo #{x} | ./cokolada > a"
system "echo #{x} | ./cokolada.2 > b"
system "diff a b"
system "rm a b"
end
Binary file not shown.

0 comments on commit 5559cbb

Please sign in to comment.