diff --git "a/blue_braige/\347\254\25432\345\234\272\350\223\235\346\241\245\302\267\347\256\227\346\263\225\345\205\245\351\227\250\350\265\233\302\267\347\231\276\346\240\241\350\201\224\350\265\233/2.cpp" "b/blue_braige/\347\254\25432\345\234\272\350\223\235\346\241\245\302\267\347\256\227\346\263\225\345\205\245\351\227\250\350\265\233\302\267\347\231\276\346\240\241\350\201\224\350\265\233/2.cpp" index 416f30e4..efd298e5 100644 --- "a/blue_braige/\347\254\25432\345\234\272\350\223\235\346\241\245\302\267\347\256\227\346\263\225\345\205\245\351\227\250\350\265\233\302\267\347\231\276\346\240\241\350\201\224\350\265\233/2.cpp" +++ "b/blue_braige/\347\254\25432\345\234\272\350\223\235\346\241\245\302\267\347\256\227\346\263\225\345\205\245\351\227\250\350\265\233\302\267\347\231\276\346\240\241\350\201\224\350\265\233/2.cpp" @@ -1,3 +1,5 @@ +#include +#include #include #define il inline using namespace std; diff --git "a/leetcode/Study Plan/21/21_\351\200\222\345\275\222.py" "b/leetcode/Study Plan/21/21_\351\200\222\345\275\222.py" index d9acf7c6..ed96c290 100644 --- "a/leetcode/Study Plan/21/21_\351\200\222\345\275\222.py" +++ "b/leetcode/Study Plan/21/21_\351\200\222\345\275\222.py" @@ -1,29 +1,29 @@ -from typing import Optional - -# 定义链表节点类 -class ListNode: - def __init__(self, val=0, next=None): - self.val = val # 节点的值 - self.next = next # 指向下一个节点的指针 - -# 定义解决方案类 -class Solution: - # 合并两个有序链表的函数 - def mergeTwoLists(self, l1: Optional[ListNode], l2: Optional[ListNode]) -> Optional[ListNode]: - # 如果l1为空,直接返回l2 - if l1 is None: - return l2 - # 如果l2为空,直接返回l1 - elif l2 is None: - return l1 - # 如果l1的值小于l2的值 - elif l1.val < l2.val: - # 递归合并l1的下一个节点和l2,并将结果赋值给l1的下一个节点 - l1.next = self.mergeTwoLists(l1.next, l2) - # 返回l1作为合并后的链表的头节点 - return l1 - else: - # 递归合并l1和l2的下一个节点,并将结果赋值给l2的下一个节点 - l2.next = self.mergeTwoLists(l1, l2.next) - # 返回l2作为合并后的链表的头节点 +from typing import Optional + +# 定义链表节点类 +class ListNode: + def __init__(self, val=0, next=None): + self.val = val # 节点的值 + self.next = next # 指向下一个节点的指针 + +# 定义解决方案类 +class Solution: + # 合并两个有序链表的函数 + def mergeTwoLists(self, l1: Optional[ListNode], l2: Optional[ListNode]) -> Optional[ListNode]: + # 如果l1为空,直接返回l2 + if l1 is None: + return l2 + # 如果l2为空,直接返回l1 + elif l2 is None: + return l1 + # 如果l1的值小于l2的值 + elif l1.val < l2.val: + # 递归合并l1的下一个节点和l2,并将结果赋值给l1的下一个节点 + l1.next = self.mergeTwoLists(l1.next, l2) + # 返回l1作为合并后的链表的头节点 + return l1 + else: + # 递归合并l1和l2的下一个节点,并将结果赋值给l2的下一个节点 + l2.next = self.mergeTwoLists(l1, l2.next) + # 返回l2作为合并后的链表的头节点 return l2 \ No newline at end of file diff --git "a/niuke/daily_problem/25_10-21\351\223\201\347\233\230\346\225\264\347\220\206/others/ida.cpp" "b/niuke/daily_problem/25_10-21\351\223\201\347\233\230\346\225\264\347\220\206/others/ida.cpp" index 54a58c1b..7fc7000b 100644 --- "a/niuke/daily_problem/25_10-21\351\223\201\347\233\230\346\225\264\347\220\206/others/ida.cpp" +++ "b/niuke/daily_problem/25_10-21\351\223\201\347\233\230\346\225\264\347\220\206/others/ida.cpp" @@ -1,54 +1,55 @@ -#include -using namespace std; - -int a[1010]; - -int n; -int res; -int check() { - int cnt = 0, i; - for (i = 2; i <= n + 1; i++) { - if (abs(a[i] - a[i - 1]) != 1)cnt++; - } - return cnt; -} -int mi; -int dep; -void dfs(int p, int cnt) { - int i, j; - // if(check()+cnt>dep||res)return; - if (check() + cnt >= mi) { - return; - } - if (check() == 0) { - // res=dep; - mi = min(mi, cnt); - return; - } - for (j = 2; j <= n; j++) { - if (j == p || abs(a[j] - a[j + 1]) == 1)continue; - for (i = 1; i <= j / 2; i++) { - swap(a[i], a[j - i + 1]); - } - dfs(j, cnt + 1); - for (i = 1; i <= j / 2; i++) { - swap(a[i], a[j - i + 1]); - } - } - -} -int main() { - mapmp; - int j = 1, i; - cin >> n; - for (i = 1; i <= n; i++)cin >> a[i], mp[a[i]] = 1; - for (auto i : mp)mp[i.first] = j++; - for (i = 1; i <= n; i++)a[i] = mp[a[i]]; - a[n + 1] = n + 1; - mi = 2 * n; - dep = check(); - dfs(0, 0); - // while(!res)dfs(0,0),dep++; - cout << mi; - // cout< +#include +using namespace std; + +int a[1010]; + +int n; +int res; +int check() { + int cnt = 0, i; + for (i = 2; i <= n + 1; i++) { + if (abs(a[i] - a[i - 1]) != 1)cnt++; + } + return cnt; +} +int mi; +int dep; +void dfs(int p, int cnt) { + int i, j; + // if(check()+cnt>dep||res)return; + if (check() + cnt >= mi) { + return; + } + if (check() == 0) { + // res=dep; + mi = min(mi, cnt); + return; + } + for (j = 2; j <= n; j++) { + if (j == p || abs(a[j] - a[j + 1]) == 1)continue; + for (i = 1; i <= j / 2; i++) { + swap(a[i], a[j - i + 1]); + } + dfs(j, cnt + 1); + for (i = 1; i <= j / 2; i++) { + swap(a[i], a[j - i + 1]); + } + } + +} +int main() { + mapmp; + int j = 1, i; + cin >> n; + for (i = 1; i <= n; i++)cin >> a[i], mp[a[i]] = 1; + for (auto i : mp)mp[i.first] = j++; + for (i = 1; i <= n; i++)a[i] = mp[a[i]]; + a[n + 1] = n + 1; + mi = 2 * n; + dep = check(); + dfs(0, 0); + // while(!res)dfs(0,0),dep++; + cout << mi; + // cout< +#include +#include /* * @Author: tkzzzzzz6 * @Date: 2026-03-04 16:52:07 diff --git "a/niuke/daily_problem/26_01-31\347\211\271\346\256\212\347\232\204\347\247\221\345\255\246\350\256\241\346\225\260\346\263\225/1.cpp" "b/niuke/daily_problem/26_01-31\347\211\271\346\256\212\347\232\204\347\247\221\345\255\246\350\256\241\346\225\260\346\263\225/1.cpp" index 00869a16..6c2257d4 100644 --- "a/niuke/daily_problem/26_01-31\347\211\271\346\256\212\347\232\204\347\247\221\345\255\246\350\256\241\346\225\260\346\263\225/1.cpp" +++ "b/niuke/daily_problem/26_01-31\347\211\271\346\256\212\347\232\204\347\247\221\345\255\246\350\256\241\346\225\260\346\263\225/1.cpp" @@ -1,3 +1,5 @@ +#include +#include /* * @Author: tkzzzzzz6 * @Date: 2026-01-31 19:46:23