题解

36 条题解

  • 0
    @ 2015-10-20 20:17:22

    编译成功

    测试数据 #0: Accepted, time = 0 ms, mem = 248 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 244 KiB, score = 10
    测试数据 #2: Accepted, time = 0 ms, mem = 244 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 244 KiB, score = 10
    测试数据 #4: Accepted, time = 0 ms, mem = 248 KiB, score = 10
    测试数据 #5: Accepted, time = 0 ms, mem = 244 KiB, score = 10
    测试数据 #6: Accepted, time = 0 ms, mem = 248 KiB, score = 10
    测试数据 #7: Accepted, time = 0 ms, mem = 248 KiB, score = 10
    测试数据 #8: Accepted, time = 0 ms, mem = 248 KiB, score = 10
    测试数据 #9: Accepted, time = 0 ms, mem = 244 KiB, score = 10
    Accepted, time = 0 ms, mem = 248 KiB, score = 100
    代码
    #include<cstdio>
    using namespace std;
    void ok(int x,int y,int l);
    int s=1;
    int main()
    {
    int n,i,j;
    scanf("%d %d %d",&n,&i,&j);
    int x=i,y=j,l=n;
    for(;;)
    {
    if(x==1||y==1||x==l||y==l)
    {
    ok(x,y,l);
    break;
    }
    s=s+(l-1)*4;
    l=l-2;
    x--;
    y--;
    }
    printf("%d",s);
    }
    void ok(int x,int y,int l)
    {
    int i=1,j=1,z=0;
    for(;;s++)
    {
    if((j==1&&z==0)||(j==l&&z==1)||(i==l&&z==2)||(j==1&&z==3)) z++;
    if(i==x&&j==y) break;
    switch(z)
    {
    case 1:j++;break;
    case 2:i++;break;
    case 3:j--;break;
    case 4:i--;break;
    }
    }
    }

  • 0
    @ 2015-09-02 00:57:03

    其实不用循环。。顺序下来就好。。
    这个矩阵从行或者列来分析都比较棘手,但分成圈来看,每一圈都遵循顺时针递增的规律。所以,我们先确定所求的点(i,j)在第k圈,并且计算第k圈的边长ak以及第一个数字bk,这样问题就简单了,分(i,j)落在第k圈的上、下、左、右四条边上的情况来讨论。
    k,ak,bk的计算方法见代码。
    ###Pascal Code
    program Project1;
    var
    ak,bk,n,k,x,y:longint;
    function min(a,b,c,d:longint):longint;
    begin
    min:=a;
    if(b<min)then min:=b;
    if(c<min)then min:=c;
    if(d<min)then min:=d;
    end;
    begin
    readln(n,x,y);
    k:=min(x,y,n-x+1,n-y+1); {计算坐标(x,y)在第几圈}
    bk:=4*(n+(k-2)*(n-k)-1)+1; {第k圈的第一个数}
    ak:=n-2*(k-1); {第k圈的边长}
    if(x=k)then writeln(bk+y-k) {在该圈上边}
    else if(y=k+ak-1)then writeln(bk+ak-1+x-k) {在该圈右边}
    else if(x=k+ak-1)then writeln(bk+3*ak+k-3-y) {在该圈下边}
    else writeln(bk+4*ak+k-4-x); {在该圈左边}
    readln
    end.

  • 0
    @ 2015-08-26 17:57:37

    #去年比赛的时候我傻乎乎的直接枚举4个边,现在想想真是太简单了,但是要求较高的分析能力
    int x,y,n; cin>>n>>x>>y;
    int p=min(x,n-x+1);

    int q=min(y,n-y+1);
    int quan=q>=p?p:q; //以上是判断在第几个圈
    int nx=quan,ny=quan,num=1;
    for (int i=1;i<quan;++i) {
    num+=4*n-4; n-=2;
    } //计算出这个圈的左上角的数
    //从这个圈的左上角出发顺时针走,碰到坐标一样则输出并结束程序
    //技术含量不高
    for (int i=0;i<n;++i) {
    if (nx==x&&ny+i==y) {
    cout<<num+i;
    return 0;
    }
    }
    num=num+n-1; ny=ny+n-1;
    for (int i=0;i<n;++i) {
    if (nx+i==x&&ny==y) {
    cout<<num+i;
    return 0;
    }
    }
    num=num+n-1; nx=nx+n-1;
    for (int i=0;i<n;++i) {
    if (nx==x&&ny-i==y) {
    cout<<num+i;
    return 0;
    }
    }
    num=num+n-1; ny=ny-n+1;
    for (int i=0;i<n;++i) {
    if (nx-i==x&&ny==y) {
    cout<<num+i;
    return 0;
    }
    }

  • 0
    @ 2015-08-04 15:47:06

    #include<iostream>
    #include<cmath>
    #include<cstdio>
    using namespace std;
    int n,i,j,q;
    int main()
    {
    cin>>n>>i>>j;

    if( i>n/2 && j>n/2 )
    q=min(n-i+1,n-j+1 );
    if( i>n/2 && j<=n/2)
    q=min(n-i+1,j);
    if( i<=n/2 && j<=n/2 )
    q=min(i,j);
    if( i<=n/2 && j>n/2 )
    q=min(i,n-j+1);
    if( i>j )
    printf("%d",-4*q*q+4*n*q+2*q+1-i-j );
    else

    printf("%d",-4*q*q+4*q*n-4*n+6*q+i+j-3 );
    return 0;
    }

  • 0
    @ 2015-08-01 11:18:21

    #include<iostream>
    #include<math.h>
    #include<stdio.h>
    #include<string.h>
    #include<algorithm>
    #include<time.h>
    #include<stdlib.h>
    using namespace std;

    int a[1005];
    void mul(int k){
    int i;
    int enter = 0;
    for (i = 0; i < 1000; i++){
    a[i] *= k;
    a[i] += enter;
    enter = a[i] / 10;
    a[i] %= 10;
    }
    }
    int main(){
    int n;
    cin >> n;
    int t = n % 3;
    int k = n / 3;
    k--;
    a[0] = 1;
    while (k--){
    mul(3);
    }
    if (t == 0)mul(3);
    if (t == 1)mul(4);
    if (t == 2)mul(6);
    int i;
    for (i = 1000; !a[i]; i--);
    while (i >= 0)cout << a[i--];
    return 0;
    }

  • 0
    @ 2015-08-01 10:06:47

    #include<cstdio>
    #include<cstring>
    using namespace std;
    const int dx[4]={1,0,-1,0};
    const int dy[4]={0,-1,0,1};
    bool v[30001][30001];
    int main()
    {
    int n,i,j,k,x,y,t,x1,y1;
    scanf("%d%d%d",&n,&x1,&y1);
    memset(v,false,sizeof(v));
    for(i=1;i<=n;i++)
    for(j=1;j<=n;j++)
    v[i][j]=true;
    x=1;y=1;k=1;t=3;
    while(k<=n*n)
    {
    if(x==x1&&y==y1)
    {
    printf("%d",k);
    return 0;

    }
    k++;
    v[x][y]=false;
    if(v[x+dx[t]][y+dy[t]]!=true)
    {
    t++; if( t==4) t=0;
    x=x+dx[t];
    y=y+dy[t];
    }
    else
    {
    x=x+dx[t];
    y=y+dy[t];
    }
    }
    return 0;
    }

  • 0
    @ 2015-06-28 11:29:15

    编译成功

    Free Pascal Compiler version 2.6.4 [2014/03/06] for i386
    Copyright (c) 1993-2014 by Florian Klaempfl and others
    Target OS: Win32 for i386
    Compiling foo.pas
    foo.pas(2,8) Note: Local variable "q" not used
    foo.pas(2,10) Note: Local variable "t" not used
    foo.pas(2,12) Note: Local variable "s" not used
    Linking foo.exe
    22 lines compiled, 0.0 sec , 28192 bytes code, 1628 bytes data
    3 note(s) issued

    测试数据 #0: Accepted, time = 0 ms, mem = 432 KiB, score = 10

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

    测试数据 #2: Accepted, time = 15 ms, mem = 432 KiB, score = 10

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

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

    测试数据 #5: Accepted, time = 15 ms, mem = 432 KiB, score = 10

    测试数据 #6: Accepted, time = 0 ms, mem = 432 KiB, score = 10

    测试数据 #7: Accepted, time = 0 ms, mem = 432 KiB, score = 10

    测试数据 #8: Accepted, time = 15 ms, mem = 432 KiB, score = 10

    测试数据 #9: Accepted, time = 0 ms, mem = 432 KiB, score = 10

    Accepted, time = 45 ms, mem = 432 KiB, score = 100
    代码

    var
    n,i,j,q,t,s,d,e:integer;
    ans:longint;
    begin
    readln(n,i,j); d:=n div 2; ans:=0;
    for e:=1 to d do
    if (i=1)or(i=n)or(j=1)or(j=n) then
    begin
    if i=1 then ans:=j+ans;
    if i=n then ans:=2*(n-1)+n-j+1+ans;
    if j=1 then if i=1 then ans:=1+ans
    else ans:=3*(n-1)+n-i+1+ans;
    if j=n then ans:=n-1+i+ans;
    break;
    end
    else
    begin
    ans:=ans+4*(n-1);
    n:=n-2;
    i:=i-1;j:=j-1;
    end;
    writeln(ans);
    end.

  • 0
    @ 2015-04-23 18:46:35

    不明白只发程序不发题解的楼下各位是什么心态- -我不觉得会有人蛋疼的看完这些程序。。。

    • @ 2015-04-23 18:50:47

      不过粗略一看下面的代码似乎跟我想的好像也差不多。。。也是差不多枚举模拟+点算又不算是数学的东西.....

      也是一圈一圈来的?

  • 0
    @ 2015-02-06 19:27:28

    测试数据 #0: Accepted, time = 0 ms, mem = 744 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 740 KiB, score = 10
    测试数据 #2: Accepted, time = 0 ms, mem = 744 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 740 KiB, score = 10
    测试数据 #4: Accepted, time = 0 ms, mem = 740 KiB, score = 10
    测试数据 #5: Accepted, time = 0 ms, mem = 740 KiB, score = 10
    测试数据 #6: Accepted, time = 7 ms, mem = 744 KiB, score = 10
    测试数据 #7: Accepted, time = 0 ms, mem = 744 KiB, score = 10
    测试数据 #8: Accepted, time = 0 ms, mem = 744 KiB, score = 10
    测试数据 #9: Accepted, time = 0 ms, mem = 744 KiB, score = 10
    Accepted, time = 7 ms, mem = 744 KiB, score = 100
    代码
    var
    z,i,j,l,n,m,x,zong,y,xs,xx,yz,yy,x1,y1:longint;
    r:real;
    function min(a,b:longint):longint;
    begin
    if a<b then exit(a) else exit(b);
    end;
    begin
    readln(n,x,y);
    xs:=x-1;
    xx:=n-x;
    yz:=y-1;
    yy:=n-y;
    m:=min(min(xs,xx),min(yz,yy)); {writeln(m);}
    l:=0; z:=n;
    for i:=1 to m do
    begin
    l:=(n-1)*4+l;
    dec(n); dec(n);
    end; {writeln(n,' ',l);}zong:=1; x1:=1;y1:=1;
    x:=x-m;
    y:=y-m; { writeln(x,' ',y); }
    if (x<>1)or (y<>1)then while (n-1)*4>zong do
    begin
    if zong<n then inc(y1);
    if (zong>=n) and(zong<2*n-1)then inc(x1);
    if (zong>=2*n-1)and(zong<3*n-2)then dec(y1);
    if (zong>=3*n-2)and (zong<4*n-4)then dec(x1);
    inc(zong);
    if (x1=x) and(y1=y)then break;
    end else zong:=1;
    writeln(zong+l);
    readln;

    end.//7ms 哪来的?!!!!!!!!

  • 0
    @ 2015-02-02 17:30:27

    ###Code
    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    #include<math.h>
    void sq();
    void cl();
    int x,y,m=0,n,n1,n2;
    void sq()
    {
    if(x==n1||x==n2||y==n1||y==n2) cl();
    else {
    m=m+(n2-n1)*4;
    n1++;
    n2--;
    sq();
    }
    }
    void cl()
    {
    if(x==n1) printf("%d",m+1+y-n1);
    else if(x==n2) printf("%d",m+(n2-n1)*3+1-y+n1);
    else if(y==n1) printf("%d",m+(n2-n1)*3+1+n2-x);
    else if(y==n2) printf("%d",m+n2-n1+1+x-n1);
    }
    int main()
    {
    int i,j;
    scanf("%d%d%d",&n,&x,&y);
    n1=1;
    n2=n;
    sq();
    return 0;
    }

  • 0
    @ 2015-02-01 10:27:51

    var
    n,sum,x,y,x1,y1,i:longint;
    begin
    readln(n,x,y);
    sum:=1;x1:=1;y1:=1;
    for i:=1 to (n+1) div 2 do
    begin
    inc(sum,n+1-i*2);y1:=y1+n+1-i*2;
    if (x1=x) and (y1>=y) then begin writeln(sum-(y1-y));halt;end;
    inc(sum,n+1-i*2);x1:=x1+n+1-i*2;
    if (y1=y) and (x<=x1) then begin writeln(sum-(x1-x));halt;end;
    inc(sum,n+1-i*2);y1:=y1-(n+1-i*2);
    if (x1=x) and (y1<=y) then begin writeln(sum-(y-y1));halt;end;
    inc(sum,n-i*2);x1:=x1-(n-i*2);
    if (y1=y) and (x1<=x) then begin writeln(sum-(x-x1));halt;end;
    inc(sum);y1:=y1+1;
    end;
    end.

  • 0
    @ 2014-12-15 22:05:21

    #include<iostream>
    #include<cmath>
    using namespace std;
    int n,i,j,q;
    int main()
    {
    cin>>n>>i>>j;
    if(i>n/2&&j>n/2)q=min(n-i+1,n-j+1);
    if(i>n/2&&j<=n/2)q=min(n-i+1,j);
    if(i<=n/2&&j<=n/2)q=min(i,j);
    if(i<=n/2&&j>n/2)q=min(i,n-j+1);
    if(i>j)cout<<-4*q*q+4*n*q+2*q+1-i-j;
    else cout<<-4*q*q+4*q*n-4*n+6*q+i+j-3;
    return 0;
    }

  • 0
    @ 2014-12-14 18:41:08

    var
    n,sum,x,y,x1,y1,i:longint;
    begin
    readln(n,x,y);
    sum:=1;x1:=1;y1:=1;
    for i:=1 to (n+1) div 2 do
    begin
    inc(sum,n+1-i*2);y1:=y1+n+1-i*2;
    if (x1=x) and (y1>=y) then begin writeln(sum-(y1-y));halt;end;
    inc(sum,n+1-i*2);x1:=x1+n+1-i*2;
    if (y1=y) and (x<=x1) then begin writeln(sum-(x1-x));halt;end;
    inc(sum,n+1-i*2);y1:=y1-(n+1-i*2);
    if (x1=x) and (y1<=y) then begin writeln(sum-(y-y1));halt;end;
    inc(sum,n-i*2);x1:=x1-(n-i*2);
    if (y1=y) and (x1<=x) then begin writeln(sum-(x-x1));halt;end;
    inc(sum);y1:=y1+1;
    end;
    end.

  • 0
    @ 2014-11-26 21:31:27

    #include<iostream>
    using namespace std;
    main()
    {
    int a,b,c,d,e=0,f=0,g=0,i,n,o=0,s=0,u=0,x[30001]={0},y[30001]={0};
    cin>>n>>a>>b;
    x[1]=1;
    if(n%2==1)
    {
    u=n;
    o=2;
    for(i=2;i<=n/2+1;i++)
    {
    x[i]=x[i-1]+(u-1)*4;
    u-=2;
    }
    for(i=n/2+2;i<=n;i++)
    {
    x[i]=x[i-1]-(o-1)*4;
    o+=2;
    }
    for(i=1;i<=n/2+1;i++)
    y[i]=x[n-i+1]+(n/2+1-i)*2;
    for(i=n/2+2;i<=n;i++)
    y[i]=x[n-i+1]+(i-(n/2+1))*2;
    c=a;
    d=b;
    if(a>n/2+1)
    c=n-a+1;
    if(b>n/2+1)
    d=n-b+1;
    e=min(c,d);
    f=e;
    g=n-e+1;
    if(a==f)
    s=x[f]+b-f;
    if(a==g)
    s=x[g]+g-b;
    if(b==f)
    s=y[f]+g-a;
    if(b==g)
    s=y[g]+a-f;
    if(a==f&&b==f)
    s=x[f];
    }
    else
    {
    u=n;
    o=2;
    for(i=2;i<=n/2;i++)
    {
    x[i]=x[i-1]+(u-1)*4;
    u-=2;
    }
    x[n/2+1]=x[n/2]+2;
    for(i=n/2+2;i<=n;i++)
    {
    x[i]=x[i-1]-o*4;
    o+=2;
    }
    for(i=1;i<=n/2;i++)
    y[i]=x[n-i+1]+(n/2-i)*2+1;
    for(i=n/2+1;i<=n;i++)
    y[i]=x[n-i+1]+(i-(n/2))*2-1;
    c=a;
    d=b;
    if(a>n/2)
    c=n-a+1;
    if(b>n/2)
    d=n-b+1;
    e=min(c,d);
    f=e;
    g=n-e+1;
    if(a==f)
    s=x[f]+b-f;
    if(a==g)
    s=x[g]+g-b;
    if(b==f)
    s=y[f]+g-a;
    if(b==g)
    s=y[g]+a-f;
    if(a==f&&b==f)
    s=x[f];
    }
    cout<<s;
    }

  • 0
    @ 2014-11-24 15:16:00

    Var
    n,x,y,k,ans,m,i:longint;
    function min(a,b,c,d:longint):longint;
    begin
    if a<b then min:=a
    else min:=b;
    if c<min then
    min:=c;
    if d<min then
    min:=d;
    end;
    begin
    readln(n,x,y);
    if n=1 then
    begin
    writeln(1);
    exit;
    end;
    k:=min(x,y,n-x+1,n-y+1);
    ans:=0;
    m:=n;
    for i:=1 to k-1 do
    begin
    inc(ans,(m-1)*4);
    dec(m,2);
    end;
    if k=x then inc(ans,y-k+1)
    else if k=n-y+1 then inc(ans,m+x-k)
    else if k=n-x+1 then inc(ans,(m-1)*2+n-y+2-k)
    else if k=y then inc(ans,(m-1)*3+n-x+2-k);
    writeln(ans);
    end.

信息

ID
1913
难度
6
分类
(无)
标签
递交数
2025
已通过
622
通过率
31%
被复制
16
上传者