zoukankan      html  css  js  c++  java
  • 新手村之BOSS战-入门综合练习1

    P1478 陶陶摘苹果(升级版) 代码:
    总:把力气从小到大排序,判断是否能摘到,累加。

    var
      j,ans,n,s,h,h1,i:longint;
      x,y:array[1..5000]of longint;
    procedure init;
    var
      i:longint;
    begin
      readln(n,s);
      readln(h,h1);
      inc(h,h1);
      for i:=1 to n do
        read(x[i],y[i]);
    end;
    
    procedure sort;
    var
      i,j,t:longint;
    begin
      for i:=1 to n-1 do
        for j:=i+1 to n do
          if y[i]>y[j] then
            begin
              t:=x[i]; x[i]:=x[j]; x[j]:=t;
              t:=y[i]; y[i]:=y[j]; y[j]:=t;
            end;
    end;
    
    procedure main;
    var
      i,t:longint;
    begin
      t:=0; ans:=0;
      for i:=1 to n do
        if x[i]<=h then
          if t<=s then
            begin
              if (t+y[i])>s then
                begin
                  write(ans); exit;
                end;
              inc(ans); inc(t,y[i]);
            end;
      write(ans);
    end;
    
    begin
      init;
      sort;
      main;
    end.

    P1618 三连击(升级版)代码:
    总:找那个什么约数。

    var
      i,a,b,c,h1,h2,p,ss:longint;
      j,k,j1,k1:real;
      x:array[-1..100] of longint;
      bo:boolean;
    procedure try1(i:longint);
    begin
      x[i mod 10]:=1; x[i div 10 mod 10]:=1; x[i div 100]:=1;
    end;
    
    begin
      readln(a,b,c);
      bo:=false;
      for i:=123 to 987 do
        begin
          if (j1*i>=1000) or (k1*i>=1000) then break;
          j:=b*i/a; k:=c*i/a;
          if (trunc(j)=j) and (trunc(k)=k) then
            begin
              h1:=trunc(j); h2:=trunc(k);
              p:=0;
              try1(i); try1(h1); try1(h2);
              for ss:=1 to 9 do
                if x[ss]>=1 then
                  begin
                    inc(p); x[ss]:=0;
                  end;
              if p=9 then
                begin
                  writeln(i,' ',h1,' ',h2); bo:=true;
                end;
    
            end;
        end;
      if bo=false then
        writeln('No!!!');
    end.

    P1579 哥德巴赫猜想(升级版)代码:
    总:枚举两个质数,判断第三个数。

    var
      n,i,j:longint;
    function try1(x:longint):boolean;
    var
      xx:longint;
    begin
      if x<2 then exit(false);
      for xx:=2 to trunc(sqrt(x)) do
        if x mod xx=0 then
          exit(false);
      exit(true);
    end;
    
    begin
      readln(n);
      for i:= 2 to n-1 do
        if try1(i) then
          for j:= 2 to n-i do
            if (try1(j)) and (try1(n-i-j)) then
              begin
                writeln(i,' ',j,' ',n-i-j);
                halt;
              end;
    end.

    P2089 烤鸡 代码:
    总:深搜。

    type
      data=array [1..10] of longint;
    var  
      n:longint;
      ans:array [0..10000] of data;
      t:data;
    procedure search(d:longint;a:data);
    var  
      sum,i:longint;
    begin  
      if d=10 then
        begin
          sum:=0;
          for i:=1 to 10 do
            inc(sum,a[i]);
          if sum=n then
            begin
              inc(ans[0,1]);
              ans[ans[0,1]]:=a;
            end;
        exit;
      end;
      a[d+1]:=1; search(d+1,a);
      a[d+1]:=2; search(d+1,a);
      a[d+1]:=3; search(d+1,a);
    end;
    
    procedure print;
    var
      i,j:longint;
    begin
      for i:=1 to ans[0,1] do
        begin
          for j:=1 to 10 do
            write(ans[i,j],' ');
          writeln;
        end;
    end;
    
    begin
      read(n);
      search(0,t);
      writeln(ans[0,1]);
      print;
    end.

    总:烤鸡挺好吃!

  • 相关阅读:
    练习_Python3 爬取笔趣阁最新小说章节
    Python3 map()函数
    Java图片验证码生成
    神经网络
    leetcode
    hive开发规范
    北明数科 bug
    JAVA集合~
    令人头痛的JVM
    重定向和管道符
  • 原文地址:https://www.cnblogs.com/zyx-crying/p/9319522.html
Copyright © 2011-2022 走看看