Skip to content

Instantly share code, notes, and snippets.

@hodduc
Created April 4, 2013 13:58
Show Gist options
  • Save hodduc/5310579 to your computer and use it in GitHub Desktop.
Save hodduc/5310579 to your computer and use it in GitHub Desktop.
#include<vector>
#include<memory.h>
using namespace std;
int buf[555];
class MafiaGame {
public:
double probabilityToLose(int N, vector <int> decisions)
{
int i, maxv = 0, cc, maxc = 0;
double ret = 1.0;
maxv=-1;
for(i=0;i<decisions.size();i++) buf[decisions[i]]++;
for(i=0;i<N;i++)
if(buf[i] > maxv) maxv = buf[i], maxc=1;
else if(buf[i]==maxv) maxc++;
if(maxv < 2) return 0.0;
if(maxc == 1) return 1.0;
ret = 1.0 / maxc;
cc = maxc;
for(;;){
if(cc == 1) return ret;
if(N % cc == 0) return 0.0;
cc = N % cc;
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment