Last active
December 12, 2015 10:49
-
-
Save yinyanghu/4761607 to your computer and use it in GitHub Desktop.
Topcoder SRM569 Div2
This file contains hidden or 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
#include <vector> | |
#include <list> | |
#include <map> | |
#include <set> | |
#include <deque> | |
#include <stack> | |
#include <bitset> | |
#include <algorithm> | |
#include <functional> | |
#include <cstring> | |
#include <numeric> | |
#include <utility> | |
#include <sstream> | |
#include <iostream> | |
#include <iomanip> | |
#include <cstdio> | |
#include <cmath> | |
#include <cstdlib> | |
#include <ctime> | |
#define maxn 1010 | |
#define maxm 110 | |
#define MOD 1000000009 | |
using namespace std; | |
class MegaFactorialDiv2 { | |
public: | |
int countDivisors(int, int); | |
}; | |
long long f[maxn]; | |
int prime[maxn]; | |
int MegaFactorialDiv2::countDivisors(int N, int K) { | |
long long ans = 1; | |
memset(prime, true, sizeof(prime)); | |
for (int alpha = 2; alpha <= N; ++ alpha) | |
{ | |
if (!prime[alpha]) continue; | |
memset(f, 0, sizeof(f)); | |
f[alpha] = 1; | |
for (int i = alpha * 2; i <= N; i += alpha) | |
{ | |
prime[i] = false; | |
for (int x = i; x % alpha == 0; x /= alpha) | |
++ f[i]; | |
} | |
for (int i = 1; i <= K; ++ i) | |
for (int j = 1; j <= N; ++ j) | |
f[j] = (f[j] + f[j - 1]) % MOD; | |
ans = (ans * (f[N] + 1)) % MOD; | |
} | |
return ans; | |
} |
This file contains hidden or 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
#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 TheDeviceDiv2 { | |
public: | |
string identify(vector <string>); | |
}; | |
string TheDeviceDiv2::identify(vector <string> plates) { | |
int n = plates.size(); | |
int m = plates[0].size(); | |
for (int i = 0; i < m; ++ i) | |
{ | |
int one = 0, zero = 0; | |
for (int j = 0; j < n; ++ j) | |
if (plates[j][i] == '1') | |
++ one; | |
else if (plates[j][i] == '0') | |
++ zero; | |
if (one < 2 || zero < 1) return "NO"; | |
} | |
return "YES"; | |
} |
This file contains hidden or 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
#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> | |
#define inf 1000000000 | |
#define f(x, y) (x % y == 0 ? x / y : x / y + 1) | |
using namespace std; | |
class TheJediTestDiv2 { | |
public: | |
int countSupervisors(vector <int>, int, int); | |
}; | |
int TheJediTestDiv2::countSupervisors(vector <int> students, int Y, int J) { | |
sort(students.begin(), students.end()); | |
int n = students.size(); | |
int ans = inf; | |
for (int k = 0; k < n; ++ k) | |
{ | |
int total = f(max(students[k] - Y, 0), J); | |
for (int i = 0; i < n; ++ i) | |
if (i != k) | |
total += f(students[i], J); | |
if (total < ans) ans = total; | |
} | |
return ans; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment