SOJ 4389 Simulation

Source: Internet
Author: User


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.