Skip to content

Instantly share code, notes, and snippets.

@delta2323
Created May 31, 2012 16:00
Show Gist options
  • Save delta2323/2844390 to your computer and use it in GitHub Desktop.
Save delta2323/2844390 to your computer and use it in GitHub Desktop.
#line 73 "ElectionFraudDiv1.cpp"
#include <string>
#include <vector>
#include <iostream>
#include <sstream>
#include <set>
#include <map>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <cmath>
using namespace std;
#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin)
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define tr(c, i) for(iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
typedef long long ll;
const static int inf = 1e18;
const static int mod = 1000000007;
const static double eps = 1e-9;
bool check(int k, const vector<int>& p) {
int n = p.size();
if(k == 0) {
rep(i, n) {
if(p[i] != 0) {
return false;
}
}
return true;
}
int mn = 0;
int mx = 0;
rep(i, n) {
int mna = max((int)(((double)p[i]-0.5)/100 * k + 1 - eps), 0);
int mxa = (int)(((double)p[i]+0.5)/100 * k - eps);
if(mxa == 0 && p[i] != 0) {
return false;
}
if(mna == k && p[i] != 100) {
return false;
}
if(p[i] != 0 && mna == 0) {
if((int)(1.0/k*100+0.5) > p[i]) {
return false;
}
mna = 1;
}
if(p[i] != 100 && mxa == k) {
if((int)((double)(k-1)/k*100+0.5) < p[i]) {
return false;
}
mxa = k-1;
}
mn += mna;
mx += mxa;
}
return mn <= k && k <= mx;
}
class ElectionFraudDiv1 {
public:
int MinimumVoters(vector <int> p) {
for(int i = 0; i < 10000*n; ++i) {
if(check(i, p)) {
return i;
}
}
return -1;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment