Hướng dẫn giải của Cắt bánh


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 ladpro98

#include <bits/stdc++.h>
#define ii pair<int, int>
#define X first
#define Y second
const int N = 1505;
using namespace std;
int n;
int F[N][N], G[N][N];
ii a[N];

int area(int i, int j, int k)
    {return abs(a[i].X * (a[j].Y - a[k].Y) + a[j].X * (a[k].Y - a[i].Y) + a[k].X * (a[i].Y - a[j].Y));}

int main() {
    scanf("%d", &n);
    for(int i = 0; i < n; i++) scanf("%d %d", &a[i].X, &a[i].Y);
    for(int i = 0; i < n; i++) {
        int pos = i;
        for(int j = i + 1; j < n; j++) {
            while (pos < j && area(i, pos, j) <= area(i, pos + 1, j)) pos++;
            F[i][j] = area(i, pos, j);
        }
    }
    #define next(i) ((i) - 1 + n) % n
    for(int i = 0; i < n; i++) {
        int pos = i;
        for(int j = next(i); j != i; j = next(j)) {
            while (pos != j && area(i, pos, j) <= area(i, next(pos), j)) pos = next(pos);
            G[i][j] = area(i, pos, j);
        }
    }
    int res = 0;
    for(int i = 0; i < n; i++) for(int j = i + 1; j < n; j++)
        res = max(res, F[i][j] + G[i][j]);
    printf("%.1f", res / 2.0);
    return 0;
}

Code mẫu của RR

{$R+,Q+}
{$Mode objFPC}
uses math;
const
  FINP='';
  FOUT='';
var
  d,c:array[1..1501,1..1501] of longint;
  n:longint;
  x,y:array[1..3001] of longint;
  f1,f2:text;
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,x[n],y[n]);
end;
function dt(i,j,k:longint):longint;
begin
  exit(abs((x[j]-x[i])*(y[j]+y[i])
          +(x[k]-x[j])*(y[k]+y[j])
          +(x[i]-x[k])*(y[i]+y[k])));
end;
procedure solve;
var
  best,i,j,ii,temp:longint;
begin
  best:=0;
  for i:=1 to n-2 do
    begin
      ii:=i+1;
      for j:=i+2 to n-1 do
        begin
          c[i,j]:=0;
          repeat
             temp:=dt(ii,i,j);
             if (temp>=c[i,j]) then c[i,j]:=temp
             else break;
             inc(ii);
             if ii>j then break;
          until false;
          dec(ii);
        end;
    end;
  for i:=1 to n-2 do
    begin
      ii:=i+3;
      for j:=i+2 to n-1 do
        begin
          d[i,j]:=0;
          repeat
            temp:=dt(ii,i,j);
            if (temp>=d[i,j]) then d[i,j]:=temp
            else break;
            inc(ii);
            if ii>n then break;
          until false;
          dec(ii);
        end;
    end;
  for i:=1 to n-2 do
  for j:=i+2 to n-1 do
    best:=max(best,c[i,j]+d[i,j]);
  if best mod 2=0 then writeln(f2,best div 2,'.0')
  else writeln(f2,best div 2,'.5');
end;
begin
  openF;
  inp;
  solve;
  closeF;
end.

Code mẫu của hieult

#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<cassert>
#include<ctime>
#include<algorithm>
#include<iterator>
#include<iostream>
#include<cctype>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<list>
//#include<conio.h>
#define ep 0.000000001
#define maxn 10011
#define oo 1111111
#define mod 1000000000
#define TR(c, it) for(typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++)
#define fi first 
#define se second
double const PI=4*atan(1);

using namespace std;

typedef pair<int, int> II;
typedef vector<int> VI;
typedef vector<II> VII;
typedef vector<VI> VVI;
typedef vector<VII> VVII;

struct Point{
    int x, y;
    Point(){};
    Point(int _x, int _y){
        x = _x;
        y = _y;
    }
};

Point a[maxn * 2];
int n;

int dientich(int i, int j, int k){
    int T = (a[i].x * a[j].y - a[j].x * a[i].y) +
            (a[j].x * a[k].y - a[k].x * a[j].y) +
            (a[k].x * a[i].y - a[i].x * a[k].y) ; 
    return abs(T);
}

int main(){
   // freopen("input.in","r",stdin); 
   // freopen("output.out","w",stdout);

    scanf("%d",&n);
    for(int i = 1; i <= n; i++){
        scanf("%d %d", &a[i].x, &a[i].y);
        a[n+i] = a[i];
    }

    int kq = -oo;

    for(int i = 1; i <= n; i++){
        int u = i + 1, v = i + 3;
        for(int j = i + 2; j <= n; j ++){
            while(dientich(i, j, u + 1) >= dientich(i, j, u) && u < j) u ++;
            while(dientich(i, v + 1, j) >= dientich(i, v, j) && v < n) v ++;
            kq = max(kq, dientich(i, j, u) + dientich(i, v, j));
        }
    }

    printf("%.1lf",kq * 1.0 / 2);
     // getch();
}

Code mẫu của khuc_tuan

#include <iostream>
#include <cmath>
using namespace std;

struct Point {
    int x, y;
};

int n;
Point p[1550];

inline int getS(Point a, Point b, Point c) {
    return abs((a.x-b.x) * (a.y+b.y) + (b.x-c.x) * (b.y+c.y) + (c.x-a.x) * (c.y+a.y));
}

int main() {
    scanf("%d", &n);
    for(int i=0;i<n;++i)
        scanf("%d%d", &p[i].x, &p[i].y);
    int a, b, i, j;
    int result = 0;
    for(a=0;a<n;++a) {
        i = (a+1) % n;
        j = (a+3) % n;
        for(b=a+2;b<n;++b) {
            int cur = getS(p[a],p[b],p[i]), tmp = getS(p[a],p[b],p[(i+1)%n]);
            while(tmp >= cur && (i+1)%n!=b) {
                i = (i+1) % n;
                cur = tmp;
                tmp = getS(p[a],p[b],p[(i+1)%n]);
            }
            cur = getS(p[a],p[b],p[j]);
            tmp = getS(p[a],p[b],p[(j+1)%n]);
            while(tmp >= cur && (j+1)%n!=a) {
                j = (j+1) % n;
                cur = tmp;
                tmp = getS(p[a],p[b],p[(j+1)%n]);
            }
            result >?= getS(p[a],p[b],p[i]) + getS(p[a],p[b],p[j]);
        }
    }
    if(result%2==0) cout << result / 2 << ".0" << endl;
    else cout << result / 2 << ".5" << endl;
    return 0;
}

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.