2021.1.3 校測 題解報告
阿新 • • 發佈:2021-01-03
2021.1.3 校測 題解報告
前言:
做題情況:
T1 : 100 Pts
T2 : 100 Pts
T3 : 35 Pts
半個小時二百分 兩個小時三十五分...
關於考試:
搜尋專場
爆搜居多
T1 T2 都寫了優化的 但是發現好像沒有用 資料似乎不是太毒瘤 但是跑的快一點也是一點安慰了 雖然並沒有什麼鳥用就是了
T3 寫了優化 但是好像是負優化...
另:
題目什麼的懶得粘了.... 就這樣吧
下次來了再補
T1 math
/* Time: 1.3 Worker: Blank_space Source: Problem 1 數學題 */ /*--------------------------------------------*/ #include<cstdio> using namespace std; /*--------------------------------------標頭檔案*/ const int A = 1e4 + 7; const int B = 1e5 + 7; const int C = 1e6 + 7; const int D = 1e7 + 7; const int mod = 1e9 + 7; const int INF = 0x3f3f3f3f; const int FFF = 0x8fffffff; /*------------------------------------常量定義*/ int n, p, s, ans, a[11]; int d[11] = {0, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55}; /*------------------------------------變數定義*/ inline int read() { int x = 0, f = 1; char ch = getchar(); while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();} while(ch >= '0' && ch <= '9') {x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar();} return x * f; } /*----------------------------------------快讀*/ void print() { for(int i = 1; i <= n; i++) printf("%d ", a[i]); puts(""); } void dfs(int t, int sum, int last) { if(sum > s) return ; if(t > 1 && sum + (n - t + 1) * last + d[n - t + 1] * p < s) return ; if(t == n + 1) { if(sum == s) ans++; // print(); return ; } if(t == 1) for(int i = 1; i <= s - n + 1; i++) a[t] = i, dfs(t + 1, sum + i, i); else for(int i = -p; i <= p; i++) if(last + i > 0) a[t] = last + i, dfs(t + 1, sum + last + i, last + i); } /*----------------------------------------函式*/ int main() { freopen("math.in", "r", stdin); freopen("math.out", "w", stdout); n = read(); s = read(); p = read(); if(!p) {printf("%d", s % n == 0 ? 1 : 0); return 0;} dfs(1, 0, 0); printf("%d", ans); return 0; }
T2 grid
/* Time: 1.3 Worker: Blank_space Source: Problem 2 網格 */ /*--------------------------------------------*/ #include<cstdio> #include<queue> using namespace std; /*--------------------------------------標頭檔案*/ const int A = 1e4 + 7; const int B = 1e5 + 7; const int C = 1e6 + 7; const int D = 1e7 + 7; const int mod = 1e9 + 7; const int INF = 0x3f3f3f3f; const int FFF = 0x8fffffff; /*------------------------------------常量定義*/ int n, sx, sy, tx, ty, dis1[1010][1010], dis2[1010][1010]; int dx[5] = {0, 1, -1, 0, 0}; int dy[5] = {0, 0, 0, 1, -1}; int vis1[1010][1010], vis2[1010][1010]; bool mp[1010][1010], p; struct node { int x, y; }; queue <node> q1; queue <node> q2; /*------------------------------------變數定義*/ inline int read() { int x = 0, f = 1; char ch = getchar(); while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();} while(ch >= '0' && ch <= '9') {x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar();} return x * f; } /*----------------------------------------快讀*/ void bfs() { while(!q1.empty() && !q2.empty()) { if(q1.size() <= q1.size() && !q1.empty()) { node h = q1.front(); q1.pop(); int x = h.x, y = h.y; for(int i = 1; i <= 4; i++) { int xx = x + dx[i], yy = y + dy[i]; if(xx < 1 || xx > n || yy < 1 || yy > n || vis1[xx][yy] || mp[xx][yy]) continue; vis1[xx][yy] = vis1[x][y] + 1; if(vis2[xx][yy]) {printf("%d", vis1[xx][yy] + vis2[xx][yy] - 2); p = 1; return ;} q1.push((node){xx, yy}); } } if(q1.size() > q2.size() && !q2.empty()) { node h = q2.front(); q2.pop(); int x = h.x, y = h.y; for(int i = 1; i <= 4; i++) { int xx = x + dx[i], yy = y + dy[i]; if(xx < 1 || xx > n || yy < 1 || yy > n || vis2[xx][yy] || mp[xx][yy]) continue; vis2[xx][yy] = vis2[x][y] + 1; if(vis1[xx][yy]) {printf("%d", vis1[xx][yy] + vis2[xx][yy] - 2); p = 1; return ;} q2.push((node){xx, yy}); } } } } /*----------------------------------------函式*/ int main() { // freopen("out", "r", stdin); freopen("grid.in", "r", stdin); freopen("grid.out", "w", stdout); n = read(); for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) mp[i][j] = read(); sx = read(); sy = read(); tx = read(); ty = read(); q1.push((node){sx, sy}); q2.push((node){tx, ty}); vis1[sx][sy] = 1; vis2[tx][ty] = 1; bfs(); if(!p) puts("-1"); return 0; }
T3 gokigen
/* Time: 1.3 Worker: Blank_space Source: C 戈蘭斜 我真的不行了... */ /*--------------------------------------------*/ #include<cstdio> #include<iostream> using namespace std; /*--------------------------------------標頭檔案*/ const int A = 1e4 + 7; const int B = 1e5 + 7; const int C = 1e6 + 7; const int D = 1e7 + 7; const int mod = 1e9 + 7; const int INF = 0x3f3f3f3f; const int FFF = 0x8fffffff; /*------------------------------------常量定義*/ int n, mp[10][10], fa[110], cur[10][10], limit[10][10], c[10][10], ans[10][10]; bool p, vis; int dx[5] = {0, 0, 1, 0, 1}; int dy[5] = {0, 0, 0, 1, 1}; /*------------------------------------變數定義*/ inline int read() { int x = 0, f = 1; char ch = getchar(); while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();} while(ch >= '0' && ch <= '9') {x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar();} return x * f; } /*----------------------------------------快讀*/ int find(int x) {return !fa[x] ? x : find(fa[x]);} bool check(int x, int y) { if(mp[x][y] == -1) return 1; if(cur[x][y] <= mp[x][y] && cur[x][y] + limit[x][y] >= mp[x][y]) return 1; return 0; } void dfs(int x, int y) { if(y == n) y = 1, x++; if(x == n) {p = 1; return ;} cur[x][y]++; cur[x + 1][y + 1]++;//連邊 limit[x][y]--; limit[x + 1][y + 1]--;//邊的限制 limit[x + 1][y]--; limit[x][y + 1]--;//可連的邊 vis = 0; for(int i = 1; i <= 4; i++) { int xx = x + dx[i], yy = y + dy[i]; if(!check(xx, yy)) {vis = 1; break;}//沒救了 } if(!vis) { // int u = find(c[x][y]), v = find(c[x + 1][y + 1]); int u = find((x - 1) * n + y), v = find(x * n + y + 1); if(u != v) { ans[x][y] = 1; fa[u] = v; dfs(x, y + 1); if(p) return ; fa[u] = 0; } } cur[x][y]--; cur[x + 1][y + 1]--; cur[x + 1][y]++; cur[x][y + 1]++; vis = 0; for(int i = 1; i <= 4; i++) { int xx = x + dx[i], yy = y + dy[i]; if(!check(xx, yy)) {vis = 1; break;} } if(!vis) { // int u = find(c[x + 1][y]), v = find(c[x][y + 1]); int u = find(x * n + y), v = find((x - 1) * n + y + 1); if(u != v) { ans[x][y] = 0; fa[u] = v; dfs(x, y + 1); if(p) return ; fa[u] = 0; } } cur[x + 1][y]--; cur[x][y + 1]--; limit[x][y]++; limit[x + 1][y + 1]++; limit[x + 1][y]++; limit[x][y + 1]++; } /*----------------------------------------函式*/ int main() { freopen("gokigen.in","r",stdin); freopen("gokigen.out","w",stdout); n = read() + 1; int k = 0; for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) { char s; cin >> s; if(s >= '0' && s <= '9') mp[i][j] = s - 48; else mp[i][j] = -1; c[i][j] = ++k; limit[i][j] = 4; if((i == 1 || i == n) && (j == 1 || j == n)) limit[i][j] = 1; else if(i == 1 || i == n || j == 1 || j == n) limit[i][j] = 2; } // for(int i = 1; i <= k; i++) fa[i] = i; dfs(1, 1); n--; for(int i = 1; i <= n; i++) { for(int j = 1; j <= n; j++) if(ans[i][j]) printf("\\"); else printf("/"); puts(""); } return 0; }