mirror of
https://gitcode.com/Zengtudor/alg2025.git
synced 2025-09-04 01:01:43 +00:00
update
This commit is contained in:
parent
d9a9164d21
commit
a8ea175f77
59
src/8/24/P1020.cpp
Normal file
59
src/8/24/P1020.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
using ll = int64_t;
|
||||
|
||||
int main(){
|
||||
std::ios::sync_with_stdio(false);
|
||||
std::cin.tie(nullptr);
|
||||
std::vector<ll> v;
|
||||
v.reserve(100000);
|
||||
ll tmp;
|
||||
while (std::cin >> tmp) {
|
||||
v.push_back(tmp);
|
||||
}
|
||||
if (v.empty()) {
|
||||
std::cout << "0\n0\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::vector<ll> f(v.size() + 1, 0);
|
||||
f[1] = v[0];
|
||||
ll maxdp = 1;
|
||||
|
||||
for (ll i = 1; i < v.size(); i++) {
|
||||
ll h = v[i];
|
||||
ll l = 1, r = maxdp, ans = 0;
|
||||
while (l <= r) {
|
||||
ll mid = (l + r) >> 1;
|
||||
if (f[mid] >= h) {
|
||||
ans = mid;
|
||||
l = mid + 1;
|
||||
} else {
|
||||
r = mid - 1;
|
||||
}
|
||||
}
|
||||
if (ans == 0) {
|
||||
f[1] = std::max(f[1], h);
|
||||
} else {
|
||||
ll nxt = ans + 1;
|
||||
if (nxt > maxdp) {
|
||||
maxdp = nxt;
|
||||
f[nxt] = h;
|
||||
} else {
|
||||
f[nxt] = std::max(f[nxt], h);
|
||||
}
|
||||
}
|
||||
}
|
||||
std::cout << maxdp << '\n';
|
||||
std::vector<ll> sys;
|
||||
sys.reserve(v.size());
|
||||
for (ll h : v) {
|
||||
auto it = std::lower_bound(sys.begin(), sys.end(), h);
|
||||
if (it == sys.end()) sys.push_back(h);
|
||||
else *it = h;
|
||||
}
|
||||
std::cout << sys.size() << '\n';
|
||||
return 0;
|
||||
}
|
54
src/test.cpp
54
src/test.cpp
@ -1,40 +1,22 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
#include <algorithm>
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
vector<int> findDiagonalOrder(const vector<vector<int>>& m) {
|
||||
int x=0,y=0;
|
||||
bool isup=true;
|
||||
vector<int> res;
|
||||
res.reserve(m.size());
|
||||
#define isout (x<0||x>m.size()||y<0||y>m[0].size())
|
||||
do{
|
||||
res.push_back(m[x][y]);
|
||||
if(isup){
|
||||
if(x==0){
|
||||
++y;
|
||||
isup=false;
|
||||
}else{
|
||||
--x;
|
||||
++y;
|
||||
}
|
||||
}else{
|
||||
if(y==0){
|
||||
++x;
|
||||
isup=true;
|
||||
}else{
|
||||
++x;
|
||||
--y;
|
||||
}
|
||||
}
|
||||
}while(!(x==m.size()&&y==m[0].size()));
|
||||
return res;
|
||||
int main() {
|
||||
// 降序序列
|
||||
std::vector<int> nums = {9, 7, 5, 3, 1};
|
||||
int x = 4;
|
||||
|
||||
// 使用upper_bound查找第一个比x大的元素
|
||||
// 第三个参数是目标值x
|
||||
// 第四个参数是自定义比较函数,保持降序的比较逻辑
|
||||
auto it = std::upper_bound(nums.begin(), nums.end(), x, std::greater<int>());
|
||||
|
||||
if (it != nums.end()) {
|
||||
std::cout << "第一个比" << x << "大的数是: " << *it << std::endl;
|
||||
} else {
|
||||
std::cout << "没有比" << x << "大的数" << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
Solution s;
|
||||
s.findDiagonalOrder({{1,2,3},{4,5,6},{7,8,9}});
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user