zoukankan      html  css  js  c++  java
  • bzoj2456

    有趣的题目

    空间1mb,所以开数组的算法就不要想了(我一开始没看到……)

    仔细读题,然后发现这里他限定众数为出现超过n div 2次

    也就是说,这个数可以对应每一个不相同的数消掉,最终还剩下这个数

    也就是说,我们遍历,遇到不相同的就两两抵消,最终剩下的一定是ans

    得解,

     1 var n,i,s,ans,x:longint;
     2 begin
     3   readln(n);
     4   s:=0;
     5   for i:=1 to n do
     6   begin
     7     read(x);
     8     if (s=0) then
     9     begin
    10       inc(s);
    11       ans:=x;
    12     end
    13     else if ans=x then inc(s)
    14     else dec(s);
    15   end;
    16   writeln(ans);
    17 end.
    View Code

    我需要锻炼思维能力,恩恩

  • 相关阅读:
    SPOJ
    基础计算几何
    数颜色
    Codeforces 986B
    一些有趣的题
    jQuery
    linux命令学习
    javaScript
    css
    html
  • 原文地址:https://www.cnblogs.com/phile/p/4473245.html
Copyright © 2011-2022 走看看