讨论 / "4"到底是什么样的? (206)
zzkca930110 2011-10-18 19:35:00
点我顶贴 收藏 删除
"4"到底是什么样的?

int a[10][10],b[10];

int main ()

{

int n,m,i,j,p,x1,x2,x3,x4;

char ch;

cin>>n>>m;

for (i=0; i<n; i++)

for (j=0; j<m; j++) {

cin>>ch;

a[i][j]=ch-’0’;

}

if (m<2 || n<2) {

cout<<"1"<<endl;

return 0;

}

p=0;

for (i=0; i<n-1; i++)

for (j=0; j<m-1; j++) {

x1=a[i][j];

x2=a[i][j+1];

x3=a[i+1][j];

x4=a[i+1][j+1];

if (x1+x2+x4==3 && x3==0) b[p++]=1;

if (x2+x3+x4==3 && x1==0) b[p++]=2;

if (x1+x2+x3==3 && x4==0) b[p++]=3;

if (x1+x3+x4==3 && x2==0) b[p++]=4;

}

if (p==0) {

cout<<"1"<<endl;

return 0;

}

if (p==1) {

cout<<"7"<<endl;

return 0;

}

if (p==2) {

cout<<"4"<<endl;

return 0;

}

if (p==8) {

cout<<"8"<<endl;

return 0;

}

if (p==6) {

if (b[1]==4) cout<<"6"<<endl;

else cout<<"9"<<endl;

return 0;

}

if (b[1]==1 && b[2]==4) cout<<"0"<<endl;

if (b[1]==2 && b[2]==3) cout<<"2"<<endl;

if (b[1]==2 && b[2]==1) cout<<"3"<<endl;

if (b[1]==4 && b[2]==1) cout<<"5"<<endl;

return 0;

}

测试结果1: 通过本测试点|有效耗时63:ms

测试结果2: 通过本测试点|有效耗时47:ms

测试结果3: 通过本测试点|有效耗时47:ms

测试结果4: 通过本测试点|有效耗时46:ms

测试结果5: 通过本测试点|有效耗时47:ms

测试结果6: 通过本测试点|有效耗时47:ms

测试结果7: 测试结果错误.错误结果为:3

正确结果应为:4

测试结果8: 通过本测试点|有效耗时47:ms

测试结果9: 通过本测试点|有效耗时47:ms

测试结果10: 通过本测试点|有效耗时47:ms

#1 zzkca930110@2008-08-30 06:57:00
回复 删除
…………………………

打错一个字!

p==3打成p==2

int a[10][10],b[10];

int main ()

{

int n,m,i,j,p,x1,x2,x3,x4;

char ch;

cin>>n>>m;

for (i=0; i<n; i++)

for (j=0; j<m; j++) {

cin>>ch;

a[i][j]=ch-’0’;

}

if (m<2 || n<2) {

cout<<"1"<<endl;

return 0;

}

p=0;

for (i=0; i<n-1; i++)

for (j=0; j<m-1; j++) {

x1=a[i][j];

x2=a[i][j+1];

x3=a[i+1][j];

x4=a[i+1][j+1];

if (x1+x2+x4==3 && x3==0) b[p++]=1;

if (x2+x3+x4==3 && x1==0) b[p++]=2;

if (x1+x2+x3==3 && x4==0) b[p++]=3;

if (x1+x3+x4==3 && x2==0) b[p++]=4;

}

if (p==0) {

cout<<"1"<<endl;

return 0;

}

if (p==1) {

cout<<"7"<<endl;

return 0;

}

if (p==3) {

cout<<"4"<<endl;

return 0;

}

if (p==8) {

cout<<"8"<<endl;

return 0;

}

if (p==6) {

if (b[1]==4) cout<<"6"<<endl;

else cout<<"9"<<endl;

return 0;

}

if (b[1]==1 && b[2]==4) cout<<"0"<<endl;

if (b[1]==2 && b[2]==3) cout<<"2"<<endl;

if (b[1]==2 && b[2]==1) cout<<"3"<<endl;

if (b[1]==4 && b[2]==1) cout<<"5"<<endl;

return 0;

}

#2 Wych@2009-05-18 01:47:00
回复 删除
大家帮忙看看吧,按照标程思想解的,为什么第七点数据wrong answer=1可是标准答案为4?得90分?

program rq206(input,output);

const num :array [0..9] of longint=(1324,0,3142,3344,234,1234,112324,3,13123424,132344);

var n,m,i,j,f :longint;

ch :char;

g :array [0..100,0..100] of boolean;

begin

readln(n,m);

fillchar(g,sizeof(g),false);

for i:=1 to n do

begin

for j:=1 to m do

begin

read(ch);

if ch=’1’ then g[i,j]:=true;

end;

readln;

end;

f:=0;

for i:=1 to n do

for j:=1 to m do

if g[i,j] then

begin

if (g[i,j+1]) and (g[i+1,j]) and (not g[i+1,j+1]) then f:=f*10+1;

if (g[i,j+1]) and (g[i-1,j]) and (not g[i-1,j+1]) then f:=f*10+2;

if (g[i+1,j]) and (g[i,j-1]) and (not g[i+1,j-1]) then f:=f*10+3;

if (g[i-1,j]) and (g[i,j-1]) and (not g[i-1,j-1]) then f:=f*10+4;

end;

for i:=0 to 9 do

if f=num[i] then write(i);

end.

#3 wjltz@2011-10-18 19:35:00
回复 删除
同楼上啊
查看更多回复
提交回复