Hướng dẫn giải của COIN


Chỉ dùng lời giải này khi không có ý tưởng, và đừng copy-paste code từ lời giải này. Hãy tôn trọng người ra đề và người viết lời giải.
Nộp một lời giải chính thức trước khi tự giải là một hành động có thể bị ban.

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='';
      maxn=10005;
      ep=0.000000001;
      pi2=6.283185307;
var n:longint;
    a:array[1..maxn] of real;
    re:real;

procedure rf;
var i:longint;
begin
     assign(input,fi); reset(input);
     readln(n);
     for i:=1 to n do read(a[i]);
     close(input);
end;

function calc(x:real):longint;
var i,z:longint; goc,cosin,tg,b,c,d:real;
begin
     goc:=0;
     for i:=1 to n do
     begin
          z:=i+1;
          if z=n+1 then z:=1;
          b:=x+a[i]; c:=x+a[z]; d:=a[i]+a[z];
          cosin:=(b*b+c*c-d*d)/(2*b*c);
          tg:=sqrt((1-sqr(cosin))/sqr(cosin));
          if cosin>=0 then goc:=goc+arctan(tg)
          else goc:=goc+pi2/2-arctan(tg);
     end;
     if abs(goc-pi2)<=ep then calc:=0
     else
         if goc>pi2 then calc:=1
         else calc:=-1;
end;

procedure pr;
var l,m,r:real; t:longint;
begin
     l:=0; r:=1000000000000000000000000;
     while r-l>=ep do
     begin
          m:=(l+r)/2;
          t:=calc(m);
          if t=0 then break;
          if t>0 then l:=m
          else r:=m;
     end;
     re:=m;
end;

procedure wf;
begin
     assign(output,fo); rewrite(output);
     writeln(re:0:3);
     close(output);
end;

begin
     rf;
     pr;
     wf;
end.

Code mẫu của happyboy99x

#include<cstdio>
#include<cmath>

const int N = 10000+5;
const double EPS = 1e-9;
double r[N];
int n;

inline double alpha(const double &a, const double &b, const double &c) {
    return acos((b*b+c*c-a*a)/(2*b*c));
}

int main() {
    scanf("%d",&n);for(int i=0;i<n;++i) scanf("%lf",r+i);
    double l = 0, h = 1e9;
    while(fabs(h-l) > EPS) {
        double r0 = (l+h)/2, angle = alpha(r[0]+r[n-1],r0+r[0],r0+r[n-1]);
        for(int i=1;i<n;++i) angle += alpha(r[i]+r[i-1],r0+r[i],r0+r[i-1]);
        if(angle < 2*M_PI) h = r0; else l = r0;
    }
    printf("%.3lf\n", (l+h)/2);
    return 0;
}

Code mẫu của ladpro98

program lem1;
uses    math;
const   fi='';
        maxn=10004;
        eps=1e-4;
        ok=360;
var     a:array[0..maxn] of extended;
        l,r,m,x,y,z,t,alpha:extended;
        n,i:longint;
        inp:text;

begin
        assign(inp,fi);reset(inp);
        readln(inp,n);
        for i:=1 to n do read(inp,a[i]);
        a[0]:=a[n];
        l:=0;r:=1e9;
        while (r-l>eps) do
        begin
                m:=(l+r)/2;
                alpha:=0;
                for i:=1 to n do
                begin
                        x:=m+a[i-1];
                        y:=m+a[i];
                        z:=a[i-1]+a[i];
                        t:=arccos((sqr(x)+sqr(y)-sqr(z))/(2*x*y));
                        alpha:=alpha+radtodeg(t);
                end;
                if alpha<ok then r:=m
                else    l:=m;
        end;
        write(m:0:3);
end.

Code mẫu của RR

//Written by Nguyen Thanh Trung
{$R+,Q+,N+}
{$Mode objFPC}
uses math;
const
  FINP          =       '';
  FOUT          =       '';
  MAXN          =       10111;
  eps           =       1e-12;
type
  real          =       extended;
var
  f1,f2         :       text;
  n             :       longint;
  r             :       array[1..MAXN] of real;

procedure openF;
    begin
      assign(f1,FINP); reset(f1);
      assign(f2,FOUT); rewrite(f2);
    end;
procedure closeF;
    begin
      close(f1);
      close(f2);
    end;
procedure inp;
    begin
      read(f1,n);
      for n:=1 to n do
        read(f1,r[n]);
    end;
procedure solve;
    var
      kq,left,right,mid,sum,a,b,c:real;
    begin
      r[n+1]:=r[1];
      left:=0; right:=0;
      for n:=1 to n do right+=r[n]*2; right/=pi*2;
      while left<right do
        begin
          mid:=(left+right)/2; sum:=0;
          for n:=1 to n do
            begin
              a:=r[n]+mid;
              b:=r[n+1]+mid;
              c:=r[n]+r[n+1];
              sum+=arccos((a*a+b*b-c*c)/2/a/b);
            end;
          if abs(sum-2*pi)<eps then begin writeln(f2,mid:0:3); exit; end;
          if sum<2*pi then
            begin
              kq:=mid;
              right:=mid-eps;
            end
          else left:=mid+eps;
        end;
      writeln(f2,kq:0:3);
    end;

begin
  openF;
  inp;
  solve;
  closeF;
end.

Code mẫu của hieult

#include <stdio.h>
//#include <conio.h>
#include <math.h>
#define pi 3.1415926535898
long long a[10003],n;
double Bcos(double t)
{
double T=0;
for(int i=1;i<=n;i++)
  T=T+acos(1-2*a[i]*a[i+1]/((a[i]+t)*(a[i+1]+t)));
return T;
}
main()
{
//freopen("LEM1.in","r",stdin);
scanf("%lld",&n);
for(int i=1;i<=n;i++)  
  scanf("%lld",&a[i]);
  a[n+1] = a[1];
double u = 0.01,v = 1000000000;
while(v-u>0.0000001)
{
     double r = (u+v)/2;
     if(Bcos(r)<2*pi)
        v=r;
     else u = r;
}
printf("%.3lf",u); 
//getch();
}

Code mẫu của ll931110

{$N+}
program LEM1;
uses math;
const
  input  = '';
  output = '';
  maxn = 10000 + 2;
  eps = 0.00000000001;
  eps2 = 0.0000000001;
  maxv = 1000000000;
var
  n: integer;
  a: array[1..maxn] of extended;
  res: extended;

procedure init;
var
  f: text;
  i: integer;
begin
  assign(f, input);
    reset(f);

  readln(f, n);
  for i := 1 to n do read(f, a[i]);
  a[n + 1] := a[1];

  close(f);
end;

function angle(x,y,z: extended): extended;
var
  t: double;
begin
  t := (y * y + z * z - x * x) / (2 * y * z);
  angle := arccos(t);
end;

procedure solve;
var
  inf,sup,med: extended;
  anl,tmp: extended;
  i: integer;
begin
  inf := 0;
  sup := 2 * maxv;
  tmp := 2 * pi;

  repeat
    med := (inf + sup) / 2;
    anl := 0;

    for i := 1 to n do
      anl := anl + angle(a[i] + a[i + 1],med + a[i],med + a[i + 1]);

    if abs(anl - tmp) < eps then
      begin
        res := med;
        exit;
      end;

    if anl < tmp then sup := med else inf := med;
  until sup - inf < eps2;

  res := (inf + sup) / 2;
end;

procedure printresult;
var
  f: text;
begin
  assign(f, output);
    rewrite(f);
    writeln(f, res:0:3);
  close(f);
end;

begin
  init;
  solve;
  printresult;
end.

Code mẫu của skyvn97

#include<stdio.h>
#include<math.h>
#define MAX   10101
#define INF   1e8
#define EPS   1e-5
#define PI   acos(-1.0)
double r[MAX];
int n,i;
double sa;
double t,b,m;
double angleA(double a,double b,double c) {
    return (acos((b*b+c*c-a*a)/(2*b*c)));
}
int main(void) {
    scanf("%d",&n);
    for (i=1;i<=n;i=i+1)
        scanf("%lf",&r[i-1]);
    b=0;t=INF;
    while (t-b>EPS) {
        m=(t+b)/2;
        sa=0;
        for (i=0;i<n;i=i+1)
            sa=sa+angleA(r[i%n]+r[(i+1)%n],m+r[i%n],m+r[(i+1)%n]);
        if (sa<2*PI) t=m; else b=m;     
    }       
    printf("%.3lf",b);
}

Code mẫu của khuc_tuan

uses math;
var
   n, i, kk, j,t : integer;
   r : array[1..10000] of double;
   xx,total, left, right, mid : double;
   ok : boolean;

function tinh(a,b,c : double) : double;
var
   xx : double;
begin
     xx :=  (b*b+c*c-a*a)/2/b/c;
     if(xx>=1-1e-8) then xx := 1;
     if(xx<=-1+1e-8) then xx := -1;
     tinh := arccos(xx);
end;

begin
      read(n);
      for i:=1 to n do read(r[i]);
      //for i:=1 to n do r[i] := 100000;
      left := 0;
      right := 1e9;
      for kk:=1 to 50 do begin
          mid := (left+right)/2;
          total := 0;
          ok := true;
          for i:=1 to n do begin
              t := i-1;
              if t=0 then t := n;
              j := i mod n + 1;

              xx :=  tinh( r[i]+r[j], r[i]+mid, r[j]+mid) ;
              //if( tinh(r[t]+r[i],r[t]+mid,r[i]+mid) + xx <= tinh( r[t]+r[j], r[t]+mid,r[j]+mid)-1e-8) then ok := false;
              total := total + xx;
          end;
          //if not ok then right := mid else
          if(total >= 2*3.1415926535) then left := mid
          else right := mid;
          {writeln( ok);
          writeln( total); }
      end;
      writeln( left:0:3);
end.

Bình luận

Hãy đọc nội quy trước khi bình luận.


Không có bình luận tại thời điểm này.