Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <iostream>
#include <vector>
#include <bits/stdc++.h>
#define il inline
using namespace std;
Expand Down
56 changes: 28 additions & 28 deletions leetcode/Study Plan/21/21_递归.py
Original file line number Diff line number Diff line change
@@ -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
107 changes: 54 additions & 53 deletions niuke/daily_problem/25_10-21铁盘整理/others/ida.cpp
Original file line number Diff line number Diff line change
@@ -1,54 +1,55 @@
#include <bits/stdc++.h>
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() {
map<int, int>mp;
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<<res;
#include <iostream>
#include <bits/stdc++.h>
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() {
map<int, int>mp;
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<<res;
}
3 changes: 3 additions & 0 deletions niuke/daily_problem/26-3-4多米诺骨牌/1.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#include <algorithm>
#include <iostream>
#include <vector>
/*
* @Author: tkzzzzzz6
* @Date: 2026-03-04 16:52:07
Expand Down
2 changes: 2 additions & 0 deletions niuke/daily_problem/26_01-31特殊的科学计数法/1.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <string>
#include <iostream>
/*
* @Author: tkzzzzzz6
* @Date: 2026-01-31 19:46:23
Expand Down
Loading