• 两日总结十七


    前面放了几天假,这两天主要就是补了一下子前面比赛的题目。

    首先是牛客蔚蓝杯最后一场的题目:

     这一场是真的太可惜了,真的可惜,有两个题目都是直接想出来的,但是就是想的有的复杂。

    登录—专业IT笔试面试备考平台_牛客网

    Yet Another FFT Problem?

    这个一开始直接推出来就是找ai + bj == ai2 + bj2就行了,被题目影响了没有直接去FFT了,然后2e7直接爆内存了。。。其实就是暴力就行了,因为鸽巢原理,最多不会超过2e7+1个,找到就退出就行了,当时SB了。

    1. #include
    2. using namespace std;
    3. const int N = 1e6 + 5, inf = 0x3f3f3f3f, M = 1e7 + 5;
    4. int A[N],B[N];
    5. vectorint,int>> a,b,ans;
    6. int n,m,x;
    7. int mp1[2*M], mp2[M];
    8. int main() {
    9. cin >> n >> m;
    10. int fa = -1, fb = -1;
    11. for(int i = 1; i <= n; i ++) {
    12. cin >> x;
    13. A[i] = x;
    14. if(!mp1[x]) mp1[x] = i, a.push_back({x,i});
    15. else if(fa == -1) fa = i;
    16. }
    17. for(int i = 1; i <= m; i ++) {
    18. cin >> x;
    19. B[i] = x;
    20. if(!mp2[x]) mp2[x] = i, b.push_back({x,i});
    21. else if(fb == -1) fb = i;
    22. }
    23. if(fa != -1 && fb != -1) {
    24. cout << mp1[A[fa]] << " " << fa << " " << mp2[B[fb]] << " " << fb << endl;
    25. }else {
    26. for(int i = 0; i <= M; i ++) mp1[i]= 0;
    27. int cnt = 1;
    28. for(auto x : a) {
    29. for(auto y : b) {
    30. if(mp1[x.first + y.first]) {
    31. cout << ans[mp1[x.first+y.first]-1].first << " " << x.second << " " << ans[mp1[x.first+y.first]-1].second << " " << y.second << endl;
    32. return 0;
    33. }
    34. mp1[x.first + y.first] = cnt;
    35. ans.push_back({x.second,y.second});
    36. cnt ++;
    37. }
    38. }
    39. cout << -1 << endl;
    40. }
    41. return 0;
    42. }

    登录—专业IT笔试面试备考平台_牛客网

    然后就是这个Shannon Switching Game?也是相当怎么搞,但是细节没有处理好,不应该只往一边涂色的。。。

    1. #include
    2. #define OST ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    3. #define ll long long int
    4. #define ull unsigned long long int
    5. using namespace std;
    6. int e[105][105];
    7. int vis[105];
    8. int n, m, s, t;
    9. void BFS() {
    10. queue<int> q;
    11. q.push(t);
    12. while (q.size()) {
    13. int now = q.front();
    14. q.pop();
    15. for (int i = 1; i <= n; i ++) {
    16. if (vis[i] == t) continue;
    17. if (vis[i] != t && e[now][i] >= 2) {
    18. vis[i] = t;
    19. q.push(i);
    20. }
    21. int cnt = 0;
    22. for (int j = 1; j <= n; j ++) {
    23. if (vis[j] == t && e[i][j]) {
    24. cnt ++;
    25. }
    26. }
    27. if (cnt >= 2) vis[i] = t, q.push(i);
    28. }
    29. }
    30. }
    31. void BFS2() {
    32. queue<int> q;
    33. q.push(s);
    34. while (q.size()) {
    35. int now = q.front();
    36. q.pop();
    37. for (int i = 1; i <= n; i ++) {
    38. if (vis[i] != s && e[now][i] >= 2) {
    39. vis[i] = s;
    40. q.push(i);
    41. }
    42. }
    43. }
    44. }
    45. void solve() {
    46. cin >> n >> m >> s >> t;
    47. for (int i = 1; i <= n; i ++) vis[i] = i;
    48. for (int i = 1; i <= n; i ++)
    49. for (int j = 1; j <= n; j ++) e[i][j] = 0;
    50. for (int i = 1; i <= m; i ++) {
    51. int x, y;
    52. cin >> x >> y;
    53. e[x][y] ++;
    54. e[y][x] ++;
    55. }
    56. BFS();
    57. // for (int i = 1; i <= n; i ++) {
    58. // cout << vis[i] << " ";
    59. // }
    60. if (vis[s] == t) {
    61. cout << "Join Player" << endl;
    62. } else {
    63. BFS2();
    64. for (int i = 1; i <= n; i ++) {
    65. if (vis[i] == s) {
    66. int cnt = 0;
    67. for (int i = 1; i <= n; i++) {
    68. if (vis[i] == t && e[s][i]) {
    69. cnt++;
    70. }
    71. }
    72. if (cnt >= 2) {
    73. cout << "Join Player" << endl;
    74. return;
    75. }
    76. }
    77. }
    78. cout << "Cut Player" << endl;
    79. }
    80. }
    81. int main(int argc, char const *argv[]) {
    82. OST;
    83. int T;
    84. cin >> T;
    85. while (T --) {
    86. solve();
    87. }
    88. return 0;
    89. }

    登录—专业IT笔试面试备考平台_牛客网

    还有这个Reviewer Assignment网络流的板子题目,主要是建立边有点复杂,遇到的也少,就压根没有想到。最大流还有最小费用流都可以写。

    然后把这个题目补了,顺便重新整理了一下最大流,还有费用流的模板。

     然后就是Codeforces Round #816 (Div. 2)的补题:

    E题真的巧妙,每一次改变之后跑一遍最短路,然后每次更新最短值,最后面更新K次就行了。

    1. #include
    2. #define OST ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    3. #define ll long long int
    4. #define ull unsigned long long int
    5. #define pair pair
    6. using namespace std;
    7. const int N = 1e5 + 10;
    8. const ll inf = 0x3f3f3f3f3f3f3f3f;
    9. int n, m, k;
    10. struct node {
    11. int y;
    12. ll v;
    13. };
    14. vector e[N];
    15. vectordis(N, inf), dis2(N, inf);
    16. void Dij() {
    17. priority_queue, greater> q;
    18. for (int i = 1; i <= n; i ++) q.push({dis[i], i});
    19. while (q.size()) {
    20. auto [v, now] = q.top();
    21. q.pop();
    22. for (auto x : e[now]) {
    23. if (dis[x.y] > v + x.v) {
    24. dis[x.y] = v + x.v;
    25. q.push({dis[x.y], x.y});
    26. }
    27. }
    28. }
    29. }
    30. void Fen(int l, int r, int L, int R) {
    31. // cout << l << " " << r << " " << L << " " << R << endl;
    32. if (l > r) return;
    33. int mid = (l + r) / 2;
    34. //找到传送一次到m最小的
    35. int idx = -1;
    36. ll maxn = inf;
    37. for (int i = L; i <= R; i ++) {
    38. ll tmp = dis[i] + 1ll * pow(i - mid, 2);
    39. if (maxn > tmp) {
    40. maxn = tmp;
    41. idx = i;
    42. }
    43. }
    44. dis2[mid] = maxn;
    45. Fen(l, mid - 1, L, idx);
    46. Fen(mid + 1, r, idx, R);
    47. }
    48. int main(int argc, char const *argv[]) {
    49. OST;
    50. cin >> n >> m >> k;
    51. for (int i = 1; i <= m; i ++) {
    52. int x, y, v;
    53. cin >> x >> y >> v;
    54. e[x].push_back({y, v});
    55. e[y].push_back({x, v});
    56. }
    57. dis[1] = 0;
    58. Dij();
    59. // for (int i = 1; i <= n; i ++) cout << dis[i] << " ";
    60. // cout << endl;
    61. for (int i = 1; i <= k; i ++) {
    62. for (int i = 1; i <= n; i ++) dis2[i] = inf;
    63. Fen(1, n, 1, n);
    64. for (int i = 1; i <= n; i ++) dis[i] = dis2[i];
    65. Dij();
    66. }
    67. for (int i = 1; i <= n; i ++) cout << dis[i] << " ";
    68. cout << endl;
    69. return 0;
    70. }

     然后就是这几天1700分的CF题目:

     

  • 相关阅读:
    ARCGIS网络分析
    Path-Ranking:KBQA中path生成、召回、粗排与精排
    飞天使-mysql8.0远程连接允许
    gentool gen go自动生成表结构
    每日练习------生成13位条形, Ean-13码规则:第十三位数字是前十二位数字经过计算得到的校验码。
    在RK3588开发板使用FFMpeg 结合云服务器加SRS实现摄像头数据推流到云端拱其他设备查看
    Redis面试题(2022)
    Python is not set from command line or npm configuration 报错解决
    京东面试:MQ 消息丢失、重复、积压问题,如何解决?
    SpringCloud FeignClient的坑(httpClient连接池的使用)
  • 原文地址:https://blog.csdn.net/YSJ_1224/article/details/126532886