A. explosion problem in graph theory, shortest path, thinking
Gives a view from 1:00 to 1 meter per second, the start speed of flame propagation, is greater than if they encounter a flame will explode, the final explosion of the number of Q
Easy to draw the following rules: if the degree of explosion at some point, then the point is that the presence of greater than 1 shortest equal if the explosion at the edge, then this edge is not the shortest path
#include<iostream> #include<string> #include<cmath> #include<cstring> #include<vector> #include<map> #include<set> #include<algorithm> #include<queue> #include<stack> #include<sstream> #include<cstdio> #define INF 0x3f3f3f3f const int maxn = 300000 + 10; const double PI = acos(-1.0); typedef long Long LL; the using namespace STD; int n-, m; struct Edge { int V, w; Edge ( int A, int B) {V = A, w = B;}}; // V end point, w right side struct Node { int ID, dis; // ID dis point number temporal distance Node ( int A, int B) {A = ID, dis = B;} Friend BOOL operator < (Node A, Node B) { return a.dis> B .dis; // each team let out a small distance } }; the Vector <Edge>E [MAXN]; int DIS [MAXN]; // record the shortest BOOL VIS [MAXN]; // record is found shortest int ANS; void the Dijkstra () { int S = . 1 ; // S under the circumstances to change the starting point for ( int I = 0 ; I <= n-; I ++) DIS [I] = INF, VIS [I] = 0 ; DIS [S] = 0 ; The priority_queue <Node> Q; Q.push (Node (S, 0 ) ); the while (! ) {Q.empty () Node U = Q.top (); Q.pop (); if (vis[u.id])continue; vis[u.id] = 1; for (int i = 0; i < e[u.id].size(); i++) {//遍历邻居 edge y = e[u.id][i]; if (vis[y.v])continue; if (dis[y.v] > y.w + dis[u.id]) { dis[y.v] = y.w + u.dis; Q.push(node(y.v, dis[y.v]));//更新最短路 } } } } int main() { scanf("%d%d", &n, &m); int u, v, w; for (int i = 0; i < m; i++) { scanf("%d%d%d", &u, &v, &w); e[u].push_back(edge(v, w)); if (u != v) e[v].push_back(edge(u, w)); } Dijkstra(); //for (int i = 1; i <= n; i++) printf("%d ", dis[i]); for (int i = 1; i <= n; i++) { int cnt = 0; for (int j = 0; j < e[i].size(); j++) { if (dis[i] == dis[e[i][j].v] + e[i][j].w) cnt++; else if (i >= e[i][j].v && dis[i] + e[i][j].w > dis[e[i][j].v] && dis[e[i][j].v] + e[i][j].w > dis[i]) ans++; //core } if (cnt > 1) ans++; } printf("%d", ans); return 0; }
B. simulation title / title formula
In fact, gives the date, begged date n days
#include <bits/stdc++.h> using namespace std; inline void read(int &a) { int ch = getchar(); while (ch < '0') ch = getchar(); a = 0; while (ch >= '0') a = a * 10 + ch - '0', ch = getchar(); } int M[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; void work() { int Mo, y, m, d; read(Mo); read(y); read(m); read(d); int del = 0; while (Mo < int(1e9)) { del++; Mo += del; if (++d > M[m] + (m == 2 && y % 4 == 0 && (y % 100 != 0 || y % 400 == 0))) { d = 1; if (++m == 13) y ++, m = 1; } } printf("%d %d %d\n", y, m, d); } int main() { int T; read(T); while (T--) work(); return 0; }
C. next time
D. given a, b, k, gcd (a, b) = 1 find satisfy the equation ax + by = c, ab k-th small c <0 is