This commit is contained in:
Zengtudor 2024-11-25 22:52:31 +08:00
parent 8f81302029
commit 87cd0ebf71
6 changed files with 178 additions and 13 deletions

View File

@ -0,0 +1,8 @@
#include <cstdint>
using ll = int64_t;
ll dp[100][ll(1e5)];
int main(){
return **dp;
}

16
src/11/25/U144142.cpp Normal file
View File

@ -0,0 +1,16 @@
#include <cstdint>
#include <iostream>
using namespace std;
using ll = int64_t;
const ll maxn{ll(5e4+5)};
ll n,c[maxn];
int main(){
ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
cin>>n;
for(ll i{1};i<=n;i++){
cin>>c[i];
}
}

View File

@ -1,90 +1,138 @@
#include <bits/stdc++.h> #include <bits/stdc++.h>
using namespace std; using namespace std;
const int MAXN = 40005;
const int MAXM = 100005; // 定义常量
const int MAXN = 40005; // 节点数量上限
const int MAXM = 100005; // 边数量上限 (每条无向边拆分为两有向边)
const long long INF = 1e18; const long long INF = 1e18;
// 边的结构体
struct Edge { struct Edge {
int to; int to; // 目标节点
int weight; int weight; // 边权重
int next; int next; // 下一条边的索引
} edges[MAXM * 2]; } edges[MAXM * 2];
// 头指针数组
int head_arr[MAXN]; int head_arr[MAXN];
int edge_cnt = 0; int edge_cnt = 0;
// 添加一条有向边
void add_edge(int u, int v, int w){ void add_edge(int u, int v, int w){
edges[edge_cnt].to = v; edges[edge_cnt].to = v;
edges[edge_cnt].weight = w; edges[edge_cnt].weight = w;
edges[edge_cnt].next = head_arr[u]; edges[edge_cnt].next = head_arr[u];
head_arr[u] = edge_cnt++; head_arr[u] = edge_cnt++;
} }
// Dijkstra 函数,返回从 start 到 node1 的最短距离,排除 blocked_edge1 和 blocked_edge2
long long dijkstra(int start, int node1, int blocked_edge1, int blocked_edge2, int n){ long long dijkstra(int start, int node1, int blocked_edge1, int blocked_edge2, int n){
// 使用距离数组和版本号来避免每次都清零
static long long dist_arr[MAXN]; static long long dist_arr[MAXN];
static int visited_version[MAXN]; // static int visited_version[MAXN];
static int current_version = 0; // static int current_version = 0;
current_version++; // current_version++;
// 初始化距离
for(int i = 1; i <= n; ++i){ for(int i = 1; i <= n; ++i){
dist_arr[i] = INF; dist_arr[i] = INF;
} }
dist_arr[start] = 0; dist_arr[start] = 0;
// 优先队列 (距离, 节点)
priority_queue<pair<long long, int>, vector<pair<long long, int>>, std::greater<pair<long long, int>>> pq; priority_queue<pair<long long, int>, vector<pair<long long, int>>, std::greater<pair<long long, int>>> pq;
pq.emplace(0, start); pq.emplace(0, start);
while(!pq.empty()){ while(!pq.empty()){
auto [current_dist, u] = pq.top(); auto [current_dist, u] = pq.top();
pq.pop(); pq.pop();
if(u == node1){ if(u == node1){
return current_dist; return current_dist;
} }
if(current_dist > dist_arr[u]){ if(current_dist > dist_arr[u]){
continue; continue;
} }
// 遍历所有出边
for(int e = head_arr[u]; e != -1; e = edges[e].next){ for(int e = head_arr[u]; e != -1; e = edges[e].next){
// 如果这条边被阻断,则跳过
if(e == blocked_edge1 || e == blocked_edge2){ if(e == blocked_edge1 || e == blocked_edge2){
continue; continue;
} }
int v = edges[e].to; int v = edges[e].to;
long long w = edges[e].weight; long long w = edges[e].weight;
if(dist_arr[v] > dist_arr[u] + w){ if(dist_arr[v] > dist_arr[u] + w){
dist_arr[v] = dist_arr[u] + w; dist_arr[v] = dist_arr[u] + w;
pq.emplace(dist_arr[v], v); pq.emplace(dist_arr[v], v);
} }
} }
} }
return INF; return INF;
} }
int main(){ int main(){
ios::sync_with_stdio(false); ios::sync_with_stdio(false);
cin.tie(0); cin.tie(0);
// 初始化头指针数组
memset(head_arr, -1, sizeof(head_arr)); memset(head_arr, -1, sizeof(head_arr));
int n, m; int n, m;
cin >> n >> m; cin >> n >> m;
// 存储节点1的所有连接边
// 每个元素是 pair<有向边的索引,(v, w1)>
vector<pair<int, pair<int, int>>> node1_edges; vector<pair<int, pair<int, int>>> node1_edges;
for(int i = 0; i < m; ++i){ for(int i = 0; i < m; ++i){
int u, v, w1, w2; int u, v, w1, w2;
cin >> u >> v >> w1 >> w2; cin >> u >> v >> w1 >> w2;
add_edge(u, v, w1);
add_edge(v, u, w2); // 添加两条有向边
add_edge(u, v, w1); // 边编号: edge_cnt -1
add_edge(v, u, w2); // 边编号: edge_cnt -1
// 如果 u 是1记录这条边
if(u == 1){ if(u == 1){
node1_edges.emplace_back(edge_cnt -2, make_pair(v, w1)); node1_edges.emplace_back(edge_cnt -2, make_pair(v, w1));
} }
// 如果 v 是1记录这条边
if(v == 1){ if(v == 1){
node1_edges.emplace_back(edge_cnt -2, make_pair(u, w2)); node1_edges.emplace_back(edge_cnt -2, make_pair(u, w2));
} }
} }
long long answer = INF; long long answer = INF;
// 遍历节点1的所有出边
for(auto &[edge_idx, vp] : node1_edges){ for(auto &[edge_idx, vp] : node1_edges){
int v = vp.first; int v = vp.first;
int w1 = vp.second; int w1 = vp.second;
// 阻断这条无向边的两个有向边
// 由于添加边时,边 idx 是偶数,后面的边是对应的另一方向
int blocked_edge1 = edge_idx; int blocked_edge1 = edge_idx;
int blocked_edge2 = edge_idx + 1; int blocked_edge2 = edge_idx + 1;
// 运行 Dijkstra 从 v 到 node1排除 blocked_edge1 和 blocked_edge2
long long path_dist = dijkstra(v, 1, blocked_edge1, blocked_edge2, n); long long path_dist = dijkstra(v, 1, blocked_edge1, blocked_edge2, n);
if(path_dist != INF){ if(path_dist != INF){
answer = min(answer, (long long)w1 + path_dist); answer = min(answer, (long long)w1 + path_dist);
} }
} }
if(answer == INF){ if(answer == INF){
cout << "-1\n"; cout << "-1\n";
} }
else{ else{
cout << answer << "\n"; cout << answer << "\n";
} }
return 0; return 0;
} }

View File

@ -26,7 +26,7 @@ ostream&operator<<(ostream&os,pair<T,P>const&m){
} }
ll const maxn{ll(1e5+5)}; ll const maxn{ll(2e5+5)};
ll t,n,m,inf{ll(1)<<60}; ll t,n,m,inf{ll(1)<<60};
ll q[maxn],qs{}; ll q[maxn],qs{};
pair<ll, ll>e[maxn]; pair<ll, ll>e[maxn];

28
src/11/c1/fib.cpp Normal file
View File

@ -0,0 +1,28 @@
#include <cstdint>
#include <iostream>
using namespace std;
using ll = int64_t;
const ll maxn{ll(1e6+5)};
// ll n,fn,f1,f2;
ll n,f[maxn];
ll dfs(ll const& now){
if(f[now])return f[now];
if(now==1||now==2){
return 1;
}
f[now]=dfs(now-1)+dfs(now-2);
return f[now];
}
int main(){
cin>>n;
// f1=1,f2=1;
// for(ll i{3};i<=n;i++){
// fn=f1+f2;
// swap(fn,f2);
// swap(fn,f1);
// }
cout<<dfs(n)<<'\n';
}

View File

@ -1,6 +1,71 @@
#include <array>
#include <cstdint>
#include <iostream> #include <iostream>
#include <random>
#include <stdexcept>
#include <string>
#include <type_traits>
#include <utility>
#include <variant>
using namespace std; using namespace std;
using ll = int64_t;
template<class T,class P>
ostream&operator<<(ostream&os,pair<T,P>const&p){
os<<"( "<<p.first<<", "<<p.second<<" )";
return os;
}
variant<ll,string> test(){
random_device v;
mt19937 mt(v());
uniform_int_distribution<short> un(0,50);
ll number{un(mt)};
if(!number){
return "Zengtudor";
}
return number;
}
template<class... Ts> struct overloaded : Ts... { using Ts::operator()...; };
template<class... Ts> overloaded(Ts...) -> overloaded<Ts...>;
template<class T,class ...Args>
struct Array{
static constexpr ll size(){return sizeof...(Args)+1;}
decay_t<T> arr[size()];
Array(T const&t, Args const&...args){
arr[0]=t;
ll idx{1};
((arr[idx++]=args),...);
}
friend ostream&operator<<(ostream&os,Array const&arr){
os<<"[ ";
for(ll i{0};i<size();i++){
os<<arr.arr[i]<<" ,";
}
cout<<" ]";
return os;
}
};
// template<class T,class ...Args>
// Array(T,Args...)->Array<T,Args...>;
int main(){ int main(){
cout<<"Hello World!\n"; array<int,2> a{};
for(auto const& i:a)cout<<i<<" ";
cout<<'\n';
Array arr {1,2,3};
cout<<arr<<'\n';
// cout<<sizeof(test())<<'\n';
// ll n{100};
// // cin>>n;
// while(n--){
// cout<<visit(overloaded{
// [](string const&str){cout<<"is str\n";throw runtime_error("throwing error");return 1;},
// [](ll const& n){cout<<"is number\n";return 2;}
// },test())<<"\n";
// }
} }