Skip to content

Instantly share code, notes, and snippets.

@yinyanghu
Last active December 13, 2015 18:58
Show Gist options
  • Save yinyanghu/4958698 to your computer and use it in GitHub Desktop.
Save yinyanghu/4958698 to your computer and use it in GitHub Desktop.
Topcoder SRM570 Div2
#include <vector>
#include <cstring>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
vector<int> edge[60];
long long f[60];
class CentaurCompanyDiv2 {
public:
long long count(vector <int>, vector <int>);
};
int N;
bool flag[60];
void dfs(int x)
{
flag[x] = false;
f[x] = 1;
for (int i = 0; i < edge[x].size(); ++ i)
if (flag[edge[x][i]])
{
dfs(edge[x][i]);
f[x] = f[x] * (f[edge[x][i]] + 1);
}
}
long long CentaurCompanyDiv2::count(vector <int> a, vector <int> b) {
N = a.size() + 1;
for (int i = 1; i <= N; ++ i)
edge[i].clear();
for (int i = 0; i < N - 1; ++ i)
{
edge[a[i]].push_back(b[i]);
edge[b[i]].push_back(a[i]);
}
memset(f, 0, sizeof(f));
memset(flag, true, sizeof(flag));
dfs(1);
long long ans = 1;
for (int i = 1; i <= N; ++ i)
ans = ans + f[i];
return ans;
}
#include <vector>
#include <cstring>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
class Chopsticks {
public:
int getmax(vector <int>);
};
int Chopsticks::getmax(vector <int> length) {
int n = length.size();
int count[101];
memset(count, 0, sizeof(count));
for (int i = 0; i < n; ++ i)
++ count[length[i]];
int ans = 0;
for (int i = 1; i <= 100; ++ i)
ans += (count[i] >> 1);
return ans;
}
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
class RobotHerbDiv2 {
public:
int getdist(int, vector <int>);
};
int RobotHerbDiv2::getdist(int T, vector <int> a) {
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
long long x, y;
int dire;
x = y = dire = 0;
int n = a.size();
while (T --)
{
for (int i = 0; i < n; ++ i)
{
x += (long long)dx[dire] * a[i];
y += (long long)dy[dire] * a[i];
dire = (dire + a[i]) & 3;
}
}
return (abs(x) + abs(y));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment