39 条题解
-
02233702013 LV 8 @ 2016-08-23 15:21:36
本蒟蒻以O(n×d^2)**强势鄙视**O(d^2×128^2)!
c++
#include <iostream>
using namespace std;
int g[129][129],d,n,ans1=0,ans2=0;
int main()
{
ios::sync_with_stdio(0);
cin>>d>>n;
for(int i=1;i<=n;i++)
{
int x,y,k;
cin>>x>>y>>k;
for(int j=x-d;j<=x+d;j++)
for(int j2=y-d;j2<=y+d;j2++)
if(0<=j&&j<=128&&0<=j2&&j2<=128)
{
g[j][j2]+=k;
if(g[j][j2]>ans2)ans1=1,ans2=g[j][j2];
else
if(g[j][j2]==ans2)ans1++;
}
}
cout<<ans1<<" "<<ans2;
return 0;
}
-
02016-07-12 15:36:24@
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int map[200][200];
int main(){
int x,y,k,d,n;
int a=1,b=0;
int u,v;
cin>>d>>n;
for(int i=1;i<=n;i++){
cin>>x>>y>>k;
map[x][y]=k;
}
int c=0;
for(int i=0;i<=128;i++){
for(int j=0;j<=128;j++){
for(u=i-d;u<=i+d;u++){
for(v=j-d;v<=j+d;v++){
if(u>=0 && u<=128 && v>=0 && v<=128)
c=map[u][v];
}
if(b<c){
a=1;
b=c;}
else
if(b=c)
a++;
}}
}
printf("%d %d",a,b);
return 0;
} -
02016-02-13 22:15:32@
水啊,直接暴搜,一次AC了
Pascal AC
var d,n,i,j,t,s,x,y,k,p,q,f:longint;
a:array[-100..200,-100..200]of longint;
begin
readln(d);
readln(n);
for i:=1 to n do
begin
readln(x,y,k);
a[x,y]:=k;
end;
x:=0;
y:=0;
s:=0;
for i:=0 to 128 do
for j:=0 to 128 do
begin
x:=i-d;
y:=j-d;
t:=0;
for p:=x to x+2*d do
for q:=y to y+2*d do
if a[p,q]>0 then
t:=t+a[p,q];
if t>s then begin
s:=t;
f:=0;
end;
if t=s then inc(f);
end;
write(f,' ',s);
end. -
02015-10-27 21:33:25@
逐一枚举即可轻松AC,没有难度
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int f[129][129],n,d,a[50000];
int comp(const int&x,const int&y)
{
return x>y;
}
void work()
{
int i,j,k,l,tot=0;
for(i=0;i<=128;i++){
for(j=0;j<=128;j++){
int sum=0;
for(k=(i-d<0?0:i-d);k<=(i+d>128?128:i+d);k++){
for(l=(j-d<0?0:j-d);l<=(j+d>128?128:j+d);l++){
sum+=f[k][l];
}
}
a[++tot]=sum;
}
}
sort(a+1,a+tot+1,comp);
int sum=1;
for(i=2;i<=tot;i++){
if(a[i]!=a[i-1]){
break;
}
++sum;
}
printf("%d %d",sum,a[i-1]);
}
void init()
{
int i,j,x,y,k,l,tot,sum;
scanf("%d%d",&d,&n);
for(i=1;i<=n;i++){
scanf("%d%d",&x,&y);
scanf("%d",&f[x][y]);
}}
int main()
{
init();
work();
return 0;
} -
02015-10-27 12:16:59@
program P1908;
var
d, n, max, i, j, k, t1, t2: longint;
xy: array[1..20, 1..3] of longint;
begin
Read(d);
Read(n);
max := 1;
for i := 1 to n do
Read(xy[i, 1], xy[i, 2], xy[i, 3]);
t2 := 1;
for i := 0 to 128 do
for j := 0 to 128 do
begin
t1 := 0;
for k := 1 to n do
if (xy[k, 1] >= i - d) and (xy[k, 1] <= i + d) and (xy[k, 2] >= j - d) and
(xy[k, 2] <= j + d) then
t1 := t1 + xy[k, 3];
if t1 > max then
begin
max := t1;
t2 := 1;
end
else if t1 = max then
Inc(t2);
end;
Write(t2, ' ', max);
readln;
readln;
end.不能从(d,d)开始搜,从(0,0)开始,覆盖区域不一定是4d^2
-
02015-10-24 21:33:12@
-
02015-10-20 21:54:45@
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;int map[200][200];
int main()
{
int d, n;
ll ans = 0, sum = 1;
cin>>d>>n;
for(int i=1; i<=n; i++){
int x, y, k;
cin>>x>>y>>k;
map[x][y] = k;
}
for(int i=0; i<=128; i++)
for(int j=0; j<=128; j++){
ll bri = 0;
for(int u=i-d; u<=i+d; u++)
for(int v=j-d; v<=j+d; v++)
if(u>=0 && u<=128 && v>=0 && v<=128)
bri += (ll)map[u][v];
if(ans < bri){
ans = bri;
sum = 1;
}
else if(ans == bri)
sum++;
}
printf("%lld %lld", sum, ans);
return 0;
}
水一发~~~ -
02015-10-16 06:47:53@
program codevs3578;
const
maxn=128;
var
t,ans,d,n,x,y,k,i,j:longint;
f,s,map:array[-200..200,-200..200] of longint;
function max(a,b:longint):longint;
begin
if a>b then exit(a); exit(b);
end;
procedure work;
begin
for i:=0 to maxn+d do
for j:=0 to maxn+d do
begin
f[i,j]:=s[i,j]-s[i-d-1,j]-s[i,j-d-1]+s[i-d-1,j-d-1];
ans:=max(ans,f[i,j]);
end;
for i:=0 to maxn+d do
for j:=0 to maxn+d do
if f[i,j]=ans then inc(t);
end;
begin
assign(input,'2.in');
reset(input);
readln(d); d:=d*2;
readln(n);
fillchar(map,sizeof(map),0);
fillchar(f,sizeof(f),0);
fillchar(s,sizeof(s),0);
ans:=0; t:=0;
for i:=1 to n do
begin
readln(x,y,k);
map[x,y]:=k;
end;
for i:=0 to maxn+d do
for j:=0 to maxn+d do
s[i,j]:=s[i-1,j]+s[i,j-1]-s[i-1,j-1]+map[i,j];
work;
writeln(t,' ',ans);
end.
为什么都没有人用前缀和? -
02015-09-18 22:00:49@
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int a[130][130];
int d,n,x,y,k,m,s;
int min(int a,int b) {return (a<b?a:b);}
int max(int a,int b) {return (a>b?a:b);}
int find(int x,int y) {
int i,j,c;
c=0;
for (i=max(0,x-d);i<=min(128,x+d);i++)
for (j=max(0,y-d);j<=min(128,y+d);j++)
c+=a[i][j];
return c;
}
int main()
{
scanf("%d",&d);scanf("%d",&n);
int i,j;
memset(a,0,sizeof(a));
for (i=1;i<=n;i++){
scanf("%d %d %d",&x,&y,&k);
a[x][y]=k;
}
m=0;
for (i=0;i<=128;i++)
for (j=0;j<=128;j++)
if (find(i,j)>m) m=find(i,j);
s=0;
for (i=0;i<=128;i++)
for (j=0;j<=128;j++)
if (find(i,j)==m) s++;
printf("%d %d",s,m);
return 0;
} -
02015-09-04 17:28:47@
二维前缀和可以将算法优化至O(地图大小)
-
02015-08-31 12:03:39@
编译成功
测试数据 #0: Accepted, time = 5 ms, mem = 620 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 616 KiB, score = 10
测试数据 #2: Accepted, time = 15 ms, mem = 616 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 620 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 616 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 616 KiB, score = 10
测试数据 #6: Accepted, time = 6 ms, mem = 616 KiB, score = 10
测试数据 #7: Accepted, time = 0 ms, mem = 616 KiB, score = 10
测试数据 #8: Accepted, time = 0 ms, mem = 616 KiB, score = 10
测试数据 #9: Accepted, time = 0 ms, mem = 616 KiB, score = 10
Accepted, time = 26 ms, mem = 620 KiB, score = 100基于树状数组的解题报告:
http://blog.csdn.net/Onlynagesha/article/details/48132059 -
02015-08-09 13:39:08@
和导弹拦截差不多
-
02015-02-17 09:43:24@
暴力......
#include <cstdio>
#include <cstring>
#include <cstdlib>using namespace std;
int d,n;
struct Q
{
int x,y,k;
}q[21];
long long rsum=-1;
int rcnt;void init(void)
{
scanf("%d%d",&d,&n);
for (int i=1;i<=n;i++) scanf("%d%d%d",&q[i].x,&q[i].y,&q[i].k);
}void work(void)
{
for (int x=0;x<=128;x++)
for (int y=0;y<=128;y++)
{
long long sum=0;
for (int i=1;i<=n;i++)
if (x-d<=q[i].x&&q[i].x<=x+d&&y-d<=q[i].y&&q[i].y<=y+d) sum+=q[i].k;
if (rsum<sum)
{
rsum=sum;
rcnt=1;
}
else rcnt+=rsum==sum;
}
printf("%d %lld\n",rcnt,rsum);
}int main(void)
{
init();
work();
return 0;
} -
02015-02-08 12:17:29@
#include <iostream>
#include <stdio.h>using namespace std;
int x , y;
int k;
int d , n;
int i , j;
int a[128 + 5][128 + 5];
int maxd;
int sum;int max( int a , int b )
{
if( a > b )
return a;
return b;
}int find( int x , int y )
{
int i , j;
int ans = 0;
for( i = max( x - d , 0 ) ; i <= min( 128 , x + d ) ; i++ )
{
for( j = max( y - d , 0 ) ; j <= min( 128 , y + d ) ; j++ )
ans += a[i][j];
}
return ans;
}int main()
{
scanf( "%d" , &d );
scanf( "%d" , &n );
for( i = 0 ; i < n ; i++ )
{
scanf( "%d %d %d" , &x , &y , &k );
a[x][y] = k;
}
for( i = 0 ; i <= 128 ; i++ )
for( j = 0 ; j <= 128 ; j++ )
maxd = max( find( i , j ) , maxd );
for( i = 0 ; i <= 128 ; i++ )
for( j = 0 ; j <= 128 ; j++ )
if( find( i , j ) == maxd )
sum++;
cout << sum << " " << maxd << endl;
return 0;
} -
02015-02-05 20:52:31@
var d,n,i,j,k,l,sum,max,max2,x,y:longint;
a:array[-20..148,-20..148] of longint;
begin
read(d); read(n);
for i:=1 to n do
begin read(x,y,k); a[x,y]:=k; end;
for i:=0 to 128 do
for j:=0 to 128 do
begin
sum:=0;
for k:=i-d to i+d do
for l:=j-d to j+d do
inc(sum,a[k,l]);
if sum>max then
begin max2:=1; max:=sum; end
else if sum=max then inc(max2);
end;
writeln(max2,' ',max);
end.呵呵呵呵。。。。死搜,连个剪枝都没就*AC*。。。。
-
02015-01-09 19:11:13@
没人发题解么?我来吧~
###block code
program ex;
var data:array[-20..148,-20..148] of longint;
d,n,x,y,i,j,ans,a,b,s,maxx,maxy:longint;
k:longint;
z,num:int64;
begin
read(d); read(n);
fillchar(data,sizeof(data),0);
ans:=0; s:=1; z:=0;
maxx:=0; maxy:=0;
for i:=1 to n do
begin
read(x); read(y); read(k);
data[x,y]:=k;
z:=z+k;
if x>maxx then
maxx:=x;
if y>maxy then
maxy:=y;
end;for i:=0 to 128 do
for j:=0 to 128 do
begin
num:=0;for a:=i-d to i+d do
for b:=j-d to j+d do
num:=num+data[a,b];if (ans=num) then
inc(s);if ans<num then
begin
ans:=num;
s:=1;
end;end;
if ans=0 then
s:=129*129;
write(s,' ',ans);end.
-
-12020-04-02 17:30:13@
6h
-
-12015-07-26 13:42:44@
一个一个试就行了。点亮我生命的水水水水水!你是我的小呀小水题,怎么爱你都不嫌多
-
-12014-11-24 21:19:42@
死搜题,剪枝什么的这么小规模不介意的。关系要数组不能太小,防止溢出。而且应该所有点都要判断。
基本秒过= =