mirror of
https://gitcode.com/Zengtudor/alg2025.git
synced 2025-09-05 17:50:36 +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>
|
#include <vector>
|
||||||
using namespace std;
|
#include <algorithm>
|
||||||
|
|
||||||
class Solution {
|
int main() {
|
||||||
public:
|
// 降序序列
|
||||||
vector<int> findDiagonalOrder(const vector<vector<int>>& m) {
|
std::vector<int> nums = {9, 7, 5, 3, 1};
|
||||||
int x=0,y=0;
|
int x = 4;
|
||||||
bool isup=true;
|
|
||||||
vector<int> res;
|
// 使用upper_bound查找第一个比x大的元素
|
||||||
res.reserve(m.size());
|
// 第三个参数是目标值x
|
||||||
#define isout (x<0||x>m.size()||y<0||y>m[0].size())
|
// 第四个参数是自定义比较函数,保持降序的比较逻辑
|
||||||
do{
|
auto it = std::upper_bound(nums.begin(), nums.end(), x, std::greater<int>());
|
||||||
res.push_back(m[x][y]);
|
|
||||||
if(isup){
|
if (it != nums.end()) {
|
||||||
if(x==0){
|
std::cout << "第一个比" << x << "大的数是: " << *it << std::endl;
|
||||||
++y;
|
} else {
|
||||||
isup=false;
|
std::cout << "没有比" << x << "大的数" << std::endl;
|
||||||
}else{
|
|
||||||
--x;
|
|
||||||
++y;
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
if(y==0){
|
|
||||||
++x;
|
|
||||||
isup=true;
|
|
||||||
}else{
|
|
||||||
++x;
|
|
||||||
--y;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}while(!(x==m.size()&&y==m[0].size()));
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
return 0;
|
||||||
int main(){
|
|
||||||
|
|
||||||
Solution s;
|
|
||||||
s.findDiagonalOrder({{1,2,3},{4,5,6},{7,8,9}});
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user