zoukankan      html  css  js  c++  java
  • bzoj 1028 暴力枚举判断

    昨天梦到这道题了,所以一定要A掉(其实梦到了3道,有两道记不清了)

    暴力枚举等的是哪张牌,将是哪张牌,然后贪心的判断就行了。

    对于一个状态判断是否为胡牌,1-n扫一遍,然后对于每个牌,先mod 3,

    如果还有剩余,就需要和i+1,i+2凑成顺子,减掉i+1,i+2的值就行了,然后

    只要枚举到的i为负就是不可行,还有要枚举到n+2位,因为第n,n-1为可能

    减了n+1,n+2但是没扫到。

    /**************************************************************
        Problem: 1028
        User: BLADEVIL
        Language: Pascal
        Result: Accepted
        Time:1032 ms
        Memory:232 kb
    ****************************************************************/
     
    //By BLADEVIL
    var
        n, m                        :longint;
        count, jud                  :array[0..400] of longint;
        i, j, k                     :longint;
        x                           :longint;
        ans                         :array[0..400] of longint;
         
    function judge:boolean;
    var
        i                           :longint;
    begin
        for i:=1 to n+2 do
        begin
            if jud[i]<0 then exit(false);
            jud[i]:=jud[i] mod 3;
            if jud[i]>0 then
            begin
                dec(jud[i+1],jud[i]);
                dec(jud[i+2],jud[i]);
                jud[i]:=0;
            end;
        end;
        exit(true);
    end;
         
    begin
        read(n,m);
        for i:=1 to 3*m+1 do
        begin
            read(x);
            inc(count[x]);
        end;
        for i:=1 to n do
        begin
            for j:=1 to n do jud[j]:=count[j];
            inc(jud[i]);
            for j:=1 to n do if jud[j]>=2 then
            begin
                dec(jud[j],2);
                if judge then
                begin
                    inc(ans[0]);
                    ans[ans[0]]:=i;
                end;
                if ans[ans[0]]=i then break;
                for k:=1 to n+2 do jud[k]:=count[k];
                inc(jud[i]);
            end;
        end;
        if ans[0]=0 then
        begin
            writeln('NO');
            halt;
        end;
        write(ans[1]);
        for i:=2 to ans[0] do write(' ',ans[i]); writeln;
    end.
  • 相关阅读:
    2019.9.18 csp-s模拟测试46 反思总结
    2019.9.17 csp-s模拟测试45 反思总结
    矩阵求导(包含极大似然估计)
    sir
    Square into Squares. Protect trees!(平方数分解平方和)
    最小二乘法
    2.5&2.6 numpy&pandas 笔记
    2.4 python学习笔记
    2.3 python学习笔记
    2.1&2.2python学习笔记
  • 原文地址:https://www.cnblogs.com/BLADEVIL/p/3500327.html
Copyright © 2011-2022 走看看