QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#68830 | #5112. Where Am I? | chenshi# | RE | 2ms | 3072kb | C++14 | 1.4kb | 2022-12-21 10:31:29 | 2022-12-21 10:31:30 |
Judging History
answer
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
const int o=9999;
int n,m,dx[o],dy[o],cnt,ans1,ans2;char s[110][110];
struct State{int sx,sy,x,y;};
vector<State> bg1,bg2,Ans;
void slv(vector<State> vec,int t){
if((int)vec.size()==1){
ans1+=--t;
if(t>ans2) ans2=t,Ans.clear();
if(t==ans2) Ans.push_back(vec[0]);
return;
}
vector<State> v1,v2;
for(int i=vec.size();i--;){
vec[i].x+=dx[t];vec[i].y+=dy[t];
if(vec[i].x>=1&&vec[i].x<=n&&vec[i].y>=1&&vec[i].y<=m&&s[vec[i].x][vec[i].y]=='X') v1.push_back(vec[i]);
else v2.push_back(vec[i]);
}
if(!v1.empty()) slv(v1,t+1);
if(!v2.empty()) slv(v2,t+1);
}
inline bool cmp(State A,State B){if(A.sy^B.sy) return A.sy<B.sy;return A.sx<B.sx;}
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<40;++i){
for(int j=1;j<2*i;++j) dx[++cnt]=0,dy[cnt]=1;
for(int j=1;j<2*i;++j) dx[++cnt]=1,dy[cnt]=0;
for(int j=1;j<=2*i;++j) dx[++cnt]=0,dy[cnt]=-1;
for(int j=1;j<=2*i;++j) dx[++cnt]=-1,dy[cnt]=0;
}
for(int j=1;j<=m;++j) for(int i=1;i<=n;++i)
do s[i][m-j+1]=getchar();while(s[i][m-j+1]-'X'&&s[i][m-j+1]-'.');
for(int i=1;i<=n;++i) for(int j=1;j<=m;++j)
if(s[i][j]=='X') bg1.push_back((State){i,j,i,j});
else bg2.push_back((State){i,j,i,j});
slv(bg1,1);slv(bg2,1);
printf("%.5lf\n%d\n",ans1*1.0/(n*m),ans2);
sort(Ans.begin(),Ans.end(),cmp);
for(int i=0,sz=Ans.size();i<sz;++i) printf("(%d,%d) ",Ans[i].sx,Ans[i].sy);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 3072kb
input:
1 1 X
output:
0.00000 0 (1,1)
result:
ok correct!
Test #2:
score: 0
Accepted
time: 1ms
memory: 2996kb
input:
2 1 .X
output:
0.00000 0 (1,1) (2,1)
result:
ok correct!
Test #3:
score: 0
Accepted
time: 2ms
memory: 3040kb
input:
2 1 X.
output:
0.00000 0 (1,1) (2,1)
result:
ok correct!
Test #4:
score: 0
Accepted
time: 2ms
memory: 3048kb
input:
1 2 . X
output:
0.00000 0 (1,1) (1,2)
result:
ok correct!
Test #5:
score: 0
Accepted
time: 0ms
memory: 2996kb
input:
1 2 X .
output:
0.00000 0 (1,1) (1,2)
result:
ok correct!
Test #6:
score: 0
Accepted
time: 2ms
memory: 3044kb
input:
2 1 XX
output:
3.00000 3 (1,1) (2,1)
result:
ok correct!
Test #7:
score: 0
Accepted
time: 2ms
memory: 3052kb
input:
3 3 XXX X.X XXX
output:
3.11111 5 (3,1) (3,2)
result:
ok correct!
Test #8:
score: -100
Runtime Error
input:
100 100 ..X....X....X....X....X....X....X....X....X....X....X....X....X....X....X....X....X....X....X....X.. .................................................................................................... X............................................................................................