有点毒的比赛。
题目链接:https://www.jisuanke.com/contest/3870?view=challenges
B:
添加一个点连接所有救火点,路径设为0,就变成了跑两次dijkstra的题。
1 /* Contest nanchang_2019_online 2 * Problem B 3 * Team: Make One For Us 4 */ 5 #include6 7 using namespace std; 8 9 const long long int INF = 10000000000000L; 10 11 struct edge { 12 int u, v; 13 long long int w; 14 }; 15 16 struct node { 17 int u; 18 long long int d; 19 bool operator < (const node &n) const { 20 return d > n.d; 21 } 22 }; 23 24 long long int read(void) { 25 char ch; 26 do { 27 ch = getchar(); 28 } while (!isdigit(ch)); 29 long long int ret = 0; 30 while (isdigit(ch)) { 31 ret *= 10; 32 ret += ch - '0'; 33 ch = getchar(); 34 } 35 return ret; 36 } 37 38 void dijkstra(vector int>> &graph, vector &edges, vector <long long int> &dis, int s) { 39 priority_queue pq; 40 pq.push({s, dis[s] = 0}); 41 vector <int> vis(graph.size()); 42 while (!pq.empty()) { 43 auto tmp = pq.top(); 44 pq.pop(); 45 if (vis[tmp.u]) { 46 continue; 47 } 48 vis[tmp.u] = true; 49 for (unsigned int i = 0; i < graph[tmp.u].size(); i++) { 50 edge &e = edges[graph[tmp.u][i]]; 51 if (dis[e.v] > dis[e.u] + e.w) { 52 pq.push((node) {e.v, dis[e.v] = dis[e.u] + e.w}); 53 } 54 } 55 } 56 } 57 58 int main(void) { 59 ios::sync_with_stdio(false); 60 cin.tie(nullptr); 61 int T; 62 T = read(); 63 while (T--) { 64 int n = read(), m = read(), s = read(), k = read(), c = read(); 65 int ptr = 0; 66 vector edges(2 * m + k); 67 vector int>> graph(n + 1); 68 auto add_edge = [&] (int u, int v, long long int w) { 69 graph[u].emplace_back(ptr); 70 edges[ptr++] = ((edge) {u, v, w}); 71 }; 72 for (int i = 0; i < k; i++) { 73 int v = read(); 74 add_edge(0, v, 0); 75 } 76 for (int i = 0; i < m; i++) { 77 int u = read(), v = read(); 78 long long int w = read(); 79 add_edge(u, v, w); 80 add_edge(v, u, w); 81 } 82 83 vector <long long int> dis(n + 1, INF); 84 dijkstra(graph, edges, dis, s); 85 auto ans_s = *max_element(dis.begin() + 1, dis.end()); 86 for (int i = 0; i <= n; i++) { 87 dis[i] = INF; 88 } 89 dijkstra(graph, edges, dis, 0); 90 auto ans_k = *max_element(dis.begin() + 1, dis.end()); 91 92 if (ans_k * c < ans_s) { 93 cout << ans_k << endl; 94 } else { 95 cout << ans_s << endl; 96 } 97 } 98 return 0; 99 }
C:
一开始以为是莫队后来发现不对,就以为是字符串乱搞,结果是线段树维护dp矩阵区间合并。原题是Codeforces goodbye 2016 E。(tourist都没做出来的题这么多人做出来,有点假啊)
E:
一个n有4e7的约瑟夫问题居然是模拟,死都不信,垃圾数据。
G:
签到。
1 /* basic header */ 2 #include3 /* define */ 4 #define ll long long 5 #define dou double 6 #define pb emplace_back 7 #define mp make_pair 8 #define sot(a,b) sort(a+1,a+1+b) 9 #define rep1(i,a,b) for(int i=a;i<=b;++i) 10 #define rep0(i,a,b) for(int i=a;i11 #define eps 1e-8 12 #define int_inf 0x3f3f3f3f 13 #define ll_inf 0x7f7f7f7f7f7f7f7f 14 #define lson (curpos<<1) 15 #define rson (curpos<<1|1) 16 /* namespace */ 17 using namespace std; 18 /* header end */ 19 20 int t; 21 22 int main() { 23 scanf("%d", &t); 24 while (t--) { 25 ll n; scanf("%lld", &n); 26 if (n == 1) puts("18000"); 27 else puts("0"); 28 } 29 return 0; 30 }
H:
二分矩阵快速幂+记忆化。
1 #include2 typedef long long ull; 3 4 using namespace std; 5 6 const int maxn = 1e6 + 10; 7 const ull mod = 998244353; 8 9 struct Matrix { 10 ull mem[2][2]; 11 void init() { 12 memset(mem, 0, sizeof(mem)); 13 } 14 Matrix operator*(const Matrix &rhs)const { 15 Matrix ret; ret.init(); 16 for (int i = 0; i < 2; i++) { 17 for (int j = 0; j < 2; j++) { 18 for (int k = 0; k < 2; k++) 19 ret.mem[i][j] += mem[i][k] * rhs.mem[k][j]; 20 ret.mem[i][j] %= mod; 21 } 22 } 23 return ret; 24 } 25 } mAns, mBase; 26 unordered_map M; 27 28 int tot = 0; 29 Matrix solve(ull n) { 30 if (M.count(n)) return M[n]; 31 if (n == 1) { 32 M[n] = mBase; 33 return mBase; 34 } 35 Matrix ret = solve(n / 2ull); 36 ret = ret * ret; 37 if (n % 2ull == 1ull) ret = ret * mBase; 38 return M[n] = ret; 39 } 40 41 int main() { 42 ull q, n; 43 cin >> q >> n; 44 ull lastans = 0ull; 45 ull ans = 0; 46 for (int i = 1ull; i <= q; i++) { 47 mAns.mem[0][0] = 1, mAns.mem[0][1] = 0; 48 mBase.mem[0][0] = 3, mBase.mem[0][1] = 1, mBase.mem[1][0] = 2; 49 if (i >= 2ull) n = (n ^ (ans * ans)); 50 Matrix val = solve(n % (mod - 1)); 51 ans = val.mem[0][1]; 52 lastans = (lastans ^ ans); 53 } 54 cout << lastans << endl; 55 return 0; 56 }
L:
三位偏序,cdq分治。待补。