Editorial for Bulls and Cows


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

const fi='';
      fo='';
      m=2111992;
      maxn=100100;
var n,k,i:longint;
    a:array[1..maxn] of longint;
begin
     assign(input,fi);
     reset(input);
     read(n,k);
     close(input);
     fillchar(a,sizeof(a),0);
     a[1]:=2;
     for i:=2 to n do
     begin
          if i-k-1>0 then a[i]:=(a[i-1]+a[i-k-1]) mod m
          else a[i]:=(a[i-1]+1) mod m;
     end;
     assign(output,fo);
     rewrite(output);
     write(a[n]);
     close(output);
end.

Code mẫu của happyboy99x

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define sz(a) int((a).size())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(), _e = (c).end(); i != _e; ++i)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define rep(i,n) for(int i = 0, _n = (n); i < _n; ++i)
#define repd(i,n) for(int i = (n)-1; i >= 0; --i )
#define fo(i,a,b) for(int i = (a), _b = (b); i <= _b; ++i)
#define fod(i,a,b) for(int i = (a), _b = (b); i >= _b; --i)

#define INF 1000000000
#define N 100005
#define MOD 2111992

int n, k, f[N];

int main() {
    //freopen( "input.txt", "r", stdin );
    //freopen( "output.txt", "w", stdout );
    scanf("%d%d",&n,&k);
    f[0] = 1;
    fo(i,1,n) f[i] = (i>=k+1?f[i-1]+f[i-k-1]:(f[i-1]+1))%MOD;
    printf("%d\n", f[n]);
    return 0;
}

Code mẫu của ladpro98

program ctnbulls;
uses    math;
const   fi='';
var     f:array[0..100000] of longint;
        n,k,i:longint;
        s:int64;
        inp:text;
begin
        assign(inp,fi);
        reset(inp);
        readln(inp,n,k);
        for i:=0 to k+1 do f[i]:=1;
        for i:=k+2 to n do
        f[i]:=(f[i-1]+f[i-k-1]) mod 2111992;
        for i:=0 to n do
        s:=(s+f[i]) mod 2111992;
        write(s);

end.

Code mẫu của RR

var
  f:array[1..100111,0..1] of longint;
  n,k,i:longint;
begin
  read(n,k); k+=1;
  f[1,0]:=1; f[1,1]:=1;
  for i:=2 to k do
    begin
      f[i,0]:=1;
      f[i,1]:=(f[i-1,1]+f[i-1,0]) mod 2111992;
    end;

  for i:=k+1 to n do
    begin
      f[i,0]:=(f[i-k,0]+f[i-k,1]) mod 2111992;
      f[i,1]:=(f[i-1,0]+f[i-1,1]) mod 2111992;
    end;

  writeln((f[n,0]+f[n,1]) mod 2111992);
end.

Code mẫu của hieult

#include <stdio.h>
//#include <conio.h>
main()
{
long n,k,a[100001];
scanf("%ld %ld",&n,&k);
for(long i=1;i<=k+1;i++)
  a[i]=i+1;
for(long i=k+2;i<=n;i++)
  {
  a[i]=a[i-1]+a[i-k-1];
  if(a[i]>=2111992);
    a[i]=a[i]%2111992;
  }
printf("%ld",a[n]);
//getch();
}

Code mẫu của ll931110

{$MODE DELPHI}
program CTNBULLS;
const
  maxn = 100000;
  rem = 2111992;
var
  f: array[0..maxn] of integer;
  i,n,k: integer;

begin
  readln(n, k);
  f[0]:= 1;

  for i:= 1 to n do
    begin
      f[i]:= f[i - 1];
      if i > k then f[i]:= f[i] + f[i - k - 1] else inc(f[i]);
      f[i]:= f[i] mod rem;
    end;

  writeln(f[n]);
end.

Code mẫu của skyvn97

#include<stdio.h>
#define MAX   150000
#define MOD   2111992
typedef unsigned long long ull;
ull opt[MAX];
ull k,n,i;
int main(void)
{
    scanf("%llu",&n);
    scanf("%llu",&k);
    for (i=1;i<=k+1;i=i+1) opt[i]=(i+1)%MOD;
    for (i=k+2;i<=n;i=i+1) opt[i]=(opt[i-1]+opt[i-k-1])%MOD;
    printf("%llu",opt[n]);  
}

Code mẫu của khuc_tuan

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;

const int MOD = 2111992;

int F[100010], T[100010];
int n, k, res;

int main() {
    cin >> n >> k;
    res = 0;
    for(int i=1;i<=n;++i) {
        F[i] = 1;
        if(i >= k + 2) {
            F[i] = (F[i] + T[i-k-1]) % MOD; 
        }
        T[i] = (T[i-1] + F[i]) % MOD;
        res = (res + F[i]) % MOD;
    }
    res = (res + 1) % MOD;
    cout << res << endl;
    return 0;   
}

Comments

Please read the guidelines before commenting.


There are no comments at the moment.