Background: Weekly game a problem,
Learning: 1. Start not to notice the topic in the number of posts more than 1/2 of the description, pure violence count, all kinds of super!
2. It was later found that sequentially scanning each number to see if there was more than 1/2 of its number in the array. My Code:
#include <stdio.h> #include <string.h>int str[10000000];int main (void) {int n;scanf ("%d", &n), while ( n--) {int m,cout=0;scanf ("%d", &m), for (int i=0;i<m;i++) {scanf ("%d", &str[i]);} for (int i=0;i<m;i++) {for (int j=0;j<m;j++) {if (str[j]!=-1) { if (Str[j]==str[i]) { cout++; if (cout>=m/2+1) {printf ("%d\n", Str[i]); goto L1; }}} str[i]=-1;cout=0;} L1:
3. This can be too much but open a huge amount of memory (OJ limit is 10 of the 8 square int?) )
The problem solving report gives a more advanced method: Assume that the first number is and count count is 1, and then meet and it is the same as the count self-increment, when count is 0 o'clock, you can become the current number of reads, the last remaining can necessarily be found more than 1/2 of the number. Give the code:
SOJ 4389 Simulation