Welcome To Administrator's Page of Judge Online of ACM ICPC, Peking University
--------------------------------------------------------------------------------
Source
Problem Id:1048 User Id:bobpkuhj
Memory:76K Time:10MS
Language:C Result:Accepted
Source
#include<stdio.h>
#include<stdlib.h>
int state[100][100],value[26],row,column,done;
char logic[100][100];
void hdsearch(int x,int y)
{
int dir,ish;
void process(int x,int y);
if(done)return;
dir=-1;ish=1;
while(!done)
{
if(logic[x][y]>='A'&&logic[x][y]<='Z')
process(x,y);
else switch(logic[x][y])
{
case '-':
case 'o':
case ':':
case '\\':
case '/':
y=y+dir;
break;
case '|':
x+=dir;
break;
case ')':
case '>':
if(state[x-1][y-1]==-1)
{x--;y--;}
else if(state[x+1][y-1]==-1)
{x++;y--;}
else
{
if(logic[x][y]==')')
state[x][y]=state[x-1][y]&state[x+1][y];
else
state[x][y]=state[x-1][y]|state[x+1][y];
process(x,y);
}
break;
case '+':
if(ish)
{
if(x<row-1&&logic[x+1][y]=='|')
dir=1;
else
dir=-1;
ish=0;
x+=dir;
}
else
{
if(y<column-1&&logic[x][y+1]=='-')
dir=1;
else
dir=-1;
ish=1;
y+=dir;
}
break;
}
}
return;
}
void process(int x,int y)
{
int dir,ish;
void hdsearch(int x,int y);
if(done)return;
if(logic[x][y]>='A'&&logic[x][y]<='Z')
{
state[x][y]=value[logic[x][y]-'A'];
if(y<column-1&&logic[x][y+1]=='-')
{
ish=1;
dir=1;
y++;
state[x][y]=state[x][y-1];
}
else if(y>0&&logic[x][y-1]=='-')
{
ish=1;
dir=-1;
y--;
state[x][y]=state[x][y+1];
}
else if(x<row-1&&logic[x+1][y]=='|')
{
ish=0;
dir=1;
x++;
state[x][y]=state[x-1][y];
}
else if(x>0&&logic[x-1][y]=='|')
{
ish=0;
dir=-1;
x--;
state[x][y]=state[x+1][y];
}
}
else
{
ish=1;
dir=1;
}
while(!done)
{
switch(logic[x][y])
{
case '-':
case ':':
case ')':
case '>':
y+=dir;
state[x][y]=state[x][y-dir];
break;
case 'o':
y+=dir;
state[x][y]=state[x][y-dir]^1;
break;
case '|':
x+=dir;
state[x][y]=state[x-dir][y];
break;
case '\\':
if(state[x+2][y]==-1)
hdsearch(x+2,y);
else
{
x++;
y++;
if(logic[x][y]==')')
state[x][y]=state[x-1][y-1]&state[x+1][y-1];
else
state[x][y]=state[x-1][y-1]|state[x+1][y-1];
}
break;
case '/':
if(state[x-2][y]==-1)
hdsearch(x-2,y);
else
{
x--;
y++;
if(logic[x][y]==')')
state[x][y]=state[x-1][y-1]&state[x+1][y-1];
else
state[x][y]=state[x-1][y-1]|state[x+1][y-1];
}
break;
case '+':
if(ish)
{
if(x<row-1&&logic[x+1][y]=='|')
dir=1;
else
dir=-1;
ish=0;
x+=dir;
state[x][y]=state[x-dir][y];
}
else
{
if(y<column-1&&logic[x][y+1]=='-')
dir=1;
else
dir=-1;
ish=1;
y+=dir;
state[x][y]=state[x][y-dir];
}
break;
case '?':
printf("%d\n",state[x][y]);
done=1;
break;
}
}
return;
}
main()
{
int i,j,flag;
char c;
while(scanf("%c",&c)==1)
{
column=0;
for(i=0;(i>0?(c=getchar()):1)&&c!='*';i++)
{
if(c=='\n'){i--;continue;}
logic[i][0]=c;
for(j=1;(c=getchar())!='\n';j++)
{
logic[i][j]=c;
}
if(j>column)
column=j;
for(;j<100;j++)
logic[i][j]=' ';
}
c=getchar();
while(c=='\n')c=getchar();
row=i;
while(c!='*')
{
if(c=='\n')continue;
value[0]=c-'0';
for(i=1;i<26;i++)
{
value[i]=getchar();
value[i]-='0';
}
c=getchar();
for(i=0;i<row;i++)
for(j=0;j<column;j++)
state[i][j]=-1;
flag=0;
for(j=0;j<column&&!flag;j++)
for(i=0;i<row;i++)
if(logic[i][j]>='A'&&logic[i][j]<='Z')
{flag=1;break;}
done=0;
process(i,j-1);
c=getchar();
}
printf("\n");
c=getchar();
}
exit(0);
}
Admin's Home Page
--------------------------------------------------------------------------------
All Copyright Reserved 2003
Any problem, Please Contact Administrator
没有合适的资源?快使用搜索试试~ 我知道了~
北大杭电acm题解(详细)
共1598个文件
txt:649个
html:604个
cpp:119个
5星 · 超过95%的资源 需积分: 34 120 下载量 121 浏览量
2011-06-19
12:44:22
上传
评论 7
收藏 7.7MB RAR 举报
温馨提示
北大杭电acm题解(详细)北大杭电acm题解(详细)北大杭电acm题解(详细)北大杭电acm题解(详细)北大杭电acm题解(详细)北大杭电acm题解(详细)
资源推荐
资源详情
资源评论
收起资源包目录
北大杭电acm题解(详细) (1598个子文件)
HDU.bmp 2.25MB
2056.bmp 417KB
2084.bmp 386KB
redraiment.bmp 352KB
2093.bmp 289KB
2056XY.bmp 201KB
2050b.bmp 198KB
2036n.bmp 184KB
1.bmp 170KB
3.bmp 123KB
2.bmp 123KB
6.bmp 123KB
4.bmp 123KB
5.bmp 123KB
1.bmp 123KB
2088.bmp 112KB
3.bmp 110KB
2.bmp 110KB
6.bmp 110KB
4.bmp 110KB
5.bmp 110KB
1.bmp 110KB
2056A.bmp 110KB
2036.bmp 84KB
2050m.bmp 78KB
2050n.bmp 44KB
3.bmp 26KB
2.bmp 26KB
1.bmp 26KB
1675c.bmp 20KB
1675b.bmp 20KB
1675.bmp 20KB
1675a.bmp 20KB
poj1811.c 17KB
1002 A + B Problem II.c 4KB
1003n.c 3KB
fastbixc.c 2KB
BOBPKUHJ.C 2KB
land.c 2KB
1005 Number Sequence.c 2KB
1003 Max Sum.c 2KB
1048 The Hardest Problem Ever.c 1KB
NEALZANE.C 1KB
1020 Encoding.c 1KB
1040 As Easy As A+B.c 941B
1096.c 559B
1093.c 528B
1092.c 428B
1090.c 407B
1094.c 400B
1091.c 387B
1021 Fibonacci Again.c 311B
1089.c 266B
1095.c 265B
HDU 2000-2099 解题报告.CHM 831KB
Building with Blocks bak2.cpp 9KB
Blocksbak2.cpp 9KB
1688 Dolphin Pool.cpp 7KB
standards.cpp 7KB
Building with Blocks bak1.cpp 6KB
Blocksbak1.cpp 6KB
1023 Train Problem II.cpp 5KB
1713_XieDi.cpp 5KB
random1_jlu.cpp 5KB
2179.cpp 5KB
1712 Flying Stars.cpp 4KB
kicc.cpp 4KB
random1.cpp 4KB
标程.cpp 4KB
09908043.cpp 4KB
hawking.cpp 4KB
random_dynamic.cpp 3KB
09908043.cpp 3KB
1292 Will Indiana Jones Get There.cpp 3KB
1686 Lazy Math Instructor.cpp 3KB
Blocks.cpp 3KB
Building with Blocks.cpp 3KB
JURY.cpp 3KB
random.cpp 3KB
1697.cpp 3KB
1087.cpp 3KB
00001140.cpp 3KB
1074 Doing Homework.cpp 3KB
1857_XieDi.cpp 3KB
1090chain.cpp 3KB
1041 Computer Transformation.cpp 3KB
1706_XieDi.cpp 3KB
1073 Online Judge.cpp 2KB
d.cpp 2KB
复件 1038.cpp 2KB
1878_XieDi.cpp 2KB
1683-Puzzlestan.cpp 2KB
1006 Tick and Tick.cpp 2KB
1459_XieDi.cpp 2KB
1698_XieDi.cpp 2KB
1708 Game.cpp 2KB
2165gunman.cpp 2KB
1022 Train Problem I.cpp 2KB
walls.cpp 2KB
1709 Crossword.cpp 2KB
共 1598 条
- 1
- 2
- 3
- 4
- 5
- 6
- 16
vonxy
- 粉丝: 3
- 资源: 14
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页