Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding some more judges, here and there.
- Loading branch information
Andrés Mejía
committed
Oct 27, 2011
1 parent
df668a3
commit 5559cbb
Showing
1,890 changed files
with
5,179,744 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
74 changes: 74 additions & 0 deletions
74
COCI/2009-2010/Contest #7 - 24.04.2010/bakice/bakice.2.cpp
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,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; | ||
} |
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,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; | ||
} |
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,5 @@ | ||
4 4 | ||
.LX. | ||
.X.. | ||
.... | ||
.L.. |
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,5 @@ | ||
4 4 | ||
.XLX | ||
.X.. | ||
...L | ||
.X.. |
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,8 @@ | ||
7 7 | ||
...X..X | ||
XL....L | ||
....... | ||
...L... | ||
.....XL | ||
....... | ||
...X... |
102 changes: 102 additions & 0 deletions
102
COCI/2009-2010/Contest #7 - 24.04.2010/bakice/bakice.in.4
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,102 @@ | ||
100 100 | ||
.................................................................................................... | ||
.............................................XX.L.XX................................................ | ||
.................................................................................................... | ||
................................................L................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
.................................................................................................... | ||
|
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 @@ | ||
1 |
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 @@ | ||
2 |
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 @@ | ||
1 |
Binary file not shown.
Binary file not shown.
31 changes: 31 additions & 0 deletions
31
COCI/2009-2010/Contest #7 - 24.04.2010/cokolada/cokolada.2.cpp
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,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
34
COCI/2009-2010/Contest #7 - 24.04.2010/cokolada/cokolada.cpp
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,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; | ||
} |
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 @@ | ||
6 |
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 @@ | ||
7 |
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 @@ | ||
5 |
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 @@ | ||
10 |
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 @@ | ||
8 2 |
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 @@ | ||
8 3 |
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 @@ | ||
8 3 |
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,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.
Oops, something went wrong.