Hướng dẫn giải của Giải phóng mặt bằng
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.
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=1500; delta=12345678901; var n,re,dem:longint; x,y,s,ss:array[1..maxn] of longint; a:array[1..maxn] of real; procedure rf; var i:longint; begin read(n); for i:=1 to n do read(x[i],y[i],s[i]); end; procedure sort(l,r:longint); var i,j,u:longint; x,y:real; begin i:=l; j:=r; x:=a[(i+j) shr 1]; repeat while a[i]<x do i:=i+1; while a[j]>x do j:=j-1; if i<=j then begin y:=a[i]; a[i]:=a[j]; a[j]:=y; u:=ss[i]; ss[i]:=ss[j]; ss[j]:=u; i:=i+1; j:=j-1; end; until i>j; if i<r then sort(i,r); if l<j then sort(l,j); end; procedure pr; var i,t,u,k,j:longint; begin re:=0; for i:=1 to n do begin dem:=0; for j:=1 to n do if i<>j then begin dem:=dem+1; if x[i]=x[j] then a[dem]:=delta else a[dem]:=(y[j]-y[i])/(x[j]-x[i]); ss[dem]:=s[j]*s[j]+5; end; sort(1,dem); t:=0; u:=ss[1]; k:=1; for j:=2 to dem do if a[j]=a[k] then u:=u+ss[j] else begin if u>t then t:=u; u:=ss[j]; k:=j; end; if u>t then t:=u; if t+s[i]*s[i]+5>re then re:=t+s[i]*s[i]+5; end; end; procedure wf; begin writeln(re); end; begin assign(input,fi); reset(input); assign(output,fo); rewrite(output); rf; pr; wf; close(input); close(output); end.
Code mẫu của happyboy99x
#include<cstdio> #include<cmath> #include<algorithm> using namespace std; struct House { int x, y, s; House(const int &x = 0, const int &y = 0, const int &s = 0): x(x), y(y), s(s) {} bool operator < (const House &h) const { return cross(h) > 0; } House operator - (const House &h) const { return House(x - h.x, y - h.y, s); } int cross(const House &h) const { return x * h.y - y * h.x; } void read() { scanf("%d%d%d", &x, &y, &s); s = s * s + 5; } }; const int N = 1500; House a[N], t[N]; int n; void enter() { scanf("%d", &n); for(int i = 0; i < n; ++i) a[i].read(); } bool cmpY(const House &a, const House &b) { return a.y == b.y ? a.x < b.x : a.y < b.y; } void solve() { int res = 0; sort(a, a+n, cmpY); for(int r = 0; r < n; ++r) { int c = 0; for(int i = r+1; i < n; ++i) t[c++] = a[i] - a[r]; sort(t, t+c); int now = 0; for(int i = 0, j = 0; j < c; ++j) if(t[i].cross(t[j]) != 0) { res = max(res, now + a[r].s); now = t[j].s; i = j; } else now += t[j].s; res = max(res, now + a[r].s); } printf("%d\n", res); } int main() { enter(); solve(); return 0; }
Code mẫu của ladpro98
program GPMB; uses math; const maxn=1700; maxV=100; fi=''; type e=record x,y,s:longint; end; var f:array[-maxV..maxV,-maxV..maxV] of longint; a,st:array[1..maxn] of e; i,j,n,d,x,y,res,g,si:longint; inp:text; procedure sort(l,r:longint); var i,j:longint; t,p:e; begin if l>=r then exit; i:=l;j:=r; p:=a[random(r-l+1)+l]; repeat while (a[i].x<p.x) or ((a[i].x=p.x) and (a[i].y<p.y)) do inc(i); while (a[j].x>p.x) or ((a[j].x=p.x) and (a[j].y>p.y)) do dec(j); if i<=j then begin if i<j then begin t:=a[i]; a[i]:=a[j]; a[j]:=t; end; inc(i);dec(j); end; until i>j; sort(l,j);sort(i,r); end; function gcd(a,b:longint):longint; begin if b=0 then exit(a); if a mod b = 0 then exit(b); exit(gcd(b, a mod b)); end; begin assign(inp,fi);reset(inp); readln(inp,n); for i:=1 to n do readln(inp,a[i].x,a[i].y,a[i].s); sort(1,n); for i:=1 to n do begin si:=sqr(a[i].s)+5; res:=max(res,si); for j:=1 to d do f[st[j].x,st[j].y]:=0; d:=0; for j:=1 to n do if i<>j then begin x:=a[j].x-a[i].x; y:=a[j].y-a[i].y; g:=gcd(x,y); x:=x div g; y:=y div g; if f[x,y]=0 then begin inc(d); st[d].x:=x;st[d].y:=y; end; inc(f[x,y],sqr(a[j].s)+5); res:=max(res,si+f[x,y]); end; end; write(res); end.
Code mẫu của RR
//Wishing myself a happy lunar new year with a lot of accept solutions //Written by Nguyen Thanh Trung {$R+,Q+} program GPMB; const FINP=''; FOUT=''; MAXN=1600; esp=1e-6; var n:longint; x,y:array[1..MAXN] of longint; d,s:array[1..MAXN] of longint; cos:array[1..MAXN] of real; kq:longint; function kc(x1,y1,x2,y2:longint):real; begin kc:=sqrt(sqr(x1-x2)+sqr(y1-y2)); end; procedure inp; var f:text; i:longint; begin assign(f,FINP); reset(f); readln(f,n); for i:=1 to n do readln(f,x[i],y[i],s[i]); close(f); end; procedure ans; var f:text; begin assign(f,FOUT); rewrite(f); writeln(f,kq); close(f); end; function max(a,b:longint):longint; begin if a>b then max:=a else max:=b; end; procedure swap(var a,b:longint); var temp:longint; begin temp:=a; a:=b; b:=temp; end; procedure swapr(var a,b:real); var temp:real; begin temp:=a; a:=b; b:=temp; end; procedure sort(l,r:longint); var i,j:longint; key:real; begin i:=l; j:=r; key:=cos[(l+r) div 2]; repeat while cos[i]<key do inc(i); while cos[j]>key do dec(j); if i<=j then begin swap(d[i],d[j]); swapr(cos[i],cos[j]); inc(i); dec(j); end; until i>j; if i<r then sort(i,r); if l<j then sort(l,j); end; procedure find(i:longint); var j,sl:longint; t:longint; begin sl:=1; d[sl]:=s[i]*s[i]+5; for j:=1 to n do if (y[j]>=y[i]) and (j<>i) then begin inc(sl); cos[sl]:=(x[j]-x[i])/kc(x[i],y[i],x[j],y[j]); d[sl]:=s[j]*s[j]+5; end; if sl=1 then exit; sort(2,sl); t:=d[1]; cos[1]:=cos[2]; for j:=2 to sl do if abs(cos[j]-cos[j-1])<esp then begin t:=t+d[j]; if t>kq then kq:=t; end else begin t:=d[1]+d[j]; if t>kq then kq:=t; end; end; procedure solve; var i:longint; begin kq:=0; for i:=1 to n do find(i); end; begin inp; solve; ans; end.
Code mẫu của hieult
#include <cstdio> #include <algorithm> #include <map> #include <vector> #include <string> //#include <conio.h> using namespace std; #define nmax 1510 #define pii pair<int, int> struct data { int hx,hy,i; data(int c1,int c2, int ii) { if(c2<0) {c1 = -c1;c2 = -c2;} hx = c1; hy = c2; i = ii; } data(){} bool operator < (data D) const { if(hy!=0 && D.hy==0) return true; else if(hy==0 || D.hy ==0) return false; else return hx*D.hy<hy*D.hx; } }; int x[nmax],y[nmax],s[nmax]; data a[nmax]; int main() { //freopen("GPMB.in","r",stdin); int n,KQ = -1; scanf("%d",&n); for(int i = 1;i<=n;i++) scanf("%d %d %d",&x[i],&y[i],&s[i]); for(int i = 1;i<=n;i++) { int m=0; for(int j = i+1;j<=n;j++) { a[m] = data(x[j]-x[i],y[j]-y[i],j); m++; } sort(a,a+m); int sum=0; for(int j = 0;j<m;j++) { sum = sum+s[a[j].i]*s[a[j].i]+5; if(j==m-1 || a[j]<a[j+1]) { KQ = max(KQ,sum+s[i]*s[i]+5); sum=0; } } } printf("%d",KQ); //getch(); return 0; }
Code mẫu của ll931110
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> #define maxn 1505 using namespace std; pair<int,int> point[maxn]; int cost[maxn],n; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d %d %d", &point[i].first, &point[i].second, &cost[i]); cost[i] = cost[i] * cost[i] + 5; } int ret = 0; for (int i = 0; i < n; i++) { int insideCost = 0; vector< pair<double,int> > v; for (int j = 0; j < n; j++) if (point[i] == point[j]) insideCost += cost[i]; else { double mx = point[j].first - point[i].first,my = point[j].second - point[i].second; v.push_back(make_pair(atan2(my,mx),cost[j])); } sort(v.begin(),v.end()); int outsideCost = 0,curCost = 0;; for (int j = 0; j < v.size(); j++) { if (!j || v[j].first > v[j - 1].first) curCost = 0; curCost += v[j].second; outsideCost = max(outsideCost,curCost); } ret = max(ret,insideCost + outsideCost); } printf("%d\n", ret); }
Code mẫu của skyvn97
#include<cstdio> struct point { int x,y; point(){} point(const int &_x,const int &_y) { x=_x;y=_y; } }; point a[1515]; int c[111][111]; int f[111][111]; int n; void init(void) { scanf("%d",&n); int i,x,y,s; for (x=0;x<=100;x=x+1) for (y=0;y<=100;y=y+1) c[x][y]=0; for (i=1;i<=n;i=i+1) { scanf("%d",&x); scanf("%d",&y); scanf("%d",&s); c[x+50][y+50]+=s*s+5; a[i]=point(x+50,y+50); } } int gcd(const int &a,const int &b) { if (a==0) return (b); if (b==0) return (a); if (a%b==0) return (b); if (b%a==0) return (a); if (a>b) return (gcd(a%b,b)); if (b>a) return (gcd(a,b%a)); } void count(void) { int i,j; for (i=0;i<=100;i=i+1) for (j=0;j<=100;j=j+1) f[i][j]=gcd(i,j); } bool inside(const int &x,const int &y) { if (x<0) return (false); if (y<0) return (false); if (x>100) return (false); if (y>100) return (false); return (true); } int max(const int &x,const int &y) { if (x>y) return (x); else return (y); } void process(void) { int res=0; int i,j,k,dx,dy,t,s; for (i=0;i<=100;i=i+1) for (j=0;j<=100;j=j+1) if (f[i][j]==1) for (k=1;k<=n;k=k+1) { s=c[a[k].x][a[k].y]; dx=i; dy=j; for (t=1;t<=500;t=t+1) { if (!inside(a[k].x+t*dx,a[k].y+t*dy)) break; s+=c[a[k].x+t*dx][a[k].y+t*dy]; } for (t=1;t<=500;t=t+1) { if (!inside(a[k].x-t*dx,a[k].y-t*dy)) break; s+=c[a[k].x-t*dx][a[k].y-t*dy]; } res=max(res,s); s=c[a[k].x][a[k].y]; dx=-i; dy=j; for (t=1;t<=500;t=t+1) { if (!inside(a[k].x+t*dx,a[k].y+t*dy)) break; s+=c[a[k].x+t*dx][a[k].y+t*dy]; } for (t=1;t<=500;t=t+1) { if (!inside(a[k].x-t*dx,a[k].y-t*dy)) break; s+=c[a[k].x-t*dx][a[k].y-t*dy]; } res=max(res,s); } printf("%d",res); } int main(void) { init(); count(); process(); }
Code mẫu của khuc_tuan
#include <iostream> #include <cmath> using namespace std; const double eps = 1e-8; struct Point { int x, y; int s; bool operator < (Point b) const { return x < b.x; } }; struct G { double val; int s; bool operator < (G g) const { if(abs(val - g.val) <= eps) return false; return val < g.val; } }; Point a[1501]; int n; G ds[1501]; int nd; int main() { scanf("%d", &n); for(int i=0;i<n;++i) scanf("%d%d%d", &a[i].x, &a[i].y, &a[i].s), a[i].s = a[i].s * a[i].s + 5; sort( a, a+n); int res = 0; for(int i=0;i<n;++i) { int base = a[i].s; nd = 0; for(int j=i+1;j<n;++j) { if(a[j].x==a[i].x && a[j].y==a[i].y) base += a[j].s; else { double d = (a[j].y - a[i].y) / sqrt( (a[i].x-a[j].x) * (a[i].x-a[j].x) + (a[i].y-a[j].y) * (a[i].y-a[j].y) ); if(abs(d+1)<=eps) d = 1; ds[nd].val = d; ds[nd].s = a[j].s; ++nd; } } sort( ds, ds+nd); int r = 0, cur = 0; for(int i=0;i<nd;++i) { if(i==0 || abs(ds[i].val-ds[i-1].val)<=eps) cur += ds[i].s; else { r >?= cur; cur = ds[i].s; } } r >?= cur; res >?= r + base; } cout << res << endl; //system("pause"); return 0; }
Bình luận