当前位置:网站首页 > 区块链基础 > 正文

单双向链表原理(单向和双向链表)



#include <bits/stdc++.h>  using namespace std; using LL = long long;  int k, n; int x; signed main() {   // freopen("in", "r", stdin);   // freopen("out", "w", stdout);   while (~scanf("%d%d", &k, &n)) {     int cur = 0, cnt = 0;     int ok = 0;     for (int i = 1; i <= n; i++) {       scanf("%d", &x);       if (ok) continue;       if (cur + x == k) {         if(n != i) ok = 1;         cur += x;       } else if (cur + x > k) {         cnt++;         cur = k - (cur + x - k);       } else {         cur += x;       }     }     if (ok || k == 0) {       printf("paradox ");     } else {       printf("%d %d ", k - cur, cnt);     }   }   return 0; }
#include <bits/stdc++.h> using namespace std; using LL = long long; #define A 1 #define B 2 #define C 3 #define D 4 #define E 5 #define F 6 const int maxn = 1010; int n; int dice[maxn][7]; int pre[maxn]; int find(int x) {   return x == pre[x] ? x : pre[x] = find(pre[x]); } void unite(int x, int y) {   x = find(x); y = find(y);   pre[x] = y; } int check(int x, int y) {   if (dice[x][1]==dice[y][A]&&dice[x][2]==dice[y][B]&&dice[x][3]==dice[y][C]&&dice[x][4]==dice[y][D]&&dice[x][5]==dice[y][E]&&dice[x][6]==dice[y][F]) return 1;   if (dice[x][1]==dice[y][C]&&dice[x][2]==dice[y][D]&&dice[x][3]==dice[y][B]&&dice[x][4]==dice[y][A]&&dice[x][5]==dice[y][E]&&dice[x][6]==dice[y][F]) return 1;   if (dice[x][1]==dice[y][B]&&dice[x][2]==dice[y][A]&&dice[x][3]==dice[y][D]&&dice[x][4]==dice[y][C]&&dice[x][5]==dice[y][E]&&dice[x][6]==dice[y][F]) return 1;   if (dice[x][1]==dice[y][D]&&dice[x][2]==dice[y][C]&&dice[x][3]==dice[y][A]&&dice[x][4]==dice[y][B]&&dice[x][5]==dice[y][E]&&dice[x][6]==dice[y][F]) return 1;   if (dice[x][1]==dice[y][A]&&dice[x][2]==dice[y][B]&&dice[x][3]==dice[y][D]&&dice[x][4]==dice[y][C]&&dice[x][5]==dice[y][F]&&dice[x][6]==dice[y][E]) return 1;   if (dice[x][1]==dice[y][C]&&dice[x][2]==dice[y][D]&&dice[x][3]==dice[y][A]&&dice[x][4]==dice[y][B]&&dice[x][5]==dice[y][F]&&dice[x][6]==dice[y][E]) return 1;   if (dice[x][1]==dice[y][B]&&dice[x][2]==dice[y][A]&&dice[x][3]==dice[y][C]&&dice[x][4]==dice[y][D]&&dice[x][5]==dice[y][F]&&dice[x][6]==dice[y][E]) return 1;   if (dice[x][1]==dice[y][D]&&dice[x][2]==dice[y][C]&&dice[x][3]==dice[y][B]&&dice[x][4]==dice[y][A]&&dice[x][5]==dice[y][F]&&dice[x][6]==dice[y][E]) return 1;   if (dice[x][1]==dice[y][A]&&dice[x][2]==dice[y][B]&&dice[x][3]==dice[y][F]&&dice[x][4]==dice[y][E]&&dice[x][5]==dice[y][C]&&dice[x][6]==dice[y][D]) return 1;   if (dice[x][1]==dice[y][F]&&dice[x][2]==dice[y][E]&&dice[x][3]==dice[y][B]&&dice[x][4]==dice[y][A]&&dice[x][5]==dice[y][C]&&dice[x][6]==dice[y][D]) return 1;   if (dice[x][1]==dice[y][B]&&dice[x][2]==dice[y][A]&&dice[x][3]==dice[y][E]&&dice[x][4]==dice[y][F]&&dice[x][5]==dice[y][C]&&dice[x][6]==dice[y][D]) return 1;   if (dice[x][1]==dice[y][E]&&dice[x][2]==dice[y][F]&&dice[x][3]==dice[y][A]&&dice[x][4]==dice[y][B]&&dice[x][5]==dice[y][C]&&dice[x][6]==dice[y][D]) return 1;   if (dice[x][1]==dice[y][A]&&dice[x][2]==dice[y][B]&&dice[x][3]==dice[y][E]&&dice[x][4]==dice[y][F]&&dice[x][5]==dice[y][D]&&dice[x][6]==dice[y][C]) return 1;   if (dice[x][1]==dice[y][E]&&dice[x][2]==dice[y][F]&&dice[x][3]==dice[y][B]&&dice[x][4]==dice[y][A]&&dice[x][5]==dice[y][D]&&dice[x][6]==dice[y][C]) return 1;   if (dice[x][1]==dice[y][B]&&dice[x][2]==dice[y][A]&&dice[x][3]==dice[y][F]&&dice[x][4]==dice[y][E]&&dice[x][5]==dice[y][D]&&dice[x][6]==dice[y][C]) return 1;   if (dice[x][1]==dice[y][F]&&dice[x][2]==dice[y][E]&&dice[x][3]==dice[y][A]&&dice[x][4]==dice[y][B]&&dice[x][5]==dice[y][D]&&dice[x][6]==dice[y][C]) return 1;   if (dice[x][1]==dice[y][F]&&dice[x][2]==dice[y][E]&&dice[x][3]==dice[y][C]&&dice[x][4]==dice[y][D]&&dice[x][5]==dice[y][A]&&dice[x][6]==dice[y][B]) return 1;   if (dice[x][1]==dice[y][C]&&dice[x][2]==dice[y][D]&&dice[x][3]==dice[y][E]&&dice[x][4]==dice[y][F]&&dice[x][5]==dice[y][A]&&dice[x][6]==dice[y][B]) return 1;   if (dice[x][1]==dice[y][E]&&dice[x][2]==dice[y][F]&&dice[x][3]==dice[y][D]&&dice[x][4]==dice[y][C]&&dice[x][5]==dice[y][A]&&dice[x][6]==dice[y][B]) return 1;   if (dice[x][1]==dice[y][D]&&dice[x][2]==dice[y][C]&&dice[x][3]==dice[y][F]&&dice[x][4]==dice[y][E]&&dice[x][5]==dice[y][A]&&dice[x][6]==dice[y][B]) return 1;   if (dice[x][1]==dice[y][E]&&dice[x][2]==dice[y][F]&&dice[x][3]==dice[y][C]&&dice[x][4]==dice[y][D]&&dice[x][5]==dice[y][B]&&dice[x][6]==dice[y][A]) return 1;   if (dice[x][1]==dice[y][D]&&dice[x][2]==dice[y][C]&&dice[x][3]==dice[y][E]&&dice[x][4]==dice[y][F]&&dice[x][5]==dice[y][B]&&dice[x][6]==dice[y][A]) return 1;   if (dice[x][1]==dice[y][F]&&dice[x][2]==dice[y][E]&&dice[x][3]==dice[y][D]&&dice[x][4]==dice[y][C]&&dice[x][5]==dice[y][B]&&dice[x][6]==dice[y][A]) return 1;   if (dice[x][1]==dice[y][C]&&dice[x][2]==dice[y][D]&&dice[x][3]==dice[y][F]&&dice[x][4]==dice[y][E]&&dice[x][5]==dice[y][B]&&dice[x][6]==dice[y][A]) return 1;   return 0; } signed main() {   // freopen("in", "r", stdin);   // freopen("out", "w", stdout);   while (~scanf("%d", &n)) {     for (int i = 1; i <= n; i++) {       pre[i] = i;     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= 6; j++) {         scanf("%d", &dice[i][j]);       }     }     for (int i = 1; i <= n; i++) {       for (int j = i + 1; j <= n; j++) {         if (check(i, j)) unite(i, j);       }     }     int ret1 = 0;     for (int i = 1; i <= n; i++) {       if (i == find(i)) ret1++;     }     printf("%d ", ret1);     map<int, int> vis;     for (int i = 1; i <= n; i++) {       vis[find(i)]++;     }     vector<int> ret2;     for (const auto &x : vis) {       ret2.emplace_back(x.second);     }     sort(ret2.begin(), ret2.end(), greater<int>());     for (int i = 0; i < ret2.size(); i++) {       printf("%d%c", ret2[i], "  "[i == ret2.size() - 1]);     }   }   return 0; } 贴一下枚举的图吧。。

#include <bits/stdc++.h> using namespace std; using LL = long long; using pii = pair<int, int>; const int maxn = ; int n, m, t; pii lunch[maxn], dinner[maxn]; int suf[maxn]; signed main() {   // freopen("in", "r", stdin);   // freopen("out", "w", stdout);   while (~scanf("%d%d%d",&n,&m,&t)) {     for (int i = 1; i <= n; i++) {       scanf("%d%d",&lunch[i].second, &lunch[i].first);     }     for (int i = 1; i <= m; i++) {       scanf("%d%d",&dinner[i].second, &dinner[i].first);     }     if (t == 0) {       printf("0 ");       continue;     }     sort(lunch + 1, lunch + n + 1);     sort(dinner + 1, dinner + m + 1);     int ret = INT_MAX;     for (int i = 1; i <= n; i++) {       if (lunch[i].first >= t) ret = min(ret, lunch[i].second);     }     for (int i = 1; i <= m; i++) {       if (dinner[i].first >= t) ret = min(ret, dinner[i].second);       suf[i] = dinner[i].second;     }     for (int i = m - 1; i >= 1; i--) {       suf[i] = min(suf[i + 1], suf[i]);     }     for (int i = 1; i <= n; i++) {       if (lunch[i].first >= t) continue;       int require = t - lunch[i].first;       if (dinner[m].first < require) continue;       int lo = 1, hi = m;       while (lo <= hi) {         int mid = (lo + hi) >> 1;         if (dinner[mid].first >= require) {           ret = min(ret, suf[mid] + lunch[i].second);           hi = mid - 1;         } else {           lo = mid + 1;         }       }     }     printf("%d ", ret == INT_MAX ? -1 : ret);   }   return 0; }
#include <bits/stdc++.h> using namespace std; using LL = long long; using pii = pair<int, int>; const LL mod = 1E9 + 9; const int dx[5] = {0, 0, 1, -1}; const int dy[5] = {1, -1, 0, 0}; const int maxn = 7; char s[maxn][maxn]; vector<pii> pos; int n = 6, m = 6; LL ret; vector<vector<int>> status; vector<int> tmp; void pre(int cnt, int cap) {   if (cnt == min((int)pos.size() + 1, 7)) {     status.emplace_back(tmp);     return;   }   for (int i = 1; i <= 6; i++) {     // if (i == cap) continue;     tmp.emplace_back(i);     pre(cnt + 1, i);     tmp.pop_back();   } } int check(int x, int y) {   return x >= 1 && x <= 6 && y >= 1 && y <= 6; } int ok() {   for (int i = 1; i <= 6; i++) {     for (int j = 1; j <= 6; j++) {       for (int k = 0; k < 4; k++) {         int x = i + dx[k];         int y = j + dy[k];         if (!check(x, y)) continue;         if (s[i][j] == '*') continue;         if (s[x][y] == s[i][j]) return 0;       }     }   }   return 1; }  signed main() {   // freopen("in", "r", stdin);   // freopen("out", "w", stdout);   pos.clear();   for (int i = 1; i <= 6; i++) {     scanf("%s", s[i] + 1);     for (int j = 1; j <= 6; j++) {       if (s[i][j] == '#') pos.emplace_back(i, j);     }   }   tmp.clear();   status.clear();   pre(1, -1);   for (int i = 0; i < status.size(); i++) {     for (int j = 0; j < pos.size(); j++) {       int x = pos[j].first, y = pos[j].second;       s[x][y] = status[i][j] + '0';     }     if (ok()) {       ret++;       if (ret >= mod) ret %= mod;     }     for (int j = 0; j < pos.size(); j++) {       int x = pos[j].first, y = pos[j].second;       s[x][y] = '#';     }   }   printf("%lld ", ret);   return 0; } 没得100分,确定不来啃啃[阿里云-超全算法笔试模拟题精解合集]? [阿里云-超全算法笔试模拟题精解合集]--70+算法题、30种大厂笔试高频知识

到此这篇单双向链表原理(单向和双向链表)的文章就 介绍到这了,更多相关内容请继续浏览下面的相关 推荐文章,希望大家都能在编程的领域有一番成就!

版权声明


相关文章:

  • 单向链表的特点是什么(单向链表的优点)2025-09-23 21:09:04
  • 跳转链接怎么弄成文件(跳转链接怎么弄成文件夹)2025-09-23 21:09:04
  • 对于有头指针和尾指针的单向链表是什么(头指针为head的带头结点的单向循环链表)2025-09-23 21:09:04
  • 腾讯文档怎么跳转链接页面(腾讯文档怎么设置链接)2025-09-23 21:09:04
  • 链接跳转工具(跳转链接制作)2025-09-23 21:09:04
  • 如何设置返回目录超链接(怎么设置返回的超链接)2025-09-23 21:09:04
  • 二维码跳转链接制作(二维码转跳网页)2025-09-23 21:09:04
  • b站怎么弄视频链接(b站视频链接怎么用)2025-09-23 21:09:04
  • 对于有头指针和尾指针的单向链表(对于有头指针和尾指针的单向链表是什么)2025-09-23 21:09:04
  • b站怎么弄视频链接(b站怎么在视频上放链接)2025-09-23 21:09:04
  • 全屏图片