【心情】NOIP2017的感想
NOIP2017,我考挂了,心情既有点郁闷又有点不服气。
第3、4题都写挂了。
这次考试我的评测结果也很神奇,自己下官网数据竟然比结果高了10分,结果没申诉(不知道怎么申诉,老师也说没问题,然而obviously我肯定不会超时。~尴尬~),最后比省一查了5分!!无语!!
最后调试后,调到了360分。(所以说吗,不服气~)
附上第3题,AK的代码:
#include<bits/stdc++.h> using namespace std; const int dx[4] = {-1,0,1,0} , dy[4] = {0,1,0,-1}; int n,m,ans[105][105],Map[105][105],front,rear,x[100005],y[100005],cost[100005]; int main() { freopen("chess.in","r",stdin); freopen("chess.out","w",stdout); scanf("%d %d",&m,&n); for (int i = 0 ; i <= m+1 ; i ++) for (int j = 0 ; j <= m+1 ; j ++) { Map[i][j] = -1; ans[i][j] = INT_MAX; } for (int i = 1 ; i <= n ; i++) { int tx,ty,c; scanf("%d %d %d",&tx,&ty,&c); Map[tx][ty] = c; } ans[1][1] = 0; front = 1 ; rear = 1; x[1] = 1 ; y[1] = 1; cost[1] = 0; while (front <= rear) { int nx = x[front] , ny = y[front] , nc = cost[front]; for (int i = 0 ; i < 4 ; i ++) { int tx = nx + dx[i] , ty = ny + dy[i] , now; if (tx > 0 && tx <= m && ty > 0 && ty <= m) { if (Map[tx][ty] != -1) { now = (Map[nx][ny] == Map[tx][ty]) ? nc : nc + 1; if (now < ans[tx][ty]) { ans[tx][ty] = now; ++rear; x[rear] = tx; y[rear] = ty; cost[rear] = now; } } else { now = nc + 2; if (now < ans[tx][ty]) ans[tx][ty] = now; for (int j = 0 ; j < 4 ; j ++) { int rx = tx + dx[j] , ry = ty + dy[j]; now = (Map[nx][ny] == Map[rx][ry]) ? nc + 2:nc + 3; if (rx > 0 && rx <= m && ry >0 && ry <= m && Map[rx][ry] != -1 && now < ans[rx][ry]) { ans[rx][ry] = now; ++rear; x[rear] = rx; y[rear] = ry; cost[rear] = now; } } } } } front ++; } if (ans[m][m] == INT_MAX) cout<<-1<<endl; else cout<<ans[m][m]<<endl; return 0; }