Editorial for Những con đường quanh nông trang


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Lưu ý: Các code mẫu dưới đây chỉ mang tính tham khảo và có thể không AC được bài tập này

Code mẫu của flashmt

var n,k:longint;

function calc(n:longint):longint;
begin
        if (n>k) and not odd(n+k) then
           calc:=calc((n+k) shr 1)+calc((n-k) shr 1)
        else calc:=1;
end;

begin
        read(n,k);
        writeln(calc(n));
end.

Code mẫu của happyboy99x

#include <cstdio>
#include <queue>
using namespace std;

int n, k;

int main() {
    scanf( "%d%d", &n, &k );
    queue<int> q; q.push(n);
    int res = 0;
    while( !q.empty() ) {
        int x = q.front(); q.pop();
        if( (x+k)%2 || x <= k ) ++res;
        else {
            q.push((x+k)/2); q.push((x-k)/2);
        }
    }
    printf( "%d\n", res );
    return 0;
}

Code mẫu của ladpro98

program vratf;
uses    math;
var     n,k:longint;

function dc(n:longint):longint;
begin
        if (n-k>0) and not (odd(n-k)) then
        exit(dc((n+k) div 2)+dc((n-k) div 2));
        exit(1);
end;

begin
        readln(n,k);
        write(dc(n));
end.

Code mẫu của RR

var
  n,k:longint;

function get(n:longint):longint;
    begin
      if n=0 then exit(0);
      if n<=k then exit(1);
      if (n-k) and 1=1 then exit(1)
      else exit(get((n-k) shr 1)+get((n+k) shr 1));
    end;

begin
  read(n,k);
  writeln(get(n));
end.

Code mẫu của hieult

#include <stdio.h>
//#include <conio.h>
main()
{
long duong(int ,int ),n,k;
  scanf("%ld %ld",&n,&k);
  printf("%ld",duong(n,k));
  //getch();
}
long duong(int x,int y)
{ if(x<=y||(x-y)%2!=0)
    return(1);
  else
    return(duong((x-y)/2, y)+duong((x+y)/2,y));
}

Code mẫu của ll931110

Program VRATF;
        Const
                input  = '';
                output = '';
        Var
                n,k: longint;

Procedure init;
          Var
                f: text;
          Begin
                Assign(f, input);
                        Reset(f);
                        Readln(f, n, k);
                Close(f);
          End;

Function solve(i: longint): longint;
         Begin
                If odd(i + k) or (i <= k) then solve:= 1 else
                        solve:= solve((i + k) div 2) + solve ((i - k) div 2);
         End;

Procedure fin;
          Var
                f: text;
          Begin
                Assign(f, output);
                        Rewrite(f);
                        Writeln(f, solve(n));
                Close(f);
          End;

Begin
        init;
        fin;
End.

Code mẫu của khuc_tuan

import java.util.Scanner;

public class Main {

    static int get(int n, int k) {
        if (n > k && (n - k) % 2 == 0)
            return get((n - k) / 2, k) + get((n - k) / 2 + k, k);
        return 1;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        System.out.println(get(n, k));
    }
}

Comments

Please read the guidelines before commenting.


There are no comments at the moment.