Editorial for Dãy số


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

#include<iostream>
using namespace std;
#define eps 1e-8

int main()
{
    int n,i;
    double a[1010],l,r,re;
    bool kt;
    cin >> n >> a[1];
    l=0; r=a[1];
    while (r-l>eps)
    {
          a[2]=(l+r)/2;
          kt=1;
          for (i=3;i<=n;i++)
          {
              a[i]=a[i-1]*2+2-a[i-2];
              if (a[i]<0)
              {
                 kt=0;
                 break;
              }
          }
          if (kt)
          {
              re=a[n];
              r=a[2];
          }
          else l=a[2];
    }      
    printf("%0.2lf",re);
}

Code mẫu của ladpro98

var i,j,k,m,n:longint;
      b,c,s,t:extended;
  begin
    readln(n,c);
    dec(n);
    m:=trunc(sqrt(c));
    if m>=n then
      begin
        writeln('0.00');
        exit;
      end;
    if c/m<=m+1 then
      begin
        b:=m+c/m;
        s:=n*n-b*n+c;
      end
    else s:=1e100;
    inc(m);
    if c/m>=m-1 then
      begin
        b:=m+c/m;
        t:=n*n-b*n+c;
      end
    else t:=1e100;
    if s<t then writeln(s:0:2)
      else writeln(t:0:2);
  end.

Code mẫu của RR

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <deque>
#include <complex>

#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)
#define REP(i,a) for(int i=0,_a=(a); i<_a; i++)
#define ll long long
#define F first
#define S second
#define PB push_back
#define MP make_pair
using namespace std;

const double PI = acos(-1.0);
const double eps = 1e-4;

int n;
double a[1011], b[1011];

bool check(double x) {
    a[n] = x;
    double sumb = a[n] - a[1];
    b[2] = (sumb - (n-1) * (n-2)) / (double) (n-1);
    FOR(i,3,n) b[i] = b[i-1] + 2;
    FOR(i,2,n-1) a[i] = a[i-1] + b[i];

    FOR(i,1,n) if (a[i] < -1e-6) return false;
    return true;
}

int main() {
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    cin >> n >> a[1];
    double l = 0.0, r = 1e12, res = r;
    while (l + eps < r) {
        double mid = (l + r) / 2.0;
        if (check(mid)) {
            res = mid;
            r = mid - eps;
        }
        else l = mid + eps;
    }
    printf("%.2lf\n", res);
    return 0;
}

Code mẫu của hieult

#include <stdio.h>
//#include <conio.h>
#include <math.h>

double maxx(double a,double b)
{
       if(a<b)
            return b;
            return a;
}

int main()
{
    int n;
    double x,f[1001];
    scanf("%d %lf",&n,&x);
    f[1] = x;
    int a = int((sqrt(4*x+1)-1)/2);
    if(n<=a)
        printf("0.00");
    else
    {
        f[2] = x*a/(a+1)-a;
        for(int i=3;i<=n;i++)
            f[i]=2*f[i-1]-f[i-2]+2;
        printf("%.2lf",f[n]);
    }
      //  getch();
}

Code mẫu của ll931110

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;

double a[1010],ret;
int n;

bool ok(double med)
{
     a[n] = med;
     double delta = ((a[1] - a[n]) + (n - 2) * (n - 1) * 1.0) / (n - 1) * 1.0;
     bool chk = true;
     for (int i = 2; i <= n; i++)
     {
         a[i] = a[i - 1] - delta;
         if (a[i] < 0) chk = false;
         delta -= 2.0;
     };
     if (chk) ret = med;
     return chk;
};

int main()
{
//    freopen("seq.in","r",stdin);
//    freopen("seq.ou","w",stdout);
    scanf("%d %lf", &n, &a[1]);
    double inf = 0.0,sup = 1e12;
    for (int i = 0; i < 70; i++)
    {
        double med = (inf + sup)/2;
        if (ok(med)) sup = med; else inf = med;
    };
    printf("%.2lf\n", ret);
};

Comments

Please read the guidelines before commenting.


There are no comments at the moment.