Skip to content

Instantly share code, notes, and snippets.

@thinkhy
Created August 13, 2011 15:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thinkhy/1143934 to your computer and use it in GitHub Desktop.
Save thinkhy/1143934 to your computer and use it in GitHub Desktop.
/**********************************************************************************
* file: pursueLover.cpp
* brief: Simulation code for the paper: http://songshuhui.net/archives/57722.
* author: thinkhy
* last version: https://gist.github.com/1143934
* date: 2011-08-13
**********************************************************************************/
#include <cstdio>
#include <cstdlib>
using namespace std;
int main()
{
srand((unsigned) time(NULL));
int man[30];
for (int i = 0; i < 30; i++)
{
man[i] = rand() % 30;
}
int max = -1;
int magic = int(30 * 0.37);
for (int i = 0; i <= magic; i++)
{
if (man[i] > max)
{
max = man[i];
}
}
bool bGot = false;
for (int i = magic + 1; i < 30; i++)
{
if (man[i] > max)
{
bGot = true;
max = man[i];
break;
}
}
if (bGot)
{
printf("She got the best man!! id: %d\n", max);
}
else
{
printf("Sigh!\n");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment