题解

175 条题解

  • 0
    @ 2015-10-05 23:55:43

    数据**#1**

    #3
    是怎么回事????
    #include <iostream>
    #include <vector>
    #include <cstdio>

    using namespace std;

    int main()
    {
    long long int n,m;
    vector<char>mapp;
    vector< vector<char> >maap;
    cin>>n>>m;
    long long int i,j;
    int fh=0;
    for(j=0;j<n;++j)
    {
    mapp.push_back('a');
    }
    for(i=0;i<n;++i)
    {
    for(j=0;j<n;++j)
    {
    cin>>mapp[j];
    if(mapp[j]=='#')fh++;
    }
    maap.push_back(mapp);
    }
    if(m>=n)
    {
    cout<<fh;
    return 0;
    }
    static long long int x,y;
    long long int i1,j1;
    static long long int ans;
    static long long int w;
    for(i=0;y<n;++i)
    {
    y=i+m;
    for(j=0;x<n;++j)
    {
    x=j+m;
    for(i1=i;i1<y;++i1)
    {
    for(j1=j;j1<x;++j1)
    {
    if(maap[i1][j1]=='#')w++;
    }
    }
    ans=ans>w? ans:w;
    w=0;
    }
    }
    cout<<ans;
    return 0;
    }

  • 0
    @ 2015-09-26 18:16:12

    评测结果
    编译成功

    测试数据 #0: Accepted, time = 15 ms, mem = 98356 KiB, score = 20
    测试数据 #1: Accepted, time = 0 ms, mem = 98356 KiB, score = 20
    测试数据 #2: Accepted, time = 15 ms, mem = 98356 KiB, score = 20
    测试数据 #3: Accepted, time = 0 ms, mem = 98352 KiB, score = 20
    测试数据 #4: Accepted, time = 16 ms, mem = 98352 KiB, score = 20
    Accepted, time = 46 ms, mem = 98356 KiB, score = 100
    代码
    #include<iostream>
    #include<fstream>
    #include<windows.h>
    #include<string>
    #include<algorithm>
    using namespace std;
    char map[10000][10000];
    int sum(int x,int y,int n)
    {
    int i,j,s=0;
    for(i=x;i<x+n;i++)
    {
    for(j=y;j<y+n;j++)
    {
    if(map[i][j]=='#')s++;
    }
    }
    return s;
    }
    int main()
    {
    int m,n,i,j,max=0;
    cin>>m>>n;
    for(i=0;i<m;i++)cin>>map[i];
    for(i=0;i<m;i++)
    {
    for(j=0;j<m;j++)
    {
    if(max<sum(i,j,n))max=sum(i,j,n);
    }
    }
    cout<<max<<endl;
    return 0;
    }
    vijos第十题纪念

  • 0
    @ 2015-09-04 21:59:49

    水题,更水的数据。。。。。
    var n,m,i,j,k,l,h,max,s:longint;
    c:array[1..10000,1..10000]of char;
    x:string;
    begin
    readln(n);readln(m);
    for i:=1 to n do begin
    readln(x);
    for j:=1 to n do c[i,j]:=x[j];
    end;
    if n=m then begin
    for i:=1 to n do
    for j:=1 to n do
    if c[i,j]='#' then inc(max);
    end else
    for i:=1 to n-m+1 do
    for j:=1 to n-m+1 do begin
    s:=0;
    for h:=i to i+m-1 do
    for l:=j to j+m-1 do begin
    if c[h,l]='#' then inc(s);
    end;
    if s>max then max:=s;
    end;
    write(max);
    end.

  • 0
    @ 2015-08-28 12:34:53

    感觉和去年noip普及组最后一题有点像
    不过数据简单很多,暴力搜索,我记得noip那道题还是剪枝优化了一堆才50分
    ###Block Code
    m = int(raw_input())
    n = int(raw_input())
    base = []

    for i in range(m):
    base.append(raw_input())

    ans = 0

    for i in range(m-n+1):
    for j in range(m-n+1):
    cnt = 0
    for i1 in range(i,i+n):
    cnt += base[i1].count('#',j,j+n)
    if cnt > ans:
    ans = cnt

    print ans

  • 0
    @ 2015-08-01 13:36:59

    暴搜,easy,纪念40AC

    var a:array[1..10000,1..10000]of char;
    n,m,i,j,p,q,ans,max:longint;
    begin
    readln(m,n);
    for i:=1 to m do begin
    for j:=1 to m-1 do read(a[i,j]);
    readln(a[i,m]);
    end;
    for i:=1 to m-n+1 do
    for j:=1 to m-n+1 do begin
    ans:=0;
    for p:=i to i+n-1 do
    for q:=j to j+n-1 do
    if a[p,q]='#' then inc(ans);
    if ans>max then max:=ans;
    end;
    writeln(max);
    end.

  • 0
    @ 2015-06-07 13:32:57

    这题数据真水……目测m,n不超过100?我的O(n^4)都过了,还是秒杀……
    注意一下核弹炸的范围可以大于基地的范围
    测试数据 #0: Accepted, time = 15 ms, mem = 98616 KiB, score = 20
    测试数据 #1: Accepted, time = 3 ms, mem = 98616 KiB, score = 20
    测试数据 #2: Accepted, time = 0 ms, mem = 98616 KiB, score = 20
    测试数据 #3: Accepted, time = 0 ms, mem = 98616 KiB, score = 20
    测试数据 #4: Accepted, time = 15 ms, mem = 98616 KiB, score = 20
    Accepted, time = 33 ms, mem = 98616 KiB, score = 100

    block code

    代码
    var
    map:array[1..10000,1..10000] of char;
    i,j,k,l:longint;
    m,n:longint;
    tmp:longint;
    ans:Longint;
    begin
    readln(m);
    readln(n);
    for i:=1 to m do
    begin
    for j:=1 to m do read(map[i,j]);
    readln;
    end;
    for i:=1 to m-n+1 do
    for j:=1 to m-n+1 do
    begin
    tmp:=0;
    for k:=i to i+n-1 do
    for l:=j to j+n-1 do
    if map[k,l]<>'.' then inc(tmp);
    if tmp>ans then ans:=tmp;
    end;
    writeln(ans);
    end.

  • 0
    @ 2015-03-20 09:17:12

    #include<stdio.h>
    char base[10000][10000];
    int main()
    {
    int n,m,i,j,k,l;
    scanf("%d%d",&m,&n);
    for(i=0;i<m;i++)
    {
    scanf("%s",base[i]);
    }
    i=0,j=0;
    int count=0,ans=0;
    while(i+n<=m)
    {
    for(k=i;k<i+n;k++)
    {
    for(l=0;l<n;l++)
    {
    if(base[k][l]=='#')count++;
    }
    }
    if(count>ans)ans=count;
    i++;
    count=0;
    }
    while(j+n<=m)
    {
    for(k=0;k<n;k++)
    {
    for(l=j;l<j+n;l++)
    {
    if(base[k][l]=='#')count++;
    }
    }
    if(count>ans)ans=count;
    j++;
    count=0;
    }
    printf("%d",ans);
    return 0;
    }
    这题很水啊。。。

  • 0
    @ 2015-02-16 14:34:49

    #include <iostream>
    using namespace std;
    const int maxx = 10001;
    int maze[maxx][maxx];
    int main(){
    int m, n, s, max = 0;
    char c;
    cin >> m >> n;
    for (int i = m; i >= 1; i--){
    for (int j = m; j >= 1; j--){
    cin >> c;
    if (c == '#'){
    maze[i][j] = 1;
    }
    maze[i][j] += maze[i + 1][j] + maze[i][j + 1] - maze[i + 1][j + 1];
    }
    }
    for (int i = 1; i <= m - n + 1; i++){
    for (int j = 1; j <= m - n + 1; j++){
    s = maze[i][j] - maze[i + n][j] - maze[i][j + n] + maze[i + n][j + n];
    if (max < s){
    max = s;
    }
    }
    }
    cout << max << endl;

    }

    这数据有问题,我用从前往后累加,从后往前计算就WA,从后往前累加,从前往后计算就AC。。。

  • 0
    @ 2015-02-01 11:37:27

    评测结果
    编译成功

    foo.pas(21,8) Warning: Variable "max" does not seem to be initialized
    测试数据 #0: Accepted, time = 0 ms, mem = 392128 KiB, score = 20
    测试数据 #1: Accepted, time = 0 ms, mem = 392132 KiB, score = 20
    测试数据 #2: Accepted, time = 0 ms, mem = 392128 KiB, score = 20
    测试数据 #3: Accepted, time = 0 ms, mem = 392128 KiB, score = 20
    测试数据 #4: Accepted, time = 0 ms, mem = 392132 KiB, score = 20
    Accepted, time = 0 ms, mem = 392132 KiB, score = 100

  • 0
    @ 2015-02-01 11:36:50

    var
    m,n,i,j,i1,j1,o,max:longint;
    u:string;
    s:array[1..10000,1..10000] of longint;
    begin
    readln(m);
    readln(n);
    for i:=1 to m do
    begin
    readln(u);
    for j:=1 to m do
    if u[j]='.' then s[i,j]:=1;
    end;
    for i:=1 to m-n+1 do
    for j:=1 to m-n+1 do
    begin
    o:=0;
    for i1:=i to i+n-1 do
    for j1:=j to j+n-1 do
    if s[i1,j1]<>1 then o:=o+1;
    if o>max then max:=o;
    end;
    writeln(max);
    end.
    超级小白

  • 0
    @ 2014-11-02 10:15:56

    #include<iostream>
    #include<cstdio>
    #include<cstdlib>
    #include<cmath>
    #include<cstring>
    using namespace std;
    const int maxn=10001;
    int ans=0,m,n,con,temp,b[maxn][maxn];
    char a[maxn][maxn];

    int main()
    {
    memset(b,0,sizeof(b));
    scanf("%d%d",&m,&n);
    for(int i=1;i<=m;i++)
    scanf("%s",&a[i][1]);
    for(int i=1;i<=m;i++)
    for(int j=1;j<=m;j++)
    {
    con=0;
    for(int p=1;p<=i;p++)
    for(int q=1;q<=j;q++)
    if(a[p][q]=='#') con++;
    b[i][j]=con;
    }
    for(int i=1;i<=m-n+1;i++)
    for(int j=1;j<=m-n+1;j++)
    {
    temp=b[i+n-1][j+n-1]-b[i-1][j-1]-b[i+n-1][j-1]-b[i-1][j+n-1];
    if(temp>ans) ans=temp;
    }
    printf("%d",ans);
    return 0;
    }

  • 0
    @ 2014-03-21 20:39:28

    水水水 数据弱爆了 枚举过

    var f,m,n,max,i,j:longint;a:array[0..10000,0..10000]of char;
    function pd(p,q:longint):longint;
    var s,x,y:longint;
    begin
    s:=0;
    for x:=p-n+1 to p do
    for y:=q-n+1 to q do
    if a[x,y]='#'then inc(s);
    exit(s);
    end;
    begin
    readln(m);readln(n);max:=0;
    for i:=1 to m do
    begin
    for j:=1 to m do read(a[i,j]);
    readln;
    end;
    for i:=n to m do
    for j:=n to m do
    begin
    f:=pd(i,j);
    if f>max then max:=f;
    end;
    writeln(max);
    end.

    • @ 2014-03-21 20:41:06

      水水水 数据弱爆了 枚举过 不清楚 再来一次

      var f,m,n,max,i,j:longint;a:array[0..10000,0..10000]of char;

      function pd(p,q:longint):longint;

      var s,x,y:longint;

      begin

      s:=0;

      for x:=p-n+1 to p do

      for y:=q-n+1 to q do

      if a[x,y]='#'then inc(s);

      exit(s);

      end;

      begin

      readln(m);readln(n);max:=0;

      for i:=1 to m do

      begin

      for j:=1 to m do read(a[i,j]);

      readln;

      end;

      for i:=n to m do

      for j:=n to m do

      begin

      f:=pd(i,j);

      if f>max then max:=f;

      end;

      writeln(max);

      end.

  • 0
    @ 2014-01-22 23:37:55

    代码块tab键缩进也没用无语了。

  • 0
    @ 2014-01-22 23:37:10

    评测结果
    编译成功

    测试数据 #0: Accepted, time = 0 ms, mem = 8316 KiB, score = 20
    测试数据 #1: Accepted, time = 0 ms, mem = 8316 KiB, score = 20
    测试数据 #2: Accepted, time = 0 ms, mem = 8316 KiB, score = 20
    测试数据 #3: Accepted, time = 0 ms, mem = 8312 KiB, score = 20
    测试数据 #4: Accepted, time = 0 ms, mem = 8316 KiB, score = 20
    Accepted, time = 0 ms, mem = 8316 KiB, score = 100
    代码
    #include <iostream>
    using namespace std;
    int m,n,i,j;
    __int64 ans;
    char ch;
    __int64 a[1001][1001];
    int main(){
    while(cin>>m>>n){
    ans=0;
    for(i=1;i<=m;i++){
    for(j=1;j<=m;j++){
    cin>>ch;
    if(ch=='#')
    a[i][j]=a[i][j-1]+a[i-1][j]-a[i-1][j-1]+1;
    else
    a[i][j]=a[i][j-1]+a[i-1][j]-a[i-1][j-1];
    if(i>=n&&j>=n&&ans<a[i][j]-a[i-n][j]-a[i][j-n]+a[i-n][j-n])
    ans=a[i][j]-a[i-n][j]-a[i][j-n]+a[i-n][j-n];
    }
    }
    cout<<ans<<endl;
    }
    return 0;
    }

  • 0
    @ 2014-01-22 23:35:22

    评测结果
    编译成功

    测试数据 #0: Accepted, time = 0 ms, mem = 8316 KiB, score = 20
    测试数据 #1: Accepted, time = 0 ms, mem = 8316 KiB, score = 20
    测试数据 #2: Accepted, time = 0 ms, mem = 8316 KiB, score = 20
    测试数据 #3: Accepted, time = 0 ms, mem = 8312 KiB, score = 20
    测试数据 #4: Accepted, time = 0 ms, mem = 8316 KiB, score = 20
    Accepted, time = 0 ms, mem = 8316 KiB, score = 100
    代码
    #include <iostream>
    using namespace std;
    int m,n,i,j;
    __int64 ans;
    char ch;
    __int64 a[1001][1001];
    int main(){
    while(cin>>m>>n){
    ans=0;
    for(i=1;i<=m;i++){
    for(j=1;j<=m;j++){
    cin>>ch;
    if(ch=='#')
    a[i][j]=a[i][j-1]+a[i-1][j]-a[i-1][j-1]+1;
    else
    a[i][j]=a[i][j-1]+a[i-1][j]-a[i-1][j-1];
    if(i>=n&&j>=n&&ans<a[i][j]-a[i-n][j]-a[i][j-n]+a[i-n][j-n])
    ans=a[i][j]-a[i-n][j]-a[i][j-n]+a[i-n][j-n];
    }
    }
    cout<<ans<<endl;
    }
    return 0;
    }

  • 0
    @ 2013-10-25 19:00:26

    0.0,数据好弱啊……

  • 0
    @ 2013-10-22 12:44:02

    大水题..

    编译成功

    测试数据 #0: Accepted, time = 0 ms, mem = 98404 KiB, score = 20

    测试数据 #1: Accepted, time = 0 ms, mem = 98412 KiB, score = 20

    测试数据 #2: Accepted, time = 0 ms, mem = 98412 KiB, score = 20

    测试数据 #3: Accepted, time = 0 ms, mem = 98412 KiB, score = 20

    测试数据 #4: Accepted, time = 0 ms, mem = 98412 KiB, score = 20

    Accepted, time = 0 ms, mem = 98412 KiB, score = 100

     
     

    #include <iostream>

    using namespace std;

    int m, n;
    char baseMap[10000][10000];

    //
    // 统计x,n+x,y,n+y正方形内有多少房屋
    //
    int CountHouse(int x, int y)
    {
    int i, j, housesTotal = 0;
    for (i = x; i < (n + x); i++) {
    for (j = y; j < (n + y); j++) {
    if (baseMap[i][j] == '#')
    housesTotal++;
    }
    }
    return housesTotal;
    }

    int main()
    {
    int i, j;

    //
    // 读入数据
    //
    cin >> m;
    cin >> n;
    for (i = 0; i < m; i++) {
    cin >> baseMap[i];
    }

    //
    // 基地矩形变长 - 炸弹矩形边长 = 搜索偏移
    //
    int Distance = m - n;
    // 特判:如果n>m那么所有房屋都会被炸
    if (Distance < 0)
    Distance = 0;

    //
    // 搜索所有可炸的正方形领域,取房屋数最大值
    //
    int HousesTotal, MaxHousesTotal = 0;
    for (i = 0; i <= Distance; i++) {
    for (j = 0; j <= Distance; j++) {
    HousesTotal = CountHouse(i, j);
    if (HousesTotal > MaxHousesTotal) {
    MaxHousesTotal = HousesTotal;
    }
    }
    }

    //
    // 输出结果
    //
    cout << MaxHousesTotal;

    return 0;
    }

  • 0
    @ 2013-10-20 19:07:23

    出题目的脑子怎么了,m<10000,尼玛,还1s,N^2的读入就超时了!

  • 0
    @ 2013-07-18 20:00:06

    FU %%% CK!!!!!!!第三组数据是长10宽8的,做测试数据的脑子进农夫山泉了吧

  • 0
    @ 2013-03-31 09:27:49

    #include<iostream>
    #include<stdio.h>
    using namespace std;

    int main()
    {
    char **a;
    int m,n,i,j,k,s;
    int sum=0; // 统计符合条件的个数
    int max=-1; //最大的个数是max
    cin>>m;
    cin>>n;
    a=new char*[ m+1 ];
    for( i=0; i<=m; i++)
    a[i]=new char[ m+1 ];

    for( i=1; i<=m; i++) //输入数据
    for( j=1; j<=m; j++)
    cin>>a[i][j];

    for( k=1; k<=m-n+1; k++) //正方形n开始第一个的横坐标
    {
    for( s=1; s<=m-n+1; s++) //正方形n开始第一个的纵坐标
    {
    sum=0;
    for( i=k; i<=k+n-1; i++) // 对正方形n中的所有符合条件的元素求和
    for( j=s; j<=s+n-1; j++)
    {
    if( a[i][j]=='#' )
    sum++;
    }

    if( max<sum ) { max=sum; }
    }
    }

    cout<<max;

    return 0;
    }

    测试数据 #0: Accepted, time = 15 ms, mem = 228 KiB, score = 20
    测试数据 #1: Accepted, time = 15 ms, mem = 228 KiB, score = 20
    测试数据 #2: WrongAnswer, time = 30 ms, mem = 228 KiB, score = 0
    测试数据 #3: Accepted, time = 15 ms, mem = 228 KiB, score = 20
    测试数据 #4: Accepted, time = 14 ms, mem = 228 KiB, score = 20

    不知怎样改才能通过第二的数据,求大神指点

信息

ID
1199
难度
4
分类
搜索 | 搜索与剪枝 点击显示
标签
递交数
2725
已通过
1238
通过率
45%
被复制
7
上传者