Heisenberg_

zzu

1.2万

Heisenberg_
2个月前
class Solution {
public:
int fib(int n) {
int a = 0 , b = 1, c;
for(int i = 1; i <= n;i++)
{
c = a + b;
b = a;
a = c;

}
return a;
}

};


Heisenberg_
2个月前

Heisenberg_
2个月前
acwing推动了整个计算机相关就业升学的内卷啊 如果acwing某天真的家喻户晓人人注册刷题。。可能必须要进阶课滚瓜烂熟 + codeforces每次div1都补题才能卷过别人了= =

Heisenberg_
3个月前
//method 1
class Solution {
public:

int findPairs(vector<int>& nums, int k) {
int res = 0;
sort(nums.begin(),nums.end());
int n = nums.size();

for(int i = 0, j = 0; i < n;i++)
{
while(i > 0 && i < n - 1 && nums[i + 1] == nums[i]) i++;

while(j < i && nums[i] - nums[j] > k) j++;
if(j < i && nums[i] - nums[j] == k) res++;
}
return res;
}
};\
//method 2

class Solution {
public:
unordered_map<int,int> less;
unordered_map<int,int> greater;
int findPairs(vector<int>& nums, int k) {
int n = nums.size();
int res = 0;
for(int i = 0; i < n;i++)
{
if(less.count(nums[i] - k))
{
if(!greater.count(nums[i])) greater[nums[i]]++;
}
if(less.count(nums[i] + k))
{
if(!greater.count(nums[i] + k)) greater[nums[i]+k]++;
}
if(!less.count(nums[i])) less[nums[i]]++;

}

res = greater.size();

return res;
}
};


Heisenberg_
4个月前
#include<bits/stdc++.h>

using namespace std;

const int N = 110;
int n,k;
int g[N][N];
bool st[N][N];

int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k;
int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};
int a = 0, b = 0, m = 0;
for(int i = 0; i < n * k; i++ )
{
g[a][b] = i + 1;
st[a][b] = true;
int ta = a, tb = b;
a = a + dx[m], b = b + dy[m];
if(a < 0 || a > n - 1 || b < 0 || b >  k - 1 || st[a][b])
{

m = (m + 1) % 4;
a = ta + dx[m], b = tb + dy[m];
}

}

for(int i = 0; i < n;i++)
{

for(int j = 0; j < k;j++)
{

cout << g[i][j] << " " ;
}

cout <<  endl;
}

return 0;
}


Heisenberg_
6个月前

#### 排序算法的稳定性

Swap的时候有可能让两个本来相等的元素交换位置 破坏了原序列的稳定性

Heisenberg_
6个月前
#include<bits/stdc++.h>

using namespace std;
int n;
vector<int> chosen;
void calc(int x)
{

if(x == n + 1)
{
for(int i = 0; i < chosen.size();i++) cout << chosen[i] << ' ';
cout << endl;
return;
}
calc(x+1); // not choose

chosen.push_back(x);
calc(x+1);
chosen.pop_back();
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);

cin >> n;
calc(1);

return 0;
}


Heisenberg_
6个月前
#include<bits/stdc++.h>

using namespace std;

const int N = 1000010;
int q[N],a[N];

int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n,k;
cin >> n >> k;
for(int i = 0; i < n; i++) cin >> a[i];
int hh = 0, tt = -1;
for(int i = 0; i < n;i++)
{
if(hh <= tt && q[hh] < i - k + 1) hh++;
while(hh <= tt && a[q[tt]] >= a[i]) tt--;
q[++ tt] = i;
if(i >= k - 1) cout << a[q[hh]] << ' ';

}
cout << endl;
hh = 0, tt = -1;
for(int i = 0; i < n;i++)
{
if(hh <= tt && q[hh] < i - k + 1) hh++;
while(hh <= tt && a[q[tt]] <= a[i]) tt--;
q[++ tt] = i;
if(i >= k - 1) cout << a[q[hh]] << ' ';

}

return 0;
}


Heisenberg_
6个月前
#include<bits/stdc++.h>

using namespace std;

const int N = 1000010;
int q[N],a[N];

int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n,k;
cin >> n >> k;
for(int i = 0; i < n; i++) cin >> a[i];
int hh = 0, tt = -1;
for(int i = 0; i < n;i++)
{
if(hh <= tt && q[hh] < i - k + 1) hh++;
while(hh <= tt && a[q[tt]] >= a[i]) tt--;
q[++ tt] = i;
if(i >= k - 1) cout << a[q[hh]] << ' ';

}
cout << endl;
hh = 0, tt = -1;
for(int i = 0; i < n;i++)
{
if(hh <= tt && q[hh] < i - k + 1) hh++;
while(hh <= tt && a[q[tt]] <= a[i]) tt--;
q[++ tt] = i;
if(i >= k - 1) cout << a[q[hh]] << ' ';

}

return 0;
}


Heisenberg_
6个月前
#include<bits/stdc++.h>

using namespace std;
const int N = 100010;
int stk[N],tt;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n; cin >> n;
for(int i = 1; i <= n;i++)
{
int x;
cin >> x;
while(tt && stk[tt] >= x) tt--;
if(tt) cout << stk[tt] << ' ';
else cout << "-1" << ' ';
stk[++tt] = x;
}
return 0;
}