Created
October 22, 2011 22:48
-
-
Save mejibyte/1306592 to your computer and use it in GitHub Desktop.
Solutions from little programming contest at UPB, October 22nd.
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
using namespace std; | |
#include<iostream> | |
#include<algorithm> | |
#include<iterator> | |
#include<sstream> | |
#include<fstream> | |
#include<cassert> | |
#include<climits> | |
#include<cstdlib> | |
#include<cstring> | |
#include<string> | |
#include<cstdio> | |
#include<vector> | |
#include<cmath> | |
#include<queue> | |
#include<deque> | |
#include<stack> | |
#include<list> | |
#include<map> | |
#include<set> | |
template <class T> string toStr(const T &x) | |
{ stringstream s; s << x; return s.str(); } | |
template <class T> int toInt(const T &x) | |
{ stringstream s; s << x; int r; s >> r; return r; } | |
#define For(i, a, b) for (int i=(a); i<(b); ++i) | |
#define foreach(x, v) for (typeof (v).begin() x = (v).begin(); x != (v).end(); ++x) | |
#define D(x) cout << #x " = " << (x) << endl; | |
const double EPS=1e-9; | |
int cmp(double x, double y=0, double tol=EPS) { | |
return (x <= y+tol) ? (x + tol < y) ? -1 : 0 : 1; | |
} | |
#define INPUT_FILE "business" | |
int main() { | |
freopen(INPUT_FILE ".in", "r", stdin); | |
long long n; int m, u, d; | |
vector< pair<long long, long long> > elevs; | |
while(cin >> n >> m) { | |
elevs.clear(); | |
while(m--) { | |
cin >> u >> d; | |
elevs.push_back(make_pair(u, d)); | |
} | |
long long ans = 1 << 28; | |
for(int i=0; i<elevs.size(); ++i) { | |
long long d = elevs[i].second; | |
long long u = elevs[i].first; | |
long long k = (n * d + u + d - 1) / (u + d); | |
if (((n * d) % (u + d)) == 0) k++; | |
long long f = u * k - (n - k) * d; | |
ans = min(ans, f); | |
} | |
assert(ans > 0); | |
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
using namespace std; | |
#include<iostream> | |
#include<algorithm> | |
#include<iterator> | |
#include<sstream> | |
#include<fstream> | |
#include<cassert> | |
#include<climits> | |
#include<cstdlib> | |
#include<cstring> | |
#include<string> | |
#include<cstdio> | |
#include<vector> | |
#include<cmath> | |
#include<queue> | |
#include<deque> | |
#include<stack> | |
#include<list> | |
#include<map> | |
#include<set> | |
template <class T> string toStr(const T &x) | |
{ stringstream s; s << x; return s.str(); } | |
template <class T> int toInt(const T &x) | |
{ stringstream s; s << x; int r; s >> r; return r; } | |
#define For(i, a, b) for (int i=(a); i<(b); ++i) | |
#define foreach(x, v) for (typeof (v).begin() x = (v).begin(); x != (v).end(); ++x) | |
#define D(x) cout << #x " = " << (x) << endl; | |
const double EPS=1e-9; | |
int cmp(double x, double y=0, double tol=EPS) { | |
return (x <= y+tol) ? (x + tol < y) ? -1 : 0 : 1; | |
} | |
#define INPUT_FILE "database" | |
map<string, int> face; | |
long long mat[10005][10]; | |
char s[100]; | |
int main() { | |
freopen(INPUT_FILE ".in", "r", stdin); | |
int Casos; | |
gets(s); | |
sscanf(s, "%d", &Casos); | |
while (Casos--){ | |
int currentString = 0; | |
int n, m; | |
gets(s); | |
sscanf(s, "%d %d", &n, &m); | |
face.clear(); | |
for (int i = 0; i < n; ++i) { | |
gets(s); | |
int len = strlen(s); | |
int j = 0; | |
long long hash = 0; | |
long long pow = 1; | |
long long magic = 137; | |
for (int k = 0; k <= len; ++k) { | |
if (k == len || s[k] == ',') { | |
mat[i][j] = hash; | |
hash = 0; | |
pow = 1; | |
j++; | |
} else { | |
hash += pow * s[k]; | |
pow *= magic; | |
} | |
} | |
} | |
// if (n < 100) { | |
// printf("Mat is:\n"); | |
// for (int i = 0; i < n; ++i){ | |
// For(j, 0, n) { | |
// cout << mat[i][j] << " "; | |
// } | |
// cout << endl; | |
// } | |
// } | |
bool valid = true; | |
for (int c1 = 0; c1 < m; ++c1) { | |
for (int c2 = 0; c2 < m; ++c2) { | |
if (c1 == c2) continue; | |
map< pair<int, int>, int > seen; | |
for (int r = 0; r < n; ++r) { | |
pair<int, int> cur = make_pair(mat[r][c1], mat[r][c2]); | |
//printf("cur = <%d, %d>\n", cur.first, cur.second); | |
if (seen.count( cur ) > 0 ){ | |
// found | |
int r2 = seen[cur]; | |
puts("NO"); | |
printf("%d %d\n", r2 + 1, r + 1); | |
printf("%d %d\n", c1 + 1, c2 + 1); | |
//printf("los hashes son: %lld, %lld\n", mat[r][c1], mat[r][c2]); | |
valid = false; | |
c1 = m + 1; c2 = m + 1; break; // super break | |
} | |
seen[cur] = r; | |
} | |
} | |
} | |
if (valid) puts("YES"); | |
} | |
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
using namespace std; | |
#include<iostream> | |
#include<algorithm> | |
#include<iterator> | |
#include<sstream> | |
#include<fstream> | |
#include<cassert> | |
#include<climits> | |
#include<cstdlib> | |
#include<cstring> | |
#include<string> | |
#include<cstdio> | |
#include<vector> | |
#include<cmath> | |
#include<queue> | |
#include<deque> | |
#include<stack> | |
#include<list> | |
#include<map> | |
#include<set> | |
template <class T> string toStr(const T &x) | |
{ stringstream s; s << x; return s.str(); } | |
template <class T> int toInt(const T &x) | |
{ stringstream s; s << x; int r; s >> r; return r; } | |
#define For(i, a, b) for (int i=(a); i<(b); ++i) | |
#define foreach(x, v) for (typeof (v).begin() x = (v).begin(); x != (v).end(); ++x) | |
#define D(x) cout << #x " = " << (x) << endl; | |
const double EPS=1e-9; | |
int cmp(double x, double y=0, double tol=EPS) { | |
return (x <= y+tol) ? (x + tol < y) ? -1 : 0 : 1; | |
} | |
#define INPUT_FILE "headshot" | |
int main() { | |
freopen(INPUT_FILE ".in", "r", stdin); | |
string acase; | |
while(cin >> acase){ | |
int n = acase.size(); | |
int zeros = 0; | |
int zero_zero = 0; | |
for (int i = 0; i < n ; i++){ | |
if (acase[i] == '0'){ | |
zeros++; | |
if(acase[(i+1) % n] == '0') zero_zero++; | |
} | |
} | |
pair<int, int> rotate = make_pair(zeros, n); | |
pair<int, int> shoot = make_pair(zero_zero, zeros); | |
if (rotate.first * shoot.second > shoot.first * rotate.second){ | |
puts("ROTATE"); | |
}else if (rotate.first * shoot.second < shoot.first * rotate.second){ | |
puts("SHOOT"); | |
}else{ | |
puts("EQUAL"); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment