This commit is contained in:
Zengtudor 2024-11-13 09:41:14 +08:00
parent 690b11e039
commit ac18784798
2 changed files with 145 additions and 1 deletions

View File

@ -1,4 +1,5 @@
#include <algorithm>
#include <array>
#include <cstdint>
#include <iostream>
#include <ranges>
@ -27,9 +28,47 @@ func print(Args...args){
}
const i64 max_n = 100000 + 5, mod{998244353};
i64 w[max_n], a[max_n];
i64 w[max_n], a[max_n], dfs_in[max_n], dfs_out[max_n];
std::vector<i64> sons[max_n];
template<i64 size>
class Segtree{
private:
std::array<i64, size*4> nodes{};
std::array<i64, size*4> lazy_mul;
void build(const i64 (&arr)[], const i64 l, const i64 r, const i64 n){
if(l==r){
nodes[n]=arr[l];
return;
}
const i64 mid {(l+r)/2};
build(arr, l, mid, n*2);
build(arr, mid+1, r, n*2+1);
nodes[n] = nodes[n*2] + nodes[n*2+1];
}
void update_mul(const i64 ul, const i64 ur, const i64 l, const i64 r,const i64 n){
if(lazy_mul[n]!=1){
// nodes[]
}
if(r < ul || ur < l){
return;
}
}
public:
Segtree(const i64 (&arr)[], const i64 n){
build(arr, 1, n, 1);
std::fill(lazy_mul.begin(), lazy_mul.end(), 1);
}
};
//testing
Segtree<50> st(a,2);
i64 mod_pow(i64 b, i64 e, const i64 m = mod){
b %= mod;
i64 res {1};

105
src/20241113/T538693.cpp Normal file
View File

@ -0,0 +1,105 @@
#include <algorithm>
#include <array>
#include <cstdint>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <istream>
#include <queue>
#include <ranges>
#include <stdexcept>
#include <type_traits>
#include <utility>
#include <vector>
using int64 = std::int64_t;
template<class ...Args>
void input(Args&&...args){
(std::cin>>...>>std::forward<Args>(args));
}
template<class T>
std::remove_cv_t<T> input(){
std::remove_cv_t<T> t;
std::cin>>t;
return t;
}
template<class ...Args>
void print(Args&&...args){
(std::cout<<...<<args);
}
struct Point{
int64 x, y;
bool operator<(const Point &that)const{
return (this->x + this->y) < (that.x + that.y);
}
bool operator==(const Point &that)const{
return this->x == that.x && this->y == that.y;
}
};
using Vector2 = Point;
using Status = std::pair<Vector2, Point>;
const int64 max_n = 100 + 5;
int64 _map[max_n][max_n];
const int64 (&map)[max_n][max_n] = _map;
const std::array<std::array<int64, 2>, 4> dir{{
{0, 1},
{1, 0},
{-1, 0},
{0, -1}
}};
int main(){
std::iostream::sync_with_stdio(false), std::cin.tie(nullptr), std::cout.tie(nullptr);
std::cout<<std::fixed<<std::setprecision(3);
const int64 n = input<decltype(n)>(), m = input<decltype(m)>();
const auto inputPoint = []()->Point{
Point ret;
input(ret.x, ret.y);
return ret;
};
const Point start = inputPoint(), end = inputPoint();
std::ranges::for_each(std::ranges::views::iota(1, n+1), [&](const auto &i){
std::ranges::for_each(std::ranges::views::iota(1,m+1), [&](const auto &j){
input(_map[n][m]);
});
});
const double ansScore = input<double>();
std::priority_queue<Status, std::vector<Status>, std::greater<>> pq;
pq.emplace(Vector2{0, 0}, start);
const Vector2 ansVec = [&]()->Vector2{
while(!pq.empty()){
const auto top = pq.top();
pq.pop();
if(top.second == end){
return top.first;
}
for (const auto i : dir) {
const Point nextPoint = {top.second.x + i[0], top.second.y + i[1]};
if(map[nextPoint.x][nextPoint.y] == 1 || nextPoint.x < 1 || nextPoint.x > n || nextPoint.y < 1 || nextPoint.y > m){
continue;
}
pq.emplace(Vector2{.x = top.first.x + std::abs(i[0]), .y = top.first.y + std::abs(i[1])}, nextPoint);
}
}
throw std::runtime_error("unreachable");
}();
const double udTimes = ansScore - (double)ansVec.x;
print(udTimes/ansVec.y);
}