Created
April 18, 2015 10:23
-
-
Save anonymous/01cb8b951c5ac65dc501 to your computer and use it in GitHub Desktop.
This file contains 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 <stdio.h> | |
#include <stdlib.h> /* srand, rand */ | |
#include <time.h> /* time */ | |
#include <iostream> | |
using namespace std; | |
const int MAXN = int(1e4); | |
const int MAXN_PLUS = MAXN + 15; | |
int seq[MAXN_PLUS]; | |
int n; | |
void shuffle() { | |
for(int i = 0; i < n; i++) { | |
int swapWith = rand()%n; | |
swap(seq[i], seq[swapWith]); | |
} | |
} | |
int randomSolve(int k) { | |
for(int j = 0; j < k; j++) { | |
int s = 0; | |
for(int i = 0; i < n; i++) { | |
s = (s + seq[i])%n; | |
if (s == 0) { | |
return i + 1; | |
} | |
} | |
shuffle(); | |
} | |
return 0; | |
} | |
void printAnsw(int len) { | |
if (len) { | |
printf("%d\n", len); | |
for(int i = 0; i < len; i++) { | |
printf("%d\n", seq[i]); | |
} | |
}else { | |
printf("0\n"); | |
} | |
} | |
int main() { | |
scanf("%d", &n); | |
int answInd = -1; | |
for(int i = 0; i < n; i++) { | |
scanf("%d", &seq[i]); | |
if (seq[i] % n == 0) { | |
answInd = i; | |
} | |
} | |
if (answInd > -1) { | |
printf("1\n%d\n", seq[answInd]); | |
return 0; | |
}else { | |
int len = randomSolve(40000); | |
printAnsw(len); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment