// 7.19-7.29 东北大学秦皇岛校区十天训练营,题目都挂在了Vjudge上。训练期间比较忙,没空更博总结,回来继续补题消化。
// https://vjudge.net/contest/312902
https://vjudge.net/contest/313217
https://vjudge.net/contest/313584
https://vjudge.net/contest/314412
https://vjudge.net/contest/314730
https://vjudge.net/contest/314974
Day1
这天授课主题是简单图论,节奏挺好,wls两小时理完图论里的基本知识点。
下午的赛题就偏入门了(简单图论无疑),只涉及到最短路问题和简单的搜索以及一些奇怪的技巧。(差分约束呢?最小生成树呢?强连通分量呢?)
A - Jzzhu and Cities (补)
#include<iostream> #include<cstdio> #include<cstring> #include<queue> #include<vector> using namespace std; typedef long long ll; const int maxn = 200010; struct Edge { int to; bool istrain; ll w; Edge(int v, bool is, ll ww):to(v), istrain(is), w(ww){} bool operator<(const Edge& a)const { if(w==a.w) return istrain; // 非火车节点先更新 return w > a.w; } }; vector<Edge> G[maxn]; bool vis[maxn]; int d[maxn]; int Dijkstra() { memset(d, 0x3f, sizeof(d)); memset(vis, 0, sizeof(vis)); d[1] = 0; int res = 0; priority_queue<Edge> q; q.push(Edge(1, 0, 0)); while(!q.empty()) { Edge tmp = q.top(); q.pop(); int u = tmp.to; if(vis[u]) continue; vis[u] = 1; // d[u] = tmp.w; if(tmp.istrain) ++res; for(int i=0;i<G[u].size();i++) { int v = G[u][i].to; if(!vis[v] && d[v]>=d[u]+G[u][i].w) { d[v] = d[u] + G[u][i].w; q.push(Edge(v, G[u][i].istrain, d[v])); } } } return res; } int main() { int n, m, k; cin>>n>>m>>k; int u, v, w; for(int i=0;i<m;i++) { scanf("%d %d %d", &u, &v, &w); G[u].push_back(Edge(v, 0, w)); G[v].push_back(Edge(u, 0, w)); } for(int i=0;i<k;i++) { scanf("%d %d", &v, &w); G[1].push_back(Edge(v, 1, w)); // G[v].push_back(Edge(1, 1, w)); } printf("%d\n", k-Dijkstra()); return 0; }
B - Phillip and Trains BFS 注意打标记!!!(虽然只是3*100的地图也要爆内存!)
#include<iostream> #include<cstdio> #include<cstring> #include<queue> using namespace std; int n, k, sx; char mp[3][110]; bool vis[3][110]; struct node { int x, y; node(int _x, int _y):x(_x), y(_y) {} }; bool check(int x, int y) { if(x<0 || x>2) return false; if(y>=n) return true; if(mp[x][y]=='.') return true; return false; } bool bfs() { queue<node> q; q.push(node(sx, 0)); while(q.size()) { node now = q.front(); q.pop(); if(now.y>=n) { return true; } // printf("(%d,%d) -> ", now.x, now.y); int nx = now.x, ny = now.y+1; if(!check(nx, ny)) continue; // 向右走一步 for(int i=-1;i<=1;i++) { // 尝试三个方向移动 nx = now.x + i; if(check(nx, ny) && check(nx, ny+1) && check(nx, ny+2) && !vis[nx][ny+2]) { q.push(node(nx, ny+2)); vis[nx][ny+2] = 1; } } } return false; } int main() { int t; cin>>t; while(t--) { scanf("%d %d", &n, &k); getchar(); memset(vis, 0, sizeof(vis)); for(int i=0;i<3;i++) { scanf("%s", mp[i]); if(mp[i][0]=='s') sx = i; } printf("%s\n", bfs()?"YES":"NO"); } return 0; }
Day2
Day3
Day4
Day5
Day6