2018.08.20高二互测
2018.08.20 NOIp模擬賽
GKK大佬出的毒瘤題,燒腦。全是原題就不要密碼保護了。
第一題
T1鏈接
? 一張圖,每條邊有代價也有限制,遍歷過的點可以解鎖這些限制,求最短路。這是一道套路題,平時根本沒見過,考場上因為一個狀態或錯了調了好久好久。對每個點狀壓記個狀態判斷能不能走這條邊就行了。
code
#include<bits/stdc++.h> #define Set(a, b) memset(a, b, sizeof (a)) #define fir first #define sec second #define mp make_pair #define For(i, j, k) for(int i = j; i <= k; ++i) #define Travel(i, u) for(int i = beg[u], v = to[i]; i; i = nex[i], v = to[i]) using namespace std;inline int read() {int x = 0, p = 1; char c = getchar();for(; !isdigit(c); c = getchar()) if(c == '-') p = -1;for(; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);return x *= p; }template<typename T> inline bool chkmin(T &a, T b) { return a > b ? a = b, 1 : 0; } template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; }inline void File() {freopen("dalao.in", "r", stdin);freopen("dalao.out", "w", stdout); }typedef pair<int, int> PII; const int N = 200 + 10, M = 6e3 + 10; const int maxp = (1 << 13) + 10, inf = 0x7f7f7f7f; int e = 1, beg[N], nex[M], to[M], w[M], stt[M]; int vis[N][maxp], dis[N][maxp], st[N]; int n, m, p, k;inline void add(int x, int y, int z) {to[++ e] = y, nex[e] = beg[x], beg[x] = e, w[e] = z; }inline void spfa() {Set(vis, 0), Set(dis, 127);queue<PII> Q; Q.push(mp(st[1], 1)), vis[1][st[1]] = 1, dis[1][st[1]] = 0; while (!Q.empty()) {PII u = Q.front(); Q.pop(), vis[u.sec][u.fir] = 0;Travel(i, u.sec) {int nst = u.fir | st[v];if (dis[v][nst] > dis[u.sec][u.fir] + w[i] && (stt[i] | u.fir) == u.fir) {dis[v][nst] = dis[u.sec][u.fir] + w[i]; if (!vis[v][nst]) vis[v][nst] = 1, Q.push(mp(nst, v));}} } }int main() {File();cin >> n >> m >> p >> k;For(i, 1, k) {int pos = read(), num = read(), x;For(i, 1, num) x = read(), st[pos] |= (1 << (x - 1));}For(i, 1, m) {int x = read(), y = read(), z = read(), num = read(), a, s = 0;For(i, 1, num) a = read(), s |= (1 << (a - 1));add(x, y, z), stt[e] = s;add(y, x, z), stt[e] = s;}spfa();int ans = inf;For(i, 0, (1 << p) - 1) chkmin(ans, dis[n][i]);printf("%d\n", ans == inf ? -1 : ans);return 0; }第二題
T2鏈接
? 用\(~n~\)個數去匹配\(~m~\)個數對,可以選擇匹配與否,\(\sum ~[a_i > b_j] \times (a_i - b_j + c_j)~\)的最大值。我考場上想了一個貪心,把數對按\(~c_i - b_i~\)從大到小排序,每次二分一個滿足條件的最小的\(~a~\)去匹配,當\(~(a_i - b_j + c_j) > 0~\)是計入答案,最后計算可以通過更換剩余的\(~a~\)而產生的更大的貢獻。
? 其實這個離正解貪心差不多了,但我太菜了沒想到一個細節:就算一個\(~(a_i - b_j + c_j)~\)的貢獻是負的,之后也可以通過更換\(~a~\)來產生更大的貢獻。我那樣打就導致大樣例答案總是小一點,于是就滾去打階乘的\(~20pts~\)的暴力了。所以正解貪心就是:先把數對按\(~c_i - b_i~\)從大到小排序, 每次二分\(~a~\)看這個數對是否滿足條件,滿足就記下來,最后再一起算答案,每次用最大的\(~a~\)去匹配先前記下來的數對。我好菜啊。。。
code
#include<bits/stdc++.h> #define For(i, j, k) for(int i = j; i <= k; ++i) #define Forr(i, j, k) for(int i = j; i >= k; --i) using namespace std;inline int read() {int x = 0, p = 1; char c = getchar();for(; !isdigit(c); c = getchar()) if(c == '-') p = -1;for(; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);return x *= p; }inline void File() {freopen("winner.in", "r", stdin);freopen("winner.out", "w", stdout); }typedef long long ll; const int N = 1e5 + 10; int a[N], n, m, b[N], c[N], val[N], cnt; struct node { int b, c; } P[N]; multiset<ll> S; inline bool cmp(const node &a, const node &b) { return a.c - a.b > b.c - b.b; } inline bool cmpa(const int &a, const int &b) { return a > b; }int main() {File();n = read(), m = read();For(i, 1, n) S.insert(a[i] = read());For(i, 1, m) b[i] = read(), c[i] = read(), P[i] = (node) {b[i], c[i]};sort(P + 1, P + 1 + m, cmp);For(i, 1, m) {auto it = S.upper_bound(P[i].b);if (it == S.end()) continue;else val[++ cnt] = P[i].c - P[i].b, S.erase(it);}sort(a + 1, a + 1 + n, cmpa);ll ans = 0;For(i, 1, cnt) if (val[i] + a[i] > 0) ans += val[i] + a[i];printf("%lld\n", ans);return 0; }第三題
T3鏈接
? 先%%%HYJ大佬!給出\(~m, ~a, ~b, ~c~\), \(~a, ~b, ~c~\)兩兩互質,求解\(~x ^ a + y ^ b \equiv z^c ~(mod ~m)~\). 可以構造使\(~x = 2 ^ {kb}, ~ y = 2 ^ {ka}, z = 2 ^ p~\), 那么原式化為\(~2 ^ {kab + 1} \equiv 2 ^ {pc}~\), 則特判掉\(~m~\)是\(~2 ^ k~\)次冪,\(~k \in N^{+}\)的情況。剩余則有\(~kab + 1 = pc~\), 轉化一下就是擴歐了。膜爛hyj考場上火速ak并教會我!
code
#include<bits/stdc++.h> #define For(i, j, k) for(int i = j; i <= k; ++i) #define Forr(i, j, k) for(int i = j; i >= k; --i) using namespace std;inline int read() {int x = 0, p = 1; char c = getchar();for(; !isdigit(c); c = getchar()) if(c == '-') p = -1;for(; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);return x *= p; }inline void File() {freopen("guess.in", "r", stdin);freopen("guess.out", "w", stdout); }typedef long long ll; int mod, a, b, c;inline ll qpow(ll a, ll b) {ll res = 1;if (b < 0) b = -b;for (res = 1; b; a = a * a % mod, b >>= 1) if (b & 1) res = res * a % mod;return res; }inline void BF_Solve() {int flag = 0;For(x, 1, mod - 1) {For(y, 1, mod - 1) {For(z, 1, mod - 1) {if ((qpow(x, a) + qpow(y, b)) % mod == qpow(z, c) % mod) {printf("%d %d %d\n", x, y, z);flag = 1; break;} } if (flag) break;}if (flag) break;} }ll exgcd(ll a, ll b, ll &x, ll &y) {if (b == 0) return x = 1, y = 0, a;ll d = exgcd(b, a % b, x, y), tmp;tmp = x, x = y, y = tmp - a / b * y;return d; }int main() {File();for (int Case = read(); Case --; ) {mod = read(), a = read(), b = read(), c = read();int tt = mod, x, y, z;while (!(tt & 1)) tt /= 2;if (tt != 1) {ll A = 1ll * a * b, B = c, X, Y, d;d = exgcd(B, A, X, Y);while (X < 0 || Y > 0) X += A, Y -= B;x = qpow(2, 1ll * Y * b), y = qpow(2, 1ll * Y * a), z = qpow(2, X); } else {int res = mod >> 1;if (a > 1) x = res, y = z = 1;if (a == 1 && b > 1) y = res, x = z = 1;if (a == 1 && b == 1 && c > 1) x = y = z = res;if (a == 1 && b == 1 && c == 1) x = 1, y = 2, z = 3; }printf("%d %d %d\n", x, y, z);}return 0; }? 今天整個神游,第一題十點才調出來,大概是昨天晚上改AGC005F到一點的還沒調出來的后遺癥,以后考試要保持好精力,不然得不償失。GKK不愧是gay, 只是題面少了誰,美中不足。
轉載于:https://www.cnblogs.com/LSTete/p/9508375.html
總結
以上是生活随笔為你收集整理的2018.08.20高二互测的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 牛客小白月赛6 H 挖沟
- 下一篇: Chapter 5 Blood Type