Hướng dẫn giải của Cafe WIFI
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
#include <iostream> #include <algorithm> #include <cstdio> using namespace std; int X,Y,k,a[1010][30030],best,cnt; int main() { int x,y,r,b; cin >> Y >> X >> k; while (k--) { scanf("%d%d%d%d",&x,&y,&r,&b); int top=min(y+r,Y),bot=max(y-r,1),i=x; a[x][top+1]-=b; a[x][bot]+=b; while (i-x<r && i<X) { i++; while ((i-x)*(i-x)+(top-y)*(top-y)>r*r) top--; while ((i-x)*(i-x)+(y-bot)*(y-bot)>r*r) bot++; a[i][top+1]-=b; a[i][bot]+=b; } i=x; top=min(y+r,Y); bot=max(y-r,1); while (x-i<r && i>1) { i--; while ((i-x)*(i-x)+(top-y)*(top-y)>r*r) top--; while ((i-x)*(i-x)+(y-bot)*(y-bot)>r*r) bot++; a[i][top+1]-=b; a[i][bot]+=b; } } for (x=1;x<=X;x++) { int s=0; for (y=1;y<=Y;y++) { s+=a[x][y]; if (s>best) best=s, cnt=1; else if (s==best) cnt++; } } cout << best << endl << cnt << endl; return 0; }
Code mẫu của ladpro98
#include <bits/stdc++.h> using namespace std; const int M = 30003; const int N = 1010; const double EPSILON = 1e-9; int n, r, c; int a[N][M]; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> c >> r >> n; int x, y, R, B; while (n--) { cin >> x >> y >> R >> B; int from = max(x - R, 1), to = min(x + R, r); R *= R; for (int i = from; i <= to; ++i) { int dist = abs(x - i); int range = int(sqrt(R - dist * dist) + EPSILON); a[i][max(y - range, 1)] += B; a[i][min(y + range, c) + 1] -= B; } } int ans = 0, cnt = 0; for (int i = 1; i <= r; ++i) for (int j = 1; j <= c; ++j) { a[i][j] += a[i][j - 1]; if (a[i][j] > ans) { ans = a[i][j]; cnt = 1; } else if (a[i][j] == ans) { ++cnt; } } cout << ans << endl << cnt << endl; return 0; }
Code mẫu của RR
#include <sstream> #include <iomanip> #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 FORN(i,a,b) for(int i=(a),_b=(b);i<_b;i++) #define DOWN(i,a,b) for(int i=a,_b=(b);i>=_b;i--) #define SET(a,v) memset(a,v,sizeof(a)) #define sqr(x) ((x)*(x)) #define ll long long #define F first #define S second #define PB push_back #define MP make_pair #define DEBUG(x) cout << #x << " = "; cout << x << endl; #define PR(a,n) cout << #a << " = "; FOR(_,1,n) cout << a[_] << ' '; cout << endl; #define PR0(a,n) cout << #a << " = "; REP(_,n) cout << a[_] << ' '; cout << endl; using namespace std; //Buffer reading int INP,AM,REACHEOF; const int BUFSIZE = (1<<12) + 17; char BUF[BUFSIZE+1], *inp=BUF; #define GETCHAR(INP) { \ if(!*inp && !REACHEOF) { \ memset(BUF,0,sizeof BUF);\ int inpzzz = fread(BUF,1,BUFSIZE,stdin);\ if (inpzzz != BUFSIZE) REACHEOF = true;\ inp=BUF; \ } \ INP=*inp++; \ } #define DIG(a) (((a)>='0')&&((a)<='9')) #define GN(j) { \ AM=0;\ GETCHAR(INP); while(!DIG(INP) && INP!='-') GETCHAR(INP);\ if (INP=='-') {AM=1;GETCHAR(INP);} \ j=INP-'0'; GETCHAR(INP); \ while(DIG(INP)){j=10*j+(INP-'0');GETCHAR(INP);} \ if (AM) j=-j;\ } //End of buffer reading const long double PI = acos((long double) -1.0); const int MN = 1011; int n, m, k; int x[MN], y[MN], r[MN], b[MN]; int f[MN][30111]; #define sqr(x) ((x)*(x)) void refine(int &x, int l, int r) { if (x < l) x = l; if (x > r) x = r; } int main() { scanf("%d%d%d", &m, &n, &k); FOR(i,1,k) { scanf("%d%d%d%d", &x[i], &y[i], &r[i], &b[i]); FOR(col,max(1,x[i]-r[i]),min(n,x[i]+r[i])) { double diff = sqrt(sqr(r[i]) - sqr(col-x[i])); int y1 = (int) ( ceil(y[i] - diff - 1e-6) + 1e-6); int y2 = (int) (floor(y[i] + diff + 1e-6) + 1e-6); refine(y1, 1, m); refine(y2, 1, m); f[col][y1] += b[i]; f[col][y2+1] -= b[i]; } } int res = 0, cnt = 0; FOR(col,1,n) { int now = 0; FOR(row,1,m) { now += f[col][row]; if (now > res) { res = now; cnt = 1; } else if (now == res) { ++cnt; } } } cout << res << endl << cnt << endl; return 0; }
Code mẫu của hieult
#include <cstdio> #include <cstring> #include <algorithm> #include <cmath> //#include <conio.h> #define ep 0.000001 using namespace std; int TTD(int a){ if(a<0) return -a; return a; } int x[1111],y[1111],r[1111],b[1111],m,n,k,quan,u,v,T,f[33333],kq,so; int main(){ // freopen("TNHWIFI.in","r",stdin); scanf("%d %d %d",&m,&n,&k); for(int i = 1;i<=k;i++){ scanf("%d %d %d %d",&x[i],&y[i],&r[i],&b[i]); } kq = -1; so = 0; for(int i = 1;i<=n;i++){ memset(f,0,sizeof(f)); for(int j = 1;j<=k;j++){ if(TTD(x[j]-i)>r[j]) continue; T = int(sqrt(r[j]*r[j]-(x[j]-i)*(x[j]-i))+ep); u = y[j]-T; v = y[j]+T; if(v>m) v = m; if(u<1) u = 1; f[u]+=b[j]; f[v+1]-=b[j]; } T = 0; for(int j = 1;j<=m;j++){ T+=f[j]; if(T>kq){ kq = T; so = 1; } else if(T==kq){ so++; } // printf("%d %d %d\n",i,j,T); } } printf("%d\n%d",kq,so); // getch(); }
Bình luận