本来是8天代码放一起的,但是太麻烦了,还是分成了2个博客放。

day1

F div1 爬爬爬山 (最短路)

  1. //F
  2. #include<bits/stdc++.h>
  3. #define fi first
  4. #define se second
  5. #define iis std::ios::sync_with_stdio(false)
  6. namespace lh {
  7. #define o2(x) (x)*(x)
  8. using namespace std;
  9. typedef long long LL;
  10. typedef unsigned long long uLL;
  11. typedef pair<int, LL> pii;
  12. }
  13. using namespace lh;
  14. const int MXN = 1e6 + 7;
  15. const int INF = 0x3f3f3f3f;
  16. const int MOD = 1000000007;
  17. int n, m, k, NODE;
  18. LL height[MXN];
  19. int other[MXN];
  20. vector<pii> mp[MXN];
  21. LL dis[MXN];
  22. struct lp {
  23. int v;
  24. LL w;
  25. friend bool operator <(const lp &a, const lp &b) {
  26. return a.w > b.w;
  27. }
  28. }A, B;
  29. void add_edge(int u,int v,LL w) {
  30. mp[u].push_back({v, w});
  31. }
  32. void dij() {
  33. for(int i = 2; i <= NODE; ++i) dis[i] = 1e18;
  34. dis[1] = 0;
  35. priority_queue<lp> Q;
  36. Q.push({1, 0});
  37. while(!Q.empty()) {
  38. A = Q.top(); Q.pop();
  39. int u = A.v;
  40. if(dis[u] < A.w) continue;
  41. int len = mp[u].size();
  42. for(int i = 0; i < len; ++i) {
  43. int v = mp[u][i].fi;
  44. if(dis[v] > dis[u] + mp[u][i].se) {
  45. dis[v] = dis[u] + mp[u][i].se;
  46. Q.push({v, dis[v]});
  47. }
  48. }
  49. }
  50. printf("%lld\n", dis[n]);
  51. }
  52. int main() {
  53. scanf("%d%d%d", &n, &m, &k);
  54. NODE = n;
  55. for(int i = 1; i <= n; ++i) other[i] = -1;
  56. for(int i = 1; i <= n; ++i) {
  57. scanf("%lld", &height[i]);
  58. if(i > 1 && height[i] - height[1] > k) {
  59. other[i] = ++ NODE;
  60. add_edge(other[i], i, (height[i]-height[1]-k)*(height[i]-height[1]-k));
  61. //add_edge(i, other[i], (height[i]-height[1])*(height[i]-height[1]));
  62. //printf("%d %d\n", i, (height[i]-height[1])*(height[i]-height[1]));
  63. }
  64. }
  65. LL c;
  66. for(int i = 0, a, b; i < m; ++i) {
  67. scanf("%d%d%lld", &a, &b, &c);
  68. if(other[b] == -1) add_edge(a, b, c);
  69. else add_edge(a, other[b], c);
  70. if(other[a] == -1) add_edge(b, a, c);
  71. else add_edge(b, other[a], c);
  72. }
  73. dij();
  74. return 0;
  75. }

B div2 吃豆豆 (dp)

  1. //B
  2. #include<bits/stdc++.h>
  3. #define fi first
  4. #define se second
  5. #define iis std::ios::sync_with_stdio(false)
  6. namespace lh {
  7. #define o2(x) (x)*(x)
  8. using namespace std;
  9. typedef long long LL;
  10. typedef unsigned long long uLL;
  11. typedef pair<int, LL> pii;
  12. }
  13. using namespace lh;
  14. const int MXN = 1e6 + 7;
  15. const int INF = 0x3f3f3f3f;
  16. const int MOD = 1000000007;
  17. int n, m, C;
  18. int sx,sy,ex,ey;
  19. int ar[15][15];
  20. int dp[15][15][10352];
  21. int dir[5][2]={1,0,0,1,-1,0,0,-1,0,0};
  22. int main() {
  23. scanf("%d%d%d", &n, &m, &C);
  24. for(int i = 1; i <= n; ++i) {
  25. for(int j = 1; j <= m; ++j) {
  26. scanf("%d", &ar[i][j]);
  27. }
  28. }
  29. scanf("%d%d%d%d", &sx, &sy, &ex, &ey);
  30. for(int k = 0; k <= 10351; ++k) {
  31. for(int i = 1; i <= n; ++i) {
  32. for(int j = 1; j <= m; ++j) {
  33. dp[i][j][k] = -INF;
  34. }
  35. }
  36. }
  37. dp[sx][sy][0] = 0;
  38. for(int k = 1; k <= 10351; ++k) {
  39. for(int i = 1; i <= n; ++i) {
  40. for(int j = 1; j <= m; ++j) {
  41. for(int h = 0; h < 5; ++h) {
  42. int px = i + dir[h][0], py = j + dir[h][1];
  43. if(px < 1 || px > n || py < 1 || py > m) continue;
  44. if(dp[px][py][k-1] == -INF) continue;
  45. dp[i][j][k] = max(dp[i][j][k], dp[px][py][k-1]+((k%ar[i][j])==0));
  46. }
  47. }
  48. }
  49. }
  50. int ans = INF;
  51. for(int i = 1; i <= 10351; ++i) {
  52. if(dp[ex][ey][i] >= C) {
  53. ans = i;
  54. break;
  55. }
  56. }
  57. printf("%d\n", ans);
  58. return 0;
  59. }

J div2 夺宝奇兵(暴力)

  1. //J
  2. /*
  3. 把所有人宝物从大到小排个序,列出一个柱状图来
  4. 枚举其他人最高的宝物的数量为mid,所有高于mid的宝物我们肯定要买的
  5. 如果这时获得宝物已经多于mid了,就可以return了
  6. 不然就从剩下所有的宝物里面选出价值最小的几个宝物凑出mid+1个宝物出来
  7. */
  8. #include<bits/stdc++.h>
  9. #define fi first
  10. #define se second
  11. #define iis std::ios::sync_with_stdio(false)
  12. #define pb push_back
  13. namespace lh {
  14. #define o2(x) (x)*(x)
  15. using namespace std;
  16. typedef long long LL;
  17. typedef unsigned long long uLL;
  18. typedef pair<int, LL> pii;
  19. }
  20. using namespace lh;
  21. const LL INF = 1e18;
  22. const int N = 1e4 + 100;
  23. vector<LL> c[N];
  24. int n, m;
  25. LL x;
  26. LL solve(int mid){
  27. LL tmp = 0;
  28. int now = 0;
  29. std::vector<LL> vs;
  30. for(int i = 2; i <= n; ++i) {
  31. int siz = c[i].size();
  32. if(siz >= mid) {
  33. for(int j = 0; j < siz - mid; ++j) tmp += c[i][j], now++;
  34. for(int j = siz - mid; j < siz; ++j) vs.push_back(c[i][j]);
  35. }else {
  36. for(int j = 0; j < siz; ++j) vs.push_back(c[i][j]);
  37. }
  38. }
  39. if(now > mid) return tmp;
  40. if(now + vs.size() <= mid) return INF;
  41. sort(vs.begin(), vs.end());
  42. for(int i = 0; i <= mid - now && i < vs.size(); ++i) {
  43. tmp += vs[i];
  44. }
  45. return tmp;
  46. }
  47. int main() {
  48. scanf("%d%d", &n, &m);
  49. for (int i = 1, ar; i <= m; ++i){
  50. scanf("%lld%d", &x, &ar);
  51. ++ ar; c[ar].pb(x);
  52. }
  53. ++ n;
  54. for (int i = 2; i <= n; ++i){
  55. sort(c[i].begin(), c[i].end());
  56. }
  57. LL tmp = 1e18;
  58. for (int i = 1; i <= m; ++i){
  59. tmp = min(tmp, solve(i));
  60. }
  61. printf("%lld\n", tmp);
  62. return 0;
  63. }

J div1 夺宝奇兵 (权值线段树)

  1. //太菜了,后缀和都不会写了,找了一万年的bug
  2. #include<bits/stdc++.h>
  3. #define fi first
  4. #define se second
  5. #define lson rt<<1
  6. #define rson rt<<1|1
  7. #define iis std::ios::sync_with_stdio(false)
  8. #define pb push_back
  9. namespace lh {
  10. #define o2(x) (x)*(x)
  11. using namespace std;
  12. typedef long long LL;
  13. typedef unsigned long long uLL;
  14. typedef pair<int, int> pii;
  15. }
  16. using namespace lh;
  17. const LL INF = 1e18;
  18. const int MXN = 4e5 + 7;
  19. int n, m;
  20. std::vector<int> shut[MXN];
  21. std::vector<pii > mp[MXN];
  22. pii ar[MXN];
  23. LL suf[MXN], SUM[MXN<<2];
  24. int num[MXN], NUM[MXN<<2];
  25. LL min_sum;
  26. int min_num;
  27. bool cmp(const pii &a, const pii &b) {
  28. if(a.fi != b.fi) return a.fi > b.fi;
  29. return a.se > b.se;
  30. }
  31. void push_up(int rt) {
  32. NUM[rt] = NUM[lson] + NUM[rson];
  33. SUM[rt] = SUM[lson] + SUM[rson];
  34. }
  35. void build(int l,int r,int rt) {
  36. if(l == r) {
  37. NUM[rt] = 1;
  38. SUM[rt] = ar[l].fi;
  39. return ;
  40. }
  41. int mid = (l + r) >> 1;
  42. build(l, mid, lson), build(mid+1, r, rson);
  43. push_up(rt);
  44. }
  45. void update(int p, int v, int l, int r, int rt) {
  46. if(l == r) {
  47. NUM[rt] = 0;
  48. SUM[rt] = 0;
  49. return ;
  50. }
  51. int mid = (l + r) >> 1;
  52. if(p <= mid) update(p, v, l, mid, lson);
  53. else update(p, v, mid+1, r, rson);
  54. push_up(rt);
  55. }
  56. LL query(int nd, int l, int r, int rt) {
  57. //printf("%d %d %d %d %lld\n", nd, l, r, NUM[rt], SUM[rt]);
  58. if(l == r || nd == NUM[rt]) {
  59. return SUM[rt];
  60. }
  61. int mid = (l + r) >> 1;
  62. if(NUM[lson] >= nd) return query(nd, l, mid, lson);
  63. else {
  64. return SUM[lson] + query(nd - NUM[lson], mid+1, r, rson);
  65. }
  66. }
  67. LL solve(int mid) {
  68. LL ans = min_sum;//min_sum 和 suf[mid+1]
  69. if(min_num > mid) return ans;//min_num 和 num[mid+1]
  70. if(NUM[1] + min_num <= mid) return INF;
  71. int nd = min(mid + 1 - min_num, NUM[1]);
  72. ans += query(nd, 1, m, 1);
  73. return ans;
  74. }
  75. int main() {
  76. scanf("%d%d", &n, &m);
  77. int x, a;
  78. LL ans = 0;
  79. for(int i = 1; i <= m; ++i) {
  80. scanf("%d%d", &x, &a);
  81. ar[i] = {x, a};
  82. ans = ans + x;
  83. }
  84. sort(ar + 1, ar + 1 + m);
  85. for(int i = 1; i <= m; ++i) {
  86. mp[ar[i].se].push_back({ar[i].fi, i});
  87. }
  88. build(1, m, 1);
  89. for(int i = 1; i <= n; ++i) {
  90. sort(mp[i].begin(), mp[i].end(), cmp);
  91. for(int j = mp[i].size(); j >= 1; --j) {
  92. shut[j].push_back(mp[i][j-1].se);
  93. }
  94. }
  95. //printf("[%lld]\n", query(4, 1, m, 1));
  96. for(int i = m; i >= 1; --i) {
  97. ans = min(ans, solve(i));
  98. for(auto x: shut[i]) {
  99. ++ min_num;
  100. min_sum += ar[x].fi;
  101. update(x, -1, 1, m, 1);
  102. }
  103. }
  104. printf("%lld\n", ans);
  105. return 0;
  106. }

C div1 拆拆拆数

  1. #include<bits/stdc++.h>
  2. #define fi first
  3. #define se second
  4. #define lson rt<<1
  5. #define rson rt<<1|1
  6. #define iis std::ios::sync_with_stdio(false)
  7. #define pb push_back
  8. namespace lh {
  9. #define o2(x) (x)*(x)
  10. using namespace std;
  11. typedef long long LL;
  12. typedef unsigned long long uLL;
  13. typedef pair<int, int> pii;
  14. }
  15. using namespace lh;
  16. const int MXN = 4e5 + 7;
  17. //一个偶数可以拆成一个奇数和一个奇素数之和
  18. int n, m;
  19. LL a, b;
  20. LL pp[20] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59};
  21. LL gcd(LL a, LL b) {
  22. return b==0?a:gcd(b,a%b);
  23. }
  24. int main() {
  25. scanf("%d", &n);
  26. m = 17;
  27. while(n --) {
  28. scanf("%lld%lld", &a, &b);
  29. if(gcd(a, b) == 1) {
  30. printf("1\n%lld %lld\n", a, b);
  31. continue ;
  32. }
  33. int flag = 0;
  34. if(b % 2 == 0) swap(a, b), flag = 1;
  35. if(a % 2 == 0) {
  36. for(int i = 0; i < m; ++i) {
  37. if(gcd(b-2, pp[i]) == 1 && gcd(a-pp[i],2) == 1) {
  38. if(flag == 0) printf("2\n%lld %lld\n%lld %lld\n",pp[i],b-2,a-pp[i],2LL);
  39. else printf("2\n%lld %lld\n%lld %lld\n",b-2,pp[i],2LL,a-pp[i]);
  40. break;
  41. }
  42. }
  43. }else {
  44. if(flag == 0) printf("2\n%lld %lld\n%lld %lld\n", 2LL, b-2, a-2, 2LL);
  45. else printf("2\n%lld %lld\n%lld %lld\n", b-2, 2LL, 2LL, a-2);
  46. }
  47. }
  48. return 0;
  49. }
  50. //这个也行
  51. using namespace lh;
  52. const int MXN = 4e5 + 7;
  53. int n, m;
  54. LL a, b;
  55. LL pp[20] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59};
  56. LL gcd(LL a, LL b) {
  57. return b==0?a:gcd(b,a%b);
  58. }
  59. int main() {
  60. #ifndef ONLINE_JUDGE
  61. freopen("E://ADpan//in.in", "r", stdin);
  62. //freopen("E://ADpan//out.out", "w", stdout);
  63. #endif
  64. scanf("%d", &n);
  65. m = 17;
  66. while(n --) {
  67. scanf("%lld%lld", &a, &b);
  68. if(gcd(a, b) == 1) {
  69. printf("1\n%lld %lld\n", a, b);
  70. continue ;
  71. }else if(a % 2 == 1 && b % 2 == 1) {
  72. printf("2\n%lld %lld\n%lld %lld\n", 2LL, b-2, a-2, 2LL);
  73. continue;
  74. }
  75. printf("2\n");
  76. int flag = 1;
  77. for(LL i = 2; i <= 100 && flag; ++i) {
  78. for(LL j = 2; j <= 100 && flag; ++j) {
  79. if(gcd(i,j) == 1 && gcd(a-i,b-j) == 1) {
  80. printf("%lld %lld\n%lld %lld\n", i,j,a-i,b-j);
  81. flag = 0;
  82. }else if(gcd(i,b-j) == 1 && gcd(a-i,j) == 1) {
  83. flag = 0;
  84. printf("%lld %lld\n%lld %lld\n", i,b-j,a-i,j);
  85. }
  86. }
  87. }
  88. }
  89. return 0;
  90. }

E div1 流流流动(冰雹猜想 ,树形dp)

  1. //这玩意会连成一个森林
  2. #include<bits/stdc++.h>
  3. namespace lh {
  4. #define o2(x) (x)*(x)
  5. using namespace std;
  6. typedef long long LL;
  7. typedef unsigned long long uLL;
  8. typedef pair<int, int> pii;
  9. }
  10. using namespace lh;
  11. const int MXN = 4e5 + 7;
  12. int n, m;
  13. std::vector<int> son[MXN];
  14. int f[MXN], d[MXN], vis[MXN];
  15. LL dp[MXN][2];
  16. //dp[i][0]表示不选i, dp[i][1]表示选i
  17. void dfs(int u,int ba) {
  18. dp[u][1] += f[u];
  19. vis[u] = 1;
  20. for(auto v: son[u]) {
  21. if(v == ba) continue;
  22. dfs(v, u);
  23. dp[u][0] += max(dp[v][0], dp[v][1]);
  24. dp[u][1] += max(dp[v][0], dp[v][1]-d[min(u, v)]);
  25. }
  26. }
  27. int main() {
  28. scanf("%d", &n);
  29. for(int i = 1; i <= n; ++i) scanf("%d", &f[i]);
  30. for(int i = 1; i <= n; ++i) scanf("%d", &d[i]);
  31. for(int i = 2; i <= n; ++i) {
  32. if(i % 2 == 0) {
  33. son[i].push_back(i/2);
  34. son[i/2].push_back(i);
  35. }else if(i*3+1 <= n){
  36. son[i].push_back(i*3+1);
  37. son[i*3+1].push_back(i);
  38. }
  39. }
  40. LL ans = 0;
  41. for(int i = 1; i <= n; ++i) {
  42. if(vis[i] == 0) {
  43. dfs(i, i);
  44. ans += max(dp[i][0], dp[i][1]);
  45. }
  46. }
  47. printf("%lld\n", ans);
  48. return 0;
  49. }

I div2 起起落落 (dp)

\(dp[i]=\sum_{j=1}^{j<i}[p[j]>p[i]]\times dp[j]\times \sum_{h=j+1}^{h<i}[p[h]<p[j]]\)

  1. /*
  2. 题意:
  3. 给你一个长度为n的排列,问有多少个长度为(2*m+1)奇数且大于3的子序列满足一下条件:
  4. 1.下标序列递增(这个没啥重要的
  5. 2.(1<=i<=m) p[2*i-1]>p[2*i+1]>p[2*i]
  6. dp[i]表示以i结尾符合条件的序列的个数
  7. dp[i]=\sum_{j=1}^{j<i}[p[j]>p[i]]\times dp[j]\times \sum_{h=j+1}^{h<i}[p[h]<p[j]]
  8. 这种转移方法构造出来的方案中序列的长度肯定是奇数的
  9. */
  10. #include<bits/stdc++.h>
  11. #define fi first
  12. #define se second
  13. #define lson rt<<1
  14. #define rson rt<<1|1
  15. #define iis std::ios::sync_with_stdio(false)
  16. #define pb push_back
  17. namespace lh {
  18. #define o2(x) (x)*(x)
  19. using namespace std;
  20. typedef long long LL;
  21. typedef unsigned long long uLL;
  22. typedef pair<int, int> pii;
  23. }
  24. using namespace lh;
  25. const int mod = 1e9 +7;
  26. const int MXN = 4e5 + 7;
  27. int n, m;
  28. int p[MXN];
  29. LL dp[MXN], suf[MXN];
  30. int main() {
  31. scanf("%d", &n);
  32. for(int i = 1; i <= n; ++i) scanf("%d", &p[i]);
  33. LL ans = 0;
  34. for(int i = 3, cnt; i <= n; ++i) {
  35. cnt = 0;
  36. for(int j = i-1; j >= 1; --j) {
  37. if(p[j] < p[i]) {
  38. ++ cnt;
  39. continue;
  40. }
  41. dp[i] = (dp[i]+ (1+dp[j])*cnt%mod) % mod;//加1是要加上取单独j这一个元素和cnt和i相组合的情况
  42. }
  43. if(i >= 3) ans = (ans + dp[i]) % mod;
  44. }
  45. printf("%lld\n", ans);
  46. return 0;
  47. }

I div1 起起落落 (权值线段树优化dp)

  1. 待填坑

day2

A div2 Erase Nodes(贪心)

  1. //A
  2. #include<bits/stdc++.h>
  3. #define fi first
  4. #define se second
  5. #define iis std::ios::sync_with_stdio(false)
  6. #define pb push_back
  7. namespace lh {
  8. #define o2(x) (x)*(x)
  9. using namespace std;
  10. typedef unsigned long long LL;
  11. typedef pair<int, LL> pii;
  12. }
  13. using namespace lh;
  14. const int MXN = 1e4 + 100;
  15. int n;
  16. int ar[MXN];
  17. LL dp[20];
  18. int get(int x) {
  19. int num = 0;
  20. while(x) {
  21. num ++;
  22. x /= 10;
  23. }
  24. return num;
  25. }
  26. int main() {
  27. dp[0] = 1;
  28. for(int i = 1; i <= 10; ++i) {
  29. dp[i] = dp[i-1] * 10;
  30. }
  31. int cas = 0;
  32. int tim; scanf("%d", &tim);
  33. while(tim --) {
  34. scanf("%d", &n);
  35. int cnt = 0;
  36. for(int i = 1; i <= n; ++i) {
  37. scanf("%d", &ar[i]);
  38. if(ar[i] == 1000000000) cnt++;
  39. }
  40. int mmax = ar[n], wei = get(ar[n]);
  41. LL ans = 0, tmp = 0;
  42. int flag = 0;
  43. for(int i = n-1; i >= 1; --i) {
  44. ans = ar[i];
  45. ans *= dp[wei];
  46. ans += mmax;
  47. tmp = max(tmp, ans);
  48. if(ar[i] > mmax) {
  49. mmax = ar[i];
  50. wei = get(ar[i]);
  51. }
  52. }
  53. printf("Case #%d: %llu\n", ++cas, tmp);
  54. }
  55. return 0;
  56. }

B div2 Erase Numbers III(贪心)

  1. //B
  2. #include<bits/stdc++.h>
  3. #define fi first
  4. #define se second
  5. #define iis std::ios::sync_with_stdio(false)
  6. #define pb push_back
  7. namespace lh {
  8. #define o2(x) (x)*(x)
  9. using namespace std;
  10. typedef unsigned long long LL;
  11. typedef pair<int, LL> pii;
  12. }
  13. using namespace lh;
  14. const int INF = 0x3f3f3f3f;
  15. const int MXN = 1e4 + 100;
  16. int n;
  17. int ar[MXN], len[MXN], br[MXN], is[MXN], len2[MXN], id[MXN];
  18. LL dp[20];
  19. int get(int x) {
  20. int num = 0;
  21. while(x) {
  22. num ++;
  23. x /= 10;
  24. }
  25. return num;
  26. }
  27. string toString(int x) {
  28. string ans;
  29. char c;
  30. while(x) {
  31. c = x%10+'0';
  32. ans = c + ans;
  33. x /= 10;
  34. }
  35. return ans;
  36. }
  37. int A[20], B[20];
  38. bool mycmp(int x, int y) {//x是否比y字典序小
  39. A[0] = B[0] = 0;
  40. while(x) {
  41. A[++A[0]] = x%10;
  42. x /= 10;
  43. }
  44. while(y) {
  45. B[++B[0]] = y%10;
  46. y /= 10;
  47. }
  48. reverse(A+1, A+A[0]+1);
  49. reverse(B+1, B+B[0]+1);
  50. int tmp = min(A[0], B[0]);
  51. for(int i = 1; i <= tmp; ++i) {
  52. if(A[i] > B[i]) return 0;
  53. else if(A[i] < B[i]) return 1;
  54. }
  55. return 1;
  56. }
  57. int main() {
  58. int cas = 0;
  59. int tim; scanf("%d", &tim);
  60. while(tim --) {
  61. scanf("%d", &n);
  62. int mmin = INF;
  63. for(int i = 1; i <= n; ++i) is[i] = 0;
  64. for(int i = 1; i <= n; ++i) {
  65. scanf("%d", &ar[i]);
  66. len[i] = get(ar[i]);
  67. br[i] = len[i];
  68. mmin = min(mmin, len[i]);
  69. }
  70. sort(br + 1, br + 1 + n);
  71. int flag = 0;
  72. if(br[1] == br[2]) flag = 1;
  73. printf("Case #%d: ", ++cas);
  74. int pos = -1;
  75. if(flag == 1) {
  76. std::vector<int> my;
  77. for(int i = 1; i < n; ++i) {
  78. if(len[i] == mmin && mycmp(ar[i], ar[i+1])) {
  79. my.push_back(i);
  80. is[i] = 1;
  81. //printf("*%d\n", i);
  82. break;
  83. }
  84. }
  85. int cnt2 = 0;
  86. for(int i = 1; i <= n; ++i) {
  87. if(is[i] == 0) br[++cnt2] = ar[i], len2[cnt2] = len[i], id[cnt2] = i;
  88. }
  89. for(int i = 1; i < cnt2; ++i) {
  90. if(len2[i] == mmin && mycmp(br[i], br[i+1])) {
  91. my.push_back(id[i]);
  92. is[id[i]] = 1;
  93. //printf("**%d\n", id[i]);
  94. break;
  95. }
  96. }
  97. for(int i = n; i >= 1 && my.size() < 2; --i) {
  98. if(is[i] == 0 && len[i] == mmin) my.push_back(i);
  99. }
  100. string ans1, ans2;
  101. for(int i = 1; i <= n; ++i) {
  102. if(i == my[0] || i == my[1]) continue;
  103. ans1 += toString(ar[i]);
  104. }
  105. //cout<<ans1<<"\n";
  106. my.clear();
  107. for(int i = 1; i + 2 <= n; ++i) {
  108. if(len[i] + len[i+1] == mmin + mmin) {
  109. if(mycmp(ar[i], ar[i+2])) {
  110. my.push_back(i);
  111. break;
  112. }
  113. }
  114. }
  115. int hh = 0;
  116. if(my.size() == 0) {
  117. for(int i = n; i >= 2; --i) {
  118. if(len[i] + len[i-1] == mmin + mmin) {
  119. my.push_back(i);
  120. break;
  121. }
  122. }
  123. if(my.size() == 1) {
  124. hh = 1;
  125. my.push_back(my[0]-1);
  126. for(int i = 1; i <= n; ++i) {
  127. if(i == my[0] || i == my[1]) continue;
  128. ans2 += toString(ar[i]);
  129. }
  130. }
  131. }
  132. if(hh) ans1 = max(ans1, ans2);
  133. cout<<ans1<<"\n";
  134. continue;
  135. }
  136. pos = -1;
  137. int fuck = br[2];
  138. for(int i = 1, nex; i < n; ++i) {
  139. nex = ar[i+1];
  140. if(len[i+1] == mmin && i + 2 <= n) nex = ar[i+2];
  141. if(len[i] == fuck) {
  142. if(mycmp(ar[i], nex)) {
  143. pos = i;
  144. break;
  145. }
  146. }
  147. }
  148. if(pos == -1) {
  149. for(int i = n; i >= 1; --i) {
  150. if(len[i] == mmin) continue;
  151. if(len[i] != fuck) continue;
  152. pos = i;
  153. break;
  154. }
  155. }
  156. for(int i = 1; i <= n; ++i) {
  157. if(i == pos || len[i] == mmin) {
  158. }else printf("%d", ar[i]);
  159. }
  160. printf("\n");
  161. }
  162. return 0;
  163. }//求ac

H div1&2 Cosmic Cleaner(计算几何)

球缺体积

用一个平面截去一个球所得部分叫球缺

球缺面积\(=2\times πh\)

球缺体积\(=π\times h^2\times (R−\frac{h}{3})\)

球缺质心:匀质球缺的质心位于它的中轴线上,并且与底面的距离为

\(C=\frac{(4R-h)\times h}{12R-4h}=\frac{(d^2+2h^2)\times h}{3d^2+4h^2}\)

其中,\(h\)为球缺的高,\(R\)为大圆半径,\(d\)为球缺的底面直径

https://blog.csdn.net/enterprise_/article/details/81624174

https://paste.ubuntu.com/p/5qZKXYFsjQ/

  1. //H
  2. #include<bits/stdc++.h>
  3. #define fi first
  4. #define se second
  5. #define iis std::ios::sync_with_stdio(false)
  6. #define pb push_back
  7. namespace lh {
  8. #define o2(x) (x)*(x)
  9. using namespace std;
  10. typedef unsigned long long LL;
  11. typedef pair<int, LL> pii;
  12. }
  13. using namespace lh;
  14. const int INF = 0x3f3f3f3f;
  15. const double pi = acos(-1.0);
  16. const int MXN = 1e4 + 100;
  17. int n;
  18. int A, B, C, r1;
  19. struct lp {
  20. int a, b, c, r2;
  21. }cw[MXN];
  22. double tiji(lp ar) {
  23. double d = sqrt(o2(ar.a-A)+o2(ar.b-B)+o2(ar.c-C));
  24. double r2 = ar.r2;
  25. double X = r1-(r1*r1-r2*r2+d*d)/(2*d);
  26. double Y = r2-(r2*r2-r1*r1+d*d)/(2*d);
  27. double ans = pi/3*X*X*(3*r1-X)+pi/3*Y*Y*(3*r2-Y);
  28. return ans;
  29. }
  30. int main() {
  31. int cas = 0;
  32. int tim; scanf("%d", &tim);
  33. while(tim --) {
  34. scanf("%d", &n);
  35. int a, b, c, r2;
  36. double d;
  37. for(int i = 1; i <= n; ++i) {
  38. scanf("%d%d%d%d", &a, &b, &c, &r2);
  39. cw[i] = {a, b, c, r2};
  40. }
  41. scanf("%d%d%d%d", &A, &B, &C, &r1);
  42. double ans = 0;
  43. for(int i = 1; i <= n; ++i) {
  44. double d = sqrt(o2(cw[i].a-A)+o2(cw[i].b-B)+o2(cw[i].c-C));
  45. if(d > r1 + cw[i].r2) continue;
  46. if(d + cw[i].r2 <= r1) {
  47. ans += 4.0*pi/3*cw[i].r2*cw[i].r2*cw[i].r2;
  48. }else ans += tiji(cw[i]);
  49. }
  50. printf("Case #%d: %.10f\n", ++cas, ans);
  51. }
  52. return 0;
  53. }
  54. /*X = r1-(r1^2-r2^2+d^2)/2d
  55. pi/3*(X)^2*(3r1-(X))
  56. Y = r2-(r2^2-r1^2+d^2)/2d
  57. +pi/3*(Y)^2*(3r2-(Y))*/

K div1 Sticks 搜索

  1. //12分6写的有点丑https://paste.ubuntu.com/p/kHBHNCGgnh/
  2. #include<bits/stdc++.h>
  3. #define fi first
  4. #define se second
  5. #define iis std::ios::sync_with_stdio(false)
  6. #define pb push_back
  7. namespace lh {
  8. #define o2(x) (x)*(x)
  9. using namespace std;
  10. typedef long long LL;
  11. typedef pair<int, int> pii;
  12. }
  13. using namespace lh;
  14. const int INF = 0x3f3f3f3f;
  15. const int MXN = 1e4 + 100;
  16. int n;
  17. LL ar[MXN];
  18. int is[13][13][13], g[13];
  19. struct lp {
  20. LL x, y, z;
  21. }ans[5], tmp[5];
  22. int ANS;
  23. void dfs(int cur, int num) {
  24. if(cur/3 + num <= ANS) return ;
  25. if(cur == 3) {
  26. if(ar[g[0]]+ar[g[1]] > ar[g[2]]) {
  27. num ++;
  28. tmp[num].x = ar[g[0]]; tmp[num].y = ar[g[1]]; tmp[num].z = ar[g[2]];
  29. }
  30. if(num > ANS) {
  31. ANS = num;
  32. for(int i = 1; i <= num; ++i) ans[i] = tmp[i];
  33. }
  34. return ;
  35. }
  36. int d[13];
  37. for(int i = 0; i < cur; ++i) d[i] = g[i];
  38. int k = 0, ret;
  39. //tmp[num+1].x = ar[d[0]];
  40. for(int i = 1; i < cur; ++i) {
  41. //tmp[num+1].y = ar[d[i]];
  42. for(int j = i + 1; j < cur; ++j) {
  43. //tmp[num+1].z = ar[d[j]];
  44. ret = num + is[d[0]][d[i]][d[j]];
  45. if(is[d[0]][d[i]][d[j]]) {
  46. tmp[num+1].x = ar[d[0]];
  47. tmp[num+1].y = ar[d[i]];
  48. tmp[num+1].z = ar[d[j]];
  49. }
  50. k = 0;
  51. for(int t = 1; t < cur; ++t) {
  52. if(t != i && t != j) g[k++] = d[t];
  53. }
  54. dfs(cur-3, ret);
  55. if(ANS == 4) return ;
  56. }
  57. }
  58. }
  59. int main() {
  60. int cas = 0;
  61. int tim; scanf("%d", &tim);
  62. while(tim --) {
  63. for(int i = 0; i < 12; ++i) scanf("%lld", &ar[i]), g[i] = i;
  64. sort(ar, ar + 12);
  65. for(int i = 0; i < 12; ++i) {
  66. for(int j = i + 1; j < 12; ++j) {
  67. for(int k = j + 1; k < 12; ++k) {
  68. is[i][j][k] = ((ar[i] + ar[j]) > ar[k]);
  69. }
  70. }
  71. }
  72. ANS = 0;
  73. dfs(12, 0);
  74. printf("Case #%d: %d\n", ++cas, ANS);
  75. for(int i = 1; i <= ANS; ++i) {
  76. printf("%lld %lld %lld\n", ans[i].x, ans[i].y, ans[i].z);
  77. }
  78. }
  79. return 0;
  80. }

day3

F div2 小清新数论(莫比乌斯反演)

莫比乌斯反演

  1. //F
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. typedef long long LL;
  5. const int MXN = 1e7+ 7;
  6. const int mod = 998244353;
  7. LL n, m;
  8. int noprime[MXN], pp[MXN], pcnt;
  9. int phi[MXN], mu[MXN];
  10. LL pre_mu[MXN];
  11. void init_prime() {
  12. noprime[0] = noprime[1] = 1;
  13. mu[1] = 1; phi[1] = 1;
  14. for(int i = 2; i < MXN; ++i) {
  15. if(!noprime[i]) pp[pcnt++] = i, phi[i] = i-1, mu[i] = -1;
  16. for(int j = 0; j < pcnt && pp[j] * i < MXN; ++j) {
  17. noprime[pp[j]*i] = 1;
  18. phi[pp[j]*i] = (pp[j]-1)*phi[i];
  19. mu[pp[j]*i] = -mu[i];
  20. if(i % pp[j] == 0) {
  21. phi[pp[j]*i] = pp[j]*phi[i];
  22. mu[pp[j]*i] = 0;
  23. break;
  24. }
  25. }
  26. }
  27. for(int i = 1; i < MXN; ++i) pre_mu[i] = pre_mu[i-1] + mu[i];
  28. }
  29. LL solve(LL n) {
  30. LL ans = 0, tmp;
  31. for(LL L = 1, R; L <= n; L = R + 1) {
  32. R = n/(n/L);
  33. tmp = pre_mu[R]-pre_mu[L-1];
  34. ans = (ans + tmp*(n/L)%mod*(n/L)%mod)%mod;
  35. }
  36. return (ans+mod)%mod;
  37. }
  38. int main() {
  39. init_prime();
  40. scanf("%lld", &n);
  41. LL ans = 0, tmp;
  42. for(LL L = 1, R; L <= n; L = R + 1) {
  43. R = n/(n/L);
  44. tmp = pre_mu[R]-pre_mu[L-1];
  45. ans = (ans + tmp*solve(n/L)%mod)%mod;
  46. }
  47. printf("%lld\n", (ans+mod)%mod);
  48. return 0;
  49. }

F div1 小清新数论(杜教筛)

杜教筛

题解

code1:利用欧拉函数

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long LL;
  4. const int MXN = 1e7+ 7;
  5. const LL mod = 998244353;
  6. const LL inf = 1e18;
  7. LL n, m, inv2;
  8. int noprime[MXN], pp[MXN], pcnt;
  9. int phi[MXN], mu[MXN];
  10. LL pre_mu[MXN], pre_phi[MXN];
  11. unordered_map<LL, LL> mp1, mp2;
  12. void init_prime() {
  13. noprime[0] = noprime[1] = 1;
  14. mu[1] = 1; phi[1] = 1;
  15. for(int i = 2; i < MXN; ++i) {
  16. if(!noprime[i]) pp[pcnt++] = i, phi[i] = i-1, mu[i] = -1;
  17. for(int j = 0; j < pcnt && pp[j] * i < MXN; ++j) {
  18. noprime[pp[j]*i] = 1;
  19. phi[pp[j]*i] = (pp[j]-1)*phi[i];
  20. mu[pp[j]*i] = -mu[i];
  21. if(i % pp[j] == 0) {
  22. phi[pp[j]*i] = pp[j]*phi[i];
  23. mu[pp[j]*i] = 0;
  24. break;
  25. }
  26. }
  27. }
  28. for(int i = 1; i < MXN; ++i) {
  29. pre_mu[i] = pre_mu[i-1] + mu[i];
  30. pre_phi[i] = (pre_phi[i-1] + phi[i])%mod;
  31. }
  32. }
  33. LL solve_mu(LL n) {
  34. if(n < MXN) return pre_mu[n];
  35. if(mp1[n] == inf) return 0;
  36. if(mp1[n]) return mp1[n];
  37. LL ans = 1;
  38. for(LL L = 2, R; L <= n; L = R + 1) {
  39. R = n/(n/L);
  40. ans -= (R-L+1LL)%mod*solve_mu(n/L);
  41. }
  42. mp1[n] = ans;
  43. if(mp1[n] == 0) mp1[n] = inf;
  44. return ans;
  45. }
  46. LL solve_phi(LL n) {
  47. if(n < MXN) return pre_phi[n];
  48. if(mp2[n]) return mp2[n];
  49. LL ans = n%mod*(n+1)%mod*inv2%mod;
  50. for(LL L = 2, R; L <= n; L = R + 1) {
  51. R = n/(n/L);
  52. ans = (ans - (R-L+1LL)%mod*solve_phi(n/L)%mod)%mod;
  53. }
  54. ans = (ans + mod) % mod;
  55. mp2[n] = ans;
  56. return ans;
  57. }
  58. int main() {
  59. inv2 = 499122177;
  60. init_prime();
  61. scanf("%lld", &n);
  62. LL ans = 0;
  63. for(LL L = 1, R; L <= n; L = R + 1) {
  64. R = n/(n/L);
  65. ans = (ans + (solve_mu(R)-solve_mu(L-1))%mod*(solve_phi(n/L)*2LL%mod-1LL)%mod+mod)%mod;
  66. }
  67. printf("%lld\n", (ans+mod)%mod);
  68. return 0;
  69. }

code2:利用莫比乌斯反演和迪利克雷卷积

  1. #include<bits/stdc++.h>
  2. #define fi first
  3. #define se second
  4. #define iis std::ios::sync_with_stdio(false);cin.tie(0)
  5. #define pb push_back
  6. #define o2(x) (x)*(x)
  7. using namespace std;
  8. typedef long long LL;
  9. typedef pair<int, int> pii;
  10. typedef pair<LL, LL> pll;
  11. const int INF = 0x3f3f3f3f;
  12. const LL MOD = 998244353;
  13. const int MXN = 5e6 + 6;
  14. LL n, q, m;
  15. int noprime[MXN], pp[MXN/2], pcnt;
  16. int mu[MXN], phi[MXN];
  17. int pre_mu[MXN];
  18. LL mumu[MXN];
  19. unordered_map<LL,LL>mp1,mp2;
  20. void init_rime() {
  21. noprime[0] = noprime[1] = 1;
  22. mu[1] = 1;
  23. for(int i = 2; i < MXN; ++i) {
  24. if(!noprime[i]) pp[pcnt++] = i, mu[i]=-1;
  25. for(int j = 0; j < pcnt && i*pp[j] < MXN; ++j) {
  26. noprime[i*pp[j]] = 1;
  27. mu[i*pp[j]] = -mu[i];
  28. if(i % pp[j] == 0) {
  29. mu[i*pp[j]] = 0;
  30. break;
  31. }
  32. }
  33. }
  34. for(int i = 1; i < MXN; ++i) pre_mu[i] = pre_mu[i-1] + mu[i], mumu[i] = mu[i];
  35. for(int i = 2; i < MXN; ++i) {
  36. for(int j = i; j < MXN; j += i) {
  37. mumu[j] += mu[i]*mu[j/i];
  38. if(mumu[j] >= MOD) mumu[j] %= MOD;
  39. }
  40. }
  41. for(int i = 2; i < MXN; ++i) mumu[i] = (mumu[i]+mumu[i-1]+MOD)%MOD;
  42. }
  43. LL solve_u(LL n) {
  44. if(n < MXN) return pre_mu[n];
  45. if(mp1.count(n)) return mp1[n];
  46. LL ans = 1;
  47. for(LL L = 2, R; L <= n; L = R + 1) {
  48. R = n/(n/L);
  49. ans = (ans - (R-L+1)%MOD*solve_u(n/L)%MOD+MOD)%MOD;
  50. }
  51. mp1[n] = ans;
  52. return ans;
  53. }
  54. LL solve_uu(LL n) {
  55. if(n < MXN) return mumu[n];
  56. if(mp2.count(n)) return mp2[n];
  57. LL ans = 0;
  58. for(LL L = 1, R; L <= n; L = R + 1) {
  59. R = n/(n/L);
  60. ans = (ans + (solve_u(R)-solve_u(L-1)+MOD)%MOD*solve_u(n/L)%MOD);
  61. if(ans >= MOD) ans %= MOD;
  62. }
  63. mp2[n] = (ans+MOD)%MOD;
  64. return ans;
  65. }
  66. int main(int argc, char const *argv[]) {
  67. init_rime();
  68. scanf("%lld", &n);
  69. LL ans = 0;
  70. for(LL L = 1, R; L <= n; L = R + 1) {
  71. R = n/(n/L);
  72. ans = (ans + (n/L)%MOD*(n/L)%MOD*(solve_uu(R)-solve_uu(L-1)+MOD)%MOD)%MOD;
  73. }
  74. printf("%lld\n", (ans+MOD)%MOD);
  75. return 0;
  76. }
  77. /*
  78. void init_rime() {
  79. noprime[0] = noprime[1] = 1;
  80. mu[1] = 1;mumu[1] = 1;
  81. for(int i = 2; i < MXN; ++i) {
  82. if(!noprime[i]) pp[pcnt++] = i, mu[i]=-1, mumu[i]=-2;
  83. for(int j = 0; j < pcnt && i*pp[j] < MXN; ++j) {
  84. noprime[i*pp[j]] = 1;
  85. mu[i*pp[j]] = -mu[i];
  86. mumu[i*pp[j]] = mumu[i]*mumu[pp[j]];
  87. if(i % pp[j] == 0) {
  88. mu[i*pp[j]] = 0;
  89. if((i/pp[j])%pp[j]) mumu[i*pp[j]] = mumu[i/pp[j]];
  90. else mumu[i*pp[j]] = 0;
  91. break;
  92. }
  93. }
  94. }
  95. for(int i = 1; i < MXN; ++i) pre_mu[i] = pre_mu[i-1] + mu[i];
  96. for(int i = 2; i < MXN; ++i) mumu[i] = (mumu[i]+mumu[i-1]+MOD)%MOD;
  97. }
  98. */

H div2 涂鸦(计数)

  1. //H
  2. #include<bits/stdc++.h>
  3. #define fi first
  4. #define se second
  5. #define lson rt<<1
  6. #define rson rt<<1|1
  7. #define iis std::ios::sync_with_stdio(false)
  8. #define pb push_back
  9. namespace lh {
  10. #define o2(x) (x)*(x)
  11. using namespace std;
  12. typedef long long LL;
  13. typedef unsigned long long uLL;
  14. typedef pair<int, LL> pii;
  15. }
  16. using namespace lh;
  17. const int mod = 998244353;
  18. const int INF = 0x3f3f3f3f;
  19. const int MXN = 2e5 + 7;
  20. const int N = 1e3 + 7;
  21. int n, m;
  22. int ar[N][N];
  23. LL dp[1005][1005];
  24. LL ksm(LL a, LL b) {
  25. LL res = 1;
  26. while(b) {
  27. if(b & 1) res = res *a % mod;
  28. a = a * a % mod;
  29. b >>= 1;
  30. }
  31. return res;
  32. }
  33. int da[N][N], di[N][N], dj[N][N],dij[N][N];
  34. void ADD(LL &a) {
  35. if(a >= mod) a %= mod;
  36. }
  37. int lowbit(int x) {
  38. return x&(-x);
  39. }
  40. //sumxy = (x+1)(y+1)sigma(d[i][j])-(y+1)sigma(i*d[i][j])-(x+1)sigma(j*d[i][j])+sigma(i*j*d[i][j])
  41. void add(int x, int y, int z){
  42. for(int i=x;i<=n;i+=lowbit(i)){
  43. for(int j=y;j<=m;j+=lowbit(j)){
  44. da[i][j] += z; di[i][j] += z*x; dj[i][j] += z*y; dij[i][j] += z*x*y;
  45. }
  46. }
  47. }
  48. void update(int xa,int ya,int xb,int yb,int z){
  49. add(xa,ya,z);add(xa,yb+1,-z);add(xb+1,ya,-z);add(xb+1,yb+1,z);
  50. }
  51. int query(int x, int y){
  52. int res = 0;
  53. for(int i = x; i>0; i -= lowbit(i)){
  54. for(int j = y; j>0; j -= lowbit(j)){
  55. res += (x+1)*(y+1)*da[i][j] - (y+1)*di[i][j] - (x+1)*dj[i][j] + dij[i][j];
  56. }
  57. }
  58. return res;
  59. }
  60. int ask(int xa,int ya,int xb,int yb){
  61. return query(xb,yb)-query(xb,ya-1)-query(xa-1,yb)+query(xa-1,ya-1);
  62. }
  63. void init(){
  64. for(int i = 1; i <= n; ++i){
  65. for(int j = 1; j <= m; ++j){
  66. LL tmp = dp[i][j]-dp[i-1][j]-dp[i][j-1]+dp[i-1][j-1];
  67. tmp = (tmp%mod + mod)%mod;
  68. add(i,j,tmp);
  69. }
  70. }
  71. }
  72. int main(int argc, char const *argv[]) {
  73. int q;
  74. scanf("%d%d%d", &n, &m, &q);
  75. LL tmp, l, r;
  76. LL two = ksm(2, mod-2);
  77. for(int i = 1; i <= n; ++i) {
  78. scanf("%lld%lld", &l, &r);
  79. tmp = (r-l+1)*(r-l+2)%mod;
  80. tmp = ksm(tmp, mod - 2);
  81. for(int j = l; j <= r; ++j) {
  82. dp[i][j] = (j-l+1)*(r-j+1)%mod*tmp%mod*2%mod;
  83. }
  84. }
  85. LL ANS = 0;
  86. //init();
  87. //printf("%lld %d\n", ANS, ask(1, 1, n, m));
  88. int x1, y1, x2, y2;
  89. while(q--) {
  90. scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
  91. if(x1+y1 > x2+y2) {
  92. swap(x1,x2);
  93. swap(y1,y2);
  94. }
  95. //printf("%d %d %d %d\n", x1,y1,x2,y2);
  96. update(x1,y1,x2,y2,1);
  97. }
  98. ANS = 0;
  99. for(int i = 1; i <= n; ++i) {
  100. for(int j = 1; j <= m; ++j) {
  101. if(ask(i,j,i,j)) continue;
  102. ANS += dp[i][j];
  103. ADD(ANS);
  104. }
  105. }
  106. printf("%lld\n", ANS);
  107. return 0;
  108. }

I div1&2 (并查集)

  1. //I石头剪刀布
  2. //不能路径压缩,必须按秩合并
  3. #include<bits/stdc++.h>
  4. #define clr(a, b) memset(a,b,sizeof((a)))
  5. #define lson rt<<1
  6. #define rson rt<<1|1
  7. using namespace std;
  8. typedef long long LL;
  9. const int MXN = 1e6 + 7;
  10. const LL MOD = 998244353;
  11. int n, m, Q;
  12. int fa[MXN], rk[MXN];
  13. LL all[MXN], ke[MXN];//场数,客场数
  14. LL ALL, KE;
  15. LL ksm(LL a, LL b) {
  16. LL res = 1;
  17. while(b) {
  18. if(b&1) res = res * a % MOD;
  19. a = a * a % MOD;
  20. b >>= 1;
  21. }
  22. return res;
  23. }
  24. int Fi(int x) {
  25. ALL = all[x]; KE = ke[x];
  26. if(x == fa[x]) return x;
  27. int tmp = fa[x];
  28. while(tmp != fa[tmp]) {
  29. ALL += all[tmp]; KE += ke[tmp];
  30. tmp = fa[tmp];
  31. }
  32. ALL += all[tmp]; KE += ke[tmp];
  33. return tmp;
  34. }
  35. int Find(int x) {
  36. int ans = x;
  37. if(x != fa[x]) {
  38. int t = fa[x];
  39. ans = Find(fa[x]);
  40. ALL += all[t];
  41. KE += ke[t];
  42. }
  43. return ans;
  44. }
  45. void UNION(int x,int y) {
  46. int pa = Find(x), pb = Find(y);
  47. if(pa == pb) return ;
  48. ++ all[pa]; ++ all[pb];
  49. ++ ke[pb];
  50. if(rk[pa] < rk[pb]) swap(pa, pb);
  51. ++ rk[pa];
  52. all[pb] -= all[pa];
  53. ke[pb] -= ke[pa];
  54. fa[pb] = pa;
  55. }
  56. int main() {
  57. scanf("%d%d", &n, &m);
  58. for(int i = 1; i <= n; ++i) fa[i] = i;
  59. while(m --) {
  60. int opt, x, y;
  61. scanf("%d%d", &opt, &x);
  62. if(opt == 1) {
  63. scanf("%d", &y);
  64. UNION(x, y);
  65. }else {
  66. ALL = all[x]; KE = ke[x];
  67. Fi(x);//Find(x);
  68. LL a = ALL - KE, b = KE, c = n - a - b;
  69. printf("%lld\n", ksm(3, c) * ksm(2, a) % MOD);
  70. }
  71. }
  72. return 0;
  73. }

E div1&2 精简改良 生成树dp

迷之复杂度

  1. #include<bits/stdc++.h>
  2. #define fi first
  3. #define se second
  4. #define iis std::ios::sync_with_stdio(false)
  5. #define eb emplace_back
  6. #define o2(x) (x)*(x)
  7. using namespace std;
  8. typedef long long LL;
  9. typedef pair<int, int> pii;
  10. inline LL read(){
  11. LL x=0;int f=0;char ch=getchar();
  12. while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
  13. while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
  14. return x=f?-x:x;
  15. }
  16. inline void write(LL x) {
  17. if(x==0){putchar('0'),putchar('\n');return;}
  18. if(x < 0) {putchar('-');x=-x;}
  19. static char s[23];int l = 0;
  20. while(x!=0)s[l++]=x%10+48,x/=10;
  21. while(l)putchar(s[--l]);
  22. putchar('\n');
  23. }
  24. const int INF = 0x3f3f3f3f;
  25. const LL mod = 998244353;
  26. const int MXN = 1e3 + 7;
  27. int n, m;
  28. std::vector<int> vs[(1<<14)+5];
  29. LL dp[(1<<14)+5][20];
  30. LL dis[20][20], N[(1<<14)+5];
  31. int sta;
  32. //for (int x = S; x; x = (x-1)&S))枚举子集,复杂度2^m,会漏掉空集
  33. int main(int argc, char const *argv[]) {
  34. #ifndef ONLINE_JUDGE
  35. freopen("E://ADpan//in.in", "r", stdin);
  36. //freopen("E://ADpan//out.out", "w", stdout);
  37. #endif
  38. n = read(), m = read();
  39. //scanf("%d%d", &n, &m);
  40. memset(dis, -1, sizeof(dis));
  41. memset(dp, -1, sizeof(dp));
  42. for(int i = 0, a, b, c; i < m; ++i) {
  43. a = read(), b = read(), c = read();
  44. //scanf("%d%d%d", &a, &b, &c);
  45. dis[a][b] = dis[b][a] = c;
  46. }
  47. sta = 1 << n;
  48. for(int i = 1; i < sta; ++i) {
  49. for(int j = 0; j < n; ++j) if((i>>j)&1) vs[i].eb(j+1);
  50. N[i] = vs[i].size();
  51. }
  52. LL tmp, ans = 0;
  53. for(int i = 1, j = 1; i < sta; i <<= 1, ++j) dp[i][j] = 0;
  54. for(int t = 1; t < sta; ++t) {
  55. for(int old = (t-1)&t; old; old = (old-1)&t) {
  56. for(auto i: vs[t]) {
  57. if(dp[t-old][i]==-1) continue;
  58. for(auto j: vs[old]) {
  59. if(dis[i][j]==-1||dp[old][j]==-1) continue;
  60. tmp = dp[old][j]+dp[t-old][i]+dis[i][j]*N[old]*(n-N[old]);
  61. dp[t][i] = (dp[t][i]>tmp?dp[t][i]:tmp);
  62. }
  63. }
  64. }
  65. }
  66. for(int i = 1; i <= n; ++i) ans = (ans>dp[sta-1][i]?ans:dp[sta-1][i]);
  67. write(ans);
  68. //printf("%lld\n", ans);
  69. return 0;
  70. }

day4

I div2 咆咆咆哮 (贪心)

  1. //I
  2. #include<bits/stdc++.h>
  3. #define fi first
  4. #define se second
  5. #define iis std::ios::sync_with_stdio(false)
  6. namespace lh {
  7. #define o2(x) (x)*(x)
  8. using namespace std;
  9. typedef long long LL;
  10. typedef unsigned long long uLL;
  11. typedef pair<int, int> pii;
  12. typedef pair<int, LL> piL;
  13. }
  14. using namespace lh;
  15. const int MXN = 1e6 + 5;
  16. const double eps = 1e-8;
  17. int n;
  18. LL dp[1005][1005];
  19. struct lp {
  20. LL a, b;
  21. }cw[1005], tmp[1005];
  22. bool cmp(const lp &A, const lp &B) {
  23. if(A.a != B.a) return A.a > B.a;
  24. return A.b < B.b;
  25. }
  26. bool cmp1(const lp &A, const lp &B) {
  27. return (A.b-A.a) > (B.b-B.a);
  28. }
  29. int main(){
  30. scanf("%d", &n);
  31. LL ans = 0;
  32. for(int i = 1; i <= n; ++i) {
  33. scanf("%lld%lld", &cw[i].a, &cw[i].b);
  34. ans += cw[i].a;
  35. }
  36. for(int t = 1; t < n; ++t) {
  37. for(int i = 1; i <= n; ++i) {
  38. tmp[i].a = cw[i].a;
  39. tmp[i].b = cw[i].b * (n-t);
  40. }
  41. sort(tmp + 1, tmp + 1 + n, cmp1);
  42. LL ret = 0;
  43. for(int i = 1; i <= n; ++i) {
  44. if(i <= t) ret += tmp[i].b;
  45. else ret += tmp[i].a;
  46. }
  47. ans = max(ans, ret);
  48. }
  49. printf("%lld\n", ans);
  50. return 0;
  51. }

I div1 咆咆咆哮 (奇怪的三分+贪心)

  1. //蜜汁三分
  2. #include<bits/stdc++.h>
  3. #define fi first
  4. #define se second
  5. #define iis std::ios::sync_with_stdio(false)
  6. #define eb emplace_back
  7. #define o2(x) (x)*(x)
  8. using namespace std;
  9. typedef long long LL;
  10. typedef pair<int, int> pii;
  11. inline LL read(){
  12. LL x=0;int f=0;char ch=getchar();
  13. while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
  14. while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
  15. return x=f?-x:x;
  16. }
  17. inline void write(LL x) {
  18. if(x==0){putchar('0'),putchar('\n');return;}
  19. if(x < 0) {putchar('-');x=-x;}
  20. static char s[23];int l = 0;
  21. while(x!=0)s[l++]=x%10+48,x/=10;
  22. while(l)putchar(s[--l]);
  23. putchar('\n');
  24. }
  25. const int INF = 0x3f3f3f3f;
  26. const LL mod = 998244353;
  27. const int MXN = 1e5 + 7;
  28. int n;
  29. LL dp[1005][1005];
  30. struct lp {
  31. LL a, b;
  32. }cw[1005], tmp[1005];
  33. bool cmp(const lp &A, const lp &B) {
  34. if(A.a != B.a) return A.a > B.a;
  35. return A.b < B.b;
  36. }
  37. bool cmp1(const lp &A, const lp &B) {
  38. return (A.b-A.a) < (B.b-B.a);
  39. }
  40. LL check(int t) {//t个b
  41. LL ans = 0;
  42. priority_queue<LL> Q;
  43. for(int i = 1; i <= n; ++i) {
  44. ans += cw[i].a;
  45. Q.push(cw[i].b*(n-t)-cw[i].a);
  46. }
  47. while(t --) {
  48. ans += Q.top(); Q.pop();
  49. }
  50. return ans;
  51. }
  52. int main(){
  53. n = read();
  54. LL ans = 0;
  55. for(int i = 1; i <= n; ++i) {
  56. cw[i].a = read(), cw[i].b = read();
  57. ans += cw[i].a;
  58. }
  59. int L = 0, R = n, mid1, mid2;
  60. LL res1, res2;
  61. while(L <= R) {
  62. mid1 = (2*L+R)/3;mid2 = (L+2*R)/3;
  63. //mid1 = (L+R)/2;mid2 = (mid1+R)/2;
  64. res1 = check(mid1);
  65. res2 = check(mid2);
  66. if(res1 > res2) R = mid2-1, ans = max(ans, res1);
  67. else L = mid1+1, ans = max(ans, res2);
  68. }
  69. write(ans);
  70. return 0;
  71. }

C div2 (规律)

  1. //C
  2. 相邻点度数均大于1就不行或者链长为3

K div2 两条路径(树形dp)

  1. //K
  2. #include<bits/stdc++.h>
  3. #define fi first
  4. #define se second
  5. #define iis std::ios::sync_with_stdio(false)
  6. namespace lh {
  7. #define o2(x) (x)*(x)
  8. using namespace std;
  9. typedef long long LL;
  10. typedef unsigned long long uLL;
  11. typedef pair<int, int> pii;
  12. typedef pair<int, LL> piL;
  13. }
  14. using namespace lh;
  15. const int MXN = 1e6 + 5;
  16. const double eps = 1e-8;
  17. int n, x;
  18. std::vector<int> mp[MXN];
  19. LL ar[MXN], mi[40], dp[MXN];
  20. void dfs(int u,int ba) {
  21. dp[u] = ar[u];
  22. for(auto v: mp[u]) {
  23. if(v == ba) continue;
  24. dfs(v, u);
  25. dp[u] = max(dp[u], dp[v] + ar[u]);
  26. }
  27. }
  28. bool cmp(LL a, LL b) {
  29. return a > b;
  30. }
  31. int main(){
  32. mi[0] = 1;
  33. for(int i = 1; i <= 32; ++i) mi[i] = mi[i-1] * 2;
  34. scanf("%d", &n);
  35. for(int i = 1; i <= n; ++i) {
  36. scanf("%lld", &ar[i]);
  37. if(ar[i] >= 0) ar[i] = mi[ar[i]-1];
  38. else ar[i] = -mi[-ar[i]-1];
  39. //printf("%lld\n", ar[i]);
  40. }
  41. for(int i = 1, a, b; i < n; ++i) {
  42. scanf("%d%d", &a, &b);
  43. mp[a].push_back(b);
  44. mp[b].push_back(a);
  45. }
  46. int Q; scanf("%d", &Q);
  47. while(Q --) {
  48. scanf("%d", &x);
  49. for(int i = 1; i <= n; ++i) dp[i] = 0;
  50. dfs(x, x);
  51. std::vector<LL> vs;
  52. for(auto v: mp[x]) {
  53. if(dp[v] >= 0) vs.push_back(dp[v]);
  54. }
  55. sort(vs.begin(), vs.end(), cmp);
  56. LL ans = ar[x];
  57. for(int i = 0; i < vs.size() && i < 4; ++i) ans += vs[i];
  58. //printf("**%lld\n", ans);
  59. if(ans < 0) printf("-"), ans = -ans;
  60. std::vector<int> v;
  61. while(ans) {
  62. if(ans & 1) v.push_back(1);
  63. else v.push_back(0);
  64. ans /= 2;
  65. }
  66. reverse(v.begin(), v.end());
  67. for(auto s: v) {
  68. printf("%d", s);
  69. }
  70. printf("\n");
  71. }
  72. return 0;
  73. }

D div1&2 欧拉回路 (性质)

  1. //D欧拉回路
  2. //保证度数为偶数即可,注意特判2的情况
  3. #include<bits/stdc++.h>
  4. #define fi first
  5. #define se second
  6. #define iis std::ios::sync_with_stdio(false)
  7. #define eb emplace_back
  8. #define o2(x) (x)*(x)
  9. using namespace std;
  10. typedef long long LL;
  11. typedef pair<int, int> pii;
  12. inline LL read(){
  13. LL x=0;int f=0;char ch=getchar();
  14. while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
  15. while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
  16. return x=f?-x:x;
  17. }
  18. inline void write(LL x) {
  19. if(x==0){putchar('0'),putchar('\n');return;}
  20. if(x < 0) {putchar('-');x=-x;}
  21. static char s[23];int l = 0;
  22. while(x!=0)s[l++]=x%10+48,x/=10;
  23. while(l)putchar(s[--l]);
  24. putchar('\n');
  25. }
  26. const int INF = 0x3f3f3f3f;
  27. const LL mod = 998244353;
  28. const int MXN = 1e3 + 7;
  29. int n, m;
  30. int main(int argc, char const *argv[]) {
  31. scanf("%d%d", &n, &m);
  32. if(m % 2 == 0 && n % 2 == 1) swap(n, m);
  33. if(m == 2) swap(n, m);
  34. LL ans = (n-1)*m + n*(m-1);
  35. if(n == 2) {
  36. ans = ans + ((m-2)/2)*2+(m%2==1);
  37. }else if(n % 2 == 1) {
  38. ans = (ans+((m-2)/2)*2+4+((n-2)/2)*2);
  39. }else if(m % 2 == 1) {
  40. ans = (ans+((m-2)/2)*2+4+(n-2)/2+(n-4)/2);
  41. }else {
  42. ans = (ans+m+n-4);
  43. }
  44. printf("%lld\n", ans);
  45. return 0;
  46. }

G div1&2 置置置换

\(dp[i] = \sum_{j=1,j+=2}^{j<=i}dp[j-1]*dp[i-j]*COMB(i-1, j-1)\)

  1. /*
  2. 题意:有多少个n的排列满足:偶数位置小于奇数位置,奇数位置大于偶数位置;减增减增。。。的序列
  3. */
  4. //上凸和下凸的答案是一样的
  5. //dp[i]表示1-i的排列的合法情况总数
  6. //枚举最大的数字i所在的位置:dp[i] = \sum_{j=1,j+=2}^{j<=i}dp[j-1]*dp[i-j]*COMB(i-1, j-1)
  7. #include<bits/stdc++.h>
  8. #define fi first
  9. #define se second
  10. #define iis std::ios::sync_with_stdio(false)
  11. #define eb emplace_back
  12. #define o2(x) (x)*(x)
  13. using namespace std;
  14. typedef long long LL;
  15. typedef pair<int, int> pii;
  16. inline LL read(){
  17. LL x=0;int f=0;char ch=getchar();
  18. while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
  19. while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
  20. return x=f?-x:x;
  21. }
  22. inline void write(LL x) {
  23. if(x==0){putchar('0'),putchar('\n');return;}
  24. if(x < 0) {putchar('-');x=-x;}
  25. static char s[23];int l = 0;
  26. while(x!=0)s[l++]=x%10+48,x/=10;
  27. while(l)putchar(s[--l]);
  28. putchar('\n');
  29. }
  30. const int INF = 0x3f3f3f3f;
  31. const LL mod = 1e9 + 7;
  32. const int MXN = 1e4 + 7;
  33. LL F[MXN], Inv[MXN], invF[MXN];
  34. LL ksm(LL a, int b) {
  35. LL res = 1;
  36. for(;b;b>>=1,a=a*a%mod) {
  37. if(b&1) res=res*a%mod;
  38. }
  39. return res;
  40. }
  41. int n;
  42. LL dp[MXN];
  43. void init() {
  44. Inv[1] = F[1] = invF[1] = 1;
  45. Inv[0] = F[0] = invF[0] = 1;
  46. for(int i = 2; i < MXN; ++i) {
  47. F[i] = F[i-1] * i % mod;
  48. Inv[i] = (mod-mod/i)*Inv[mod%i] % mod;
  49. invF[i] = invF[i-1] * Inv[i] % mod;
  50. }
  51. }
  52. LL COMB(int n, int m) {
  53. if(n == m || m == 0) return 1;
  54. if(n < m) return 0;
  55. return F[n]*invF[m]%mod*invF[n-m]%mod;
  56. }
  57. int main(){
  58. n = read();
  59. init();
  60. dp[0] = dp[1] = dp[2] = 1;
  61. for(int i = 3; i <= n; ++i) {
  62. for(int j = 1; j <= i; j += 2) {
  63. dp[i] = (dp[i] + dp[j-1] * dp[i-j]%mod * COMB(i-1, j-1)%mod)%mod;
  64. }
  65. }
  66. printf("%lld\n", dp[n]);
  67. return 0;
  68. }
  69. /*
  70. d4G:
  71. f[i][j]表示前i个位置,在剩下的第j小的方案数,枚举所有大于它的k。用前缀和或后缀和维护
  72. 1I/4G/7J
  73. */

2019 wannafly winter camp day1-4代码库的更多相关文章

  1. 2019 wannafly winter camp

    2019 wannafly winter camp Name Rank Solved A B C D E F G H I J K day1 9 5/11 O O O O O day2 5 3/11 O ...

  2. 2020 CCPC Wannafly Winter Camp Day1 C. 染色图

    2020 CCPC Wannafly Winter Camp Day1 C. 染色图 定义一张无向图 G=⟨V,E⟩ 是 k 可染色的当且仅当存在函数 f:V↦{1,2,⋯,k} 满足对于 G 中的任 ...

  3. 2019 wannafly winter camp day 3

    2019 wannafly winter camp day 3 J 操作S等价于将S串取反,然后依次遍历取反后的串,每次加入新字符a,当前的串是T,那么这次操作之后的串就是TaT.这是第一次转化. 涉 ...

  4. 2019 wannafly winter camp day5-8代码库

    目录 day5 5H div2 Nested Tree (树形dp) 5F div2 Kropki (状压dp) 5J div1 Special Judge (计算几何) 5I div1 Sortin ...

  5. 2019 CCPC-Wannafly Winter Camp Day1 (Div2, onsite)

    solve:4/11 补题:6/11 A 机器人 补题:zz 这是一道分类讨论的题目,有一个规律就是如果必须要从第一个区到第二个区,那么最多转区两次(1到2一次,2到1一次),然后分类讨论即可,只要细 ...

  6. 2020 CCPC Wannafly Winter Camp Day1 Div.1&amp F

    #include<bits/stdc++.h> #define forn(i, n) for (int i = 0; i < int(n); i++) #define fore(i, ...

  7. 2020 CCPC Wannafly Winter Camp Day1 - I. K小数查询(分块)

    题目链接:K小数查询 题意:给你一个长度为$n$序列$A$,有$m$个操作,操作分为两种: 输入$x,y,c$,表示对$i\in[x,y] $,令$A_{i}=min(A_{i},c)$ 输入$x,y ...

  8. Wannafly Winter Camp 2019.Day 8 div1 E.Souls-like Game(线段树 矩阵快速幂)

    题目链接 \(998244353\)写成\(99824435\)然后调这个线段树模板1.5h= = 以后要注意常量啊啊啊 \(Description\) 每个位置有一个\(3\times3\)的矩阵, ...

  9. Wannafly Winter Camp 2019.Day 8 div1 I.岸边露伴的人生经验(FWT)

    题目链接 \(Description\) 给定\(n\)个十维向量\(\overrightarrow{V_i}=x_1,x_2,...,x_{10}\).定义\(\overrightarrow{V}= ...

随机推荐

  1. Spring 容器中bean的加载过程

    bean 的加载过程大致可以分为以下几个步骤: 1.获取配置的资源文件 2.对获取到的xml资源文件进行解析 3.获取包装资源 4.解析处理包装之后的资源 5.加载 提取bean 并进行注册(添加到b ...

  2. LiveTelecast直播平台技术图谱skill-map

    #直播平台技术图谱 ----##直播 ----###采集- **iOS** * HTTP Live Streaming * DirectShow- **Android** * setPreviewCa ...

  3. Ubuntu18.04 禁用笔记本电脑键盘

    1.先在命令行工具中输入 xinput list 找到AT Translated Set 2 keyboard,记住后面的ID,如我的ID为21. 输入命令,设置值为0 xinput 然后笔记本键盘就 ...

  4. Nacos Config客户端与Spring Boot、Spring Cloud深度集成

    目录 Nacos与Spring Boot集成 @NacosPropertySource和@NacosValue com.alibaba.nacos.spring.core.env.NacosPrope ...

  5. HTML5: HTML5 拖放

    ylbtech-HTML5: HTML5 拖放 1.返回顶部 1. HTML5 拖放(Drag 和 Drop) 拖放(Drag 和 drop)是 HTML5 标准的组成部分.   将 RUNOOB.C ...

  6. Java学习之抽象类

    抽象类特点: 1.抽象方法必须定义在抽象类中2.abstract关键字修饰:只能修饰类和方法3.抽象类不能实例化4.抽象类中的方法要被使用,必须由子类重写所有的抽象方法,实例化其子类 如果子类只重写部 ...

  7. Prometheus 详解

    Prometheus 章节 1.Prometheus 简介 2.Prometheus 安装与配置 3.Exporter 4.Pushgateway 5.本地存储和远程存储 6.高可用方案 7.报警插件 ...

  8. Zabbix当内存剩余不足10%的时候触发报警

    zabbix默认的剩余内存报警: Average Lack of available memory on server {HOST.NAME}{Template OS Linux:vm.memory. ...

  9. USACO 2014 US Open Decorating The Pastures

    题目大意: 给定n个点m条边的无向图 判断这个图能否将所有点依次染色为F J F J 若能输出最多能染多少个J 若不能输出-1 就是给一个图01染色 过程中判断是否出现不符合的情况 即点1到点2到点3 ...

  10. Zookeeper-技术专区-运作流程分析介绍

    Zookeeper的启动流程 Zookeeper的主类是QuorumPeerMain,启动时读取zoo.cfg配置文件,如果没有配置server列表,则单机模式启动,否则按集群模式启动,这里只分析集群 ...