題意,一個無向圖,求該無向圖中不小於3節點的最小奇數環。
思路bfs,但因為要求環上點的數目為奇數,所以不能簡單的用一個vis數組記錄點是否已訪問過,可以改成二維的,
vis[u][0]表示點在偶數環中出現過,vis[u][1]表示點在奇數環中出現過
#include #include #include #include #include #include #include #include #include #include #include #include #include #define eps 1e-6 #define LL long long using namespace std; const int maxn = 1000 + 10; const int INF = 0x3f3f3f3f; int n, m, kase; int vis[maxn][2], dis[maxn]; vector G[maxn]; void init() { for(int i = 1; i <= n; i++) G[i].clear(); cin >> n >> m; int u, v; for(int i = 0; i < m; i++) { cin >> u >> v; G[u].push_back(v); G[v].push_back(u); } } int bfs(int u) { memset(vis, 0, sizeof(vis)); queue q; q.push(u); dis[u] = 1; vis[u][1] = 1; while(!q.empty()) { int v = q.front(); q.pop(); for(int i = G[v].size() - 1; i >= 0; i--) { int tmp = G[v][i]; dis[tmp] = dis[v] + 1; if(tmp == u && dis[v] >= 3 && dis[v]%2 == 1) return dis[v]; if(vis[tmp][dis[tmp]%2]) continue; vis[tmp][dis[tmp]%2] = 1; q.push(G[v][i]); } } return INF; } void solve() { int ans = INF; for(int i = 1; i <= n; i++) ans = min(ans, bfs(i)); if(ans != INF) printf("Case %d: JYY has to use %d balls.\n", ++kase, ans); else printf("Case %d: Poor JYY.\n", ++kase); } int main() { //freopen("input.txt", "r", stdin); int t; cin >> t; while(t--) { init(); solve(); } return 0; }
UVA 11722(概率+幾何) Prob
The area Time Limit: 2000
C++開發本身是一個標准,各種實現之間有區別,對標准的理解
排序詳解(希爾,快排,歸並等),希爾歸並今天集中把幾種排序的
GLScene開源庫為Delphi提供了基於OpenG
Problem B: Audiophob