2018.12.15 考試解題報告
阿新 • • 發佈:2018-12-15
#include <queue> #include <cstdio> #include <cctype> #include <cstring> #include <iostream> #include <algorithm> using namespace std; typedef long long u64; const int maxn = 2000 + 10; char ques[maxn]; int n, atk[maxn], def[maxn], flag; u64 a[maxn], ans; inlinevoid Exit() { fclose(stdin), fclose(stdout), exit(0); } void Deep_fs(int attack, int kishi, u64 money, int step) { if( step == n + 1 ) { ans = max(ans, money); return ; } if( ques[step] == 'U' ) { Deep_fs(attack + 1, kishi, money, step + 1); Deep_fs(attack, kishi+ 1, money, step + 1); } else { if( attack >= atk[step] && kishi >= def[step] ) Deep_fs(attack, kishi, money + a[step], step + 1); else Deep_fs(attack, kishi, money, step + 1); } } int main(int argc, char const *argv[]) { freopen("rpg.in", "r", stdin); freopen("rpg.out", "w", stdout); scanf("%d", &n); for(int i = 1; i <= n; ++i) { cin >> ques[i]; if( ques[i] == 'M' ) { scanf("%lld%d%d", &a[i], &atk[i], &def[i]); if( def[i] != 1 ) flag = 1; } } if( !flag ) { int attack = 1; for(int i = 1; i <= n; ++i) if( ques[i] == 'U' ) ++attack; else if( attack >= atk[i] ) ans += a[i]; printf("%lld\n", ans), Exit(); } Deep_fs(1, 1, 0, 1), printf("%lld\n", ans), Exit(); }
#include <queue> #include <cstdio> #include <cctype> #include <cstring> #include <algorithm> using namespace std; typedef long long u64; typedef pair<u64, int> pairs; priority_queue<pairs, vector<pairs>, greater<pairs> > q; const int linf = 1e16 + 7; const int maxn = 1000 + 10; const int maxm = 10000 + 10; int n, m, k, head[maxn], vis[maxn], pre[maxn], edge_num; u64 dis[maxn], pre_w[maxn], ans = linf; struct Edge { int v, nxt; u64 w; } edge[maxm << 1]; inline int read() { register char ch = 0; register int w = 0, x = 0; while( !isdigit(ch) ) w |= (ch == '-'), ch = getchar(); while( isdigit(ch) ) x = (x * 10) + (ch ^ 48), ch = getchar(); return w ? -x : x; } inline void Add_edge(int u, int v, u64 w) { edge[++edge_num].v = v, edge[edge_num].w = w; edge[edge_num].nxt = head[u], head[u] = edge_num; } inline void Exit() { fclose(stdin), fclose(stdout), exit(0); } inline void Daisuki_fs(int x, u64 s, int cnt) { if( x == n ) { ans = min(ans, s); return ; } for(int i = head[x]; i; i = edge[i].nxt) { if( vis[edge[i].v] ) continue; vis[edge[i].v] = 1; Daisuki_fs(edge[i].v, s + edge[i].w, cnt); if( cnt < k ) Daisuki_fs(edge[i].v, s, cnt + 1); vis[edge[i].v] = 0; } } inline bool Breath_fs(int s) { queue<int> q; dis[s] = 1, q.push(s); while( !q.empty() ) { int x = q.front(); q.pop(); for(int i = head[x]; i; i = edge[i].nxt) if( !dis[edge[i].v] ) dis[edge[i].v] = dis[x] + 1, q.push(edge[i].v); } if( dis[n] <= k ) return false; else return true; } inline u64 Dijkstra(int s) { memset(vis, 0, sizeof vis); for(int i = 1; i <= n; ++i) dis[i] = linf; dis[s] = 0, q.push(make_pair(dis[s], s)); while( !q.empty() ) { int x = q.top().second; q.pop(); if( vis[x] ) continue; vis[x] = 1; for(int i = head[x]; i; i = edge[i].nxt) { if( dis[edge[i].v] > dis[x] + edge[i].w ) { dis[edge[i].v] = dis[x] + edge[i].w; pre[edge[i].v] = x, pre_w[edge[i].v] = edge[i].w; q.push(make_pair(dis[edge[i].v], edge[i].v)); } } } return dis[n]; } int main(int argc, char const *argv[]) { freopen("school.in", "r", stdin); freopen("school.out", "w", stdout); scanf("%d%d%d", &n, &m, &k); for(int i = 1; i <= m; ++i) { int u = read(), v = read(), w = read(); Add_edge(u, v, w), Add_edge(v, u, w); } if( !Breath_fs(1) ) printf("0\n"), Exit(); if( n <= 5 && m <= 10 ) { vis[1] = 1, Daisuki_fs(1, 0, 0); printf("%lld\n", ans), Exit(); } u64 t = Dijkstra(1); for(int i = 1, p = n; i <= k; ++i) { u64 maxx = pre_w[p]; while( pre[p] != 1 ) maxx = max(maxx, pre_w[p]), p = pre[p]; t -= maxx; } printf("%lld\n", t); Exit(); }
#include <queue> #include <cstdio> #include <cctype> #include <cstring> #include <algorithm> using namespace std; typedef long long u64; const u64 mod = 998244353; const int maxn = 1000 + 10; u64 n, a[maxn], s[maxn][32], flag; inline void Exit() { fclose(stdin), fclose(stdout), exit(0); } inline void Program_1() { u64 p = 1, ans = 0; for(int k = 0; k <= 30; ++k) { for(int i = 1; i <= n; ++i) { for(int j = i; j <= n; ++j) { if( s[i][k] != s[j][k] ) { if( (a[i] & p) == p ) ans += p * (s[j][k] - s[i][k] + 1); else ans += p * (s[j][k] - s[i][k]); } else if( (a[i] & p) != (a[j] & p) || (a[i] & p) == p ) ans += p; ans %= mod; } } p <<= 1; } printf("%lld\n", ans); } int main(int argc, char const *argv[]) { freopen("count.in", "r", stdin); freopen("count.out", "w", stdout); scanf("%lld", &n); for(int i = 1; i <= n; ++i) { scanf("%lld", &a[i]); if( a[i] != 0 && a[i] != 1 ) flag = 1; } for(int k = 0, p = 1; k <= 30; ++k) { int cnt = 0; for(int i = 1; i <= n; ++i) { if( (a[i] & p) == (a[i - 1] & p) ) s[i][k] = s[i - 1][k]; else if( (a[i] & p) == p ) s[i][k] = ++cnt; else s[i][k] = s[i - 1][k]; } p <<= 1; } if( !flag ) { u64 ans = 0; for(int i = 1; i <= n; ++i) { for(int j = i; j <= n; ++j) { if( s[i][0] != s[j][0] ) { if( a[i] == 1 ) ans += s[j][0] - s[i][0] + 1; else ans += s[j][0] - s[i][0]; } else if( a[i] != a[j] || a[i] == 1 ) ++ans; ans %= mod; } } printf("%lld\n", ans), Exit(); } else Program_1(), Exit(); return 0; }