https://code.google.com/codejam/contest/2933486/dashboard
A
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
inline int getNode(const string &name, int &n, map<string, int> &hash, vector<set<int> > &adj) {
const map<string,int>::iterator it = hash.find(name);
if (it != hash.end())
return it->second;
adj.push_back(set<int> ());
const int node = n++;
hash[name] = node;
return node;
}
bool check(const int n, const vector<set<int> > &adj) {
const int BLACK = -1, WHITE = 1, UNCOLORED = 0;
vector<int> color(n, UNCOLORED);
for (int i = 0; i < n; ++i) {
if (color[i]) continue;
color[i] = BLACK;
queue<int> q;
q.push(i);
while (!q.empty()) {
const int u = q.front();
q.pop();
for (set<int>::iterator it = adj[u].begin(); it != adj[u].end(); ++it) {
const int v = (*it);
if (color[v] == color[u]) return false;
if (color[v]) continue;
color[v] = -color[u];
q.push(v);
}
}
}
return true;
}
int main() {
int t;
cin >> t;
for (int testcase = 1; testcase <= t; ++testcase) {
int m, n = 0;
cin >> m;
map<string, int> hash;
vector<set<int> > adj;
while (m--) {
string a, b;
cin >> a >> b;
const int u = getNode(a, n, hash, adj), v = getNode(b, n, hash, adj);
adj[u].insert(v);
adj[v].insert(u);
}
cout << "Case #" << testcase << ": ";
if (check(n, adj))
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
B
#include <cmath>
#include <iostream>
using namespace std;
const double pi = acos(-1.0);
int main() {
int T;
cin >> T;
cout.precision(8);
for (int casenum = 1; casenum <= T; ++casenum) {
double v, d;
cin >> v >> d;
cout << "Case #" << casenum << ": " << fixed << 180*asin(9.8*d/v/v)/2/pi << endl;
}
return 0;
}
C
#include <algorithm>
#include <fstream>
#include <list>
#include <string>
using namespace std;
int main() {
ifstream fin("C-small-practice-2.in");
ofstream fout("c.out");
int t;
fin >> t;
for (int m = 1; m <= t; ++m) {
int n;
fin >> n;
string tmp;
getline(fin, tmp);
list<string> name;
for (int i = 0; i < n; ++i) {
string str;
getline(fin, str);
name.push_back(str);
}
int ans = 0;
for (int i = 1; i < n; ++i) {
list<string>::iterator it = name.begin(), jt;
advance(it, i);
jt = it;
--jt;
if ((*it) < (*jt)) {
string str = (*it);
it = name.erase(it);
jt = lower_bound(name.begin(), it, str);
name.insert(jt, str);
++ans;
}
}
fout << "Case #" << m << ": " << ans << endl;
}
return 0;
}