当前位置: 首页 > news >正文

Avalonia:用 ReactiveUI 的方法绑定数据、事件和命令

Avalonia集成了ReactiveUI,使用它的方法绑定数据、事件和命令很特色,据说可以预防内存泄露的风险。
还是在基础导航的基础上,体验一下,先建ColorsViewModel。

using Avalonia.Data.Converters;
using Avalonia.Media;
using ReactiveUI.SourceGenerators;
using System;
using System.Collections.ObjectModel;
using System.Reflection;namespace ReactiveUIDemo.ViewModels
{public partial class ColorsViewModel : ViewModelBase{[Reactive]private string? _colorName;[Reactive]private Color? _color;public readonly ObservableCollection<ColorsViewModel> Colors = [];public ColorsViewModel(){}[ReactiveCommand]private void Init(){var properties = typeof(Colors).GetProperties(BindingFlags.Static | BindingFlags.Public);foreach(var property in properties){if(property.GetValue(null) is Color color){Colors.Add(new ColorsViewModel{ColorName = property.Name,Color = color});}}}public static FuncValueConverter<Color, string> ToHex { get; } = new FuncValueConverter<Color, string>(color =>$"#{color.R:X2}{color.G:X2}{color.B:X2}");public static FuncValueConverter<Color, string> ToCMYK { get; } = new FuncValueConverter<Color, string>(color =>{double r = color.R / 255.0;double g = color.G / 255.0;double b = color.B / 255.0;double k = 1 - Math.Max(Math.Max(r, g), b);double c = k < 1 ? (1 - r - k) / (1 - k) : 0;double m = k < 1 ? (1 - g - k) / (1 - k) : 0;double y = k < 1 ? (1 - b - k) / (1 - k) : 0;return $"C = {Math.Round(c * 100, 1)}% M = {Math.Round(m * 100, 1)}% Y = {Math.Round(y * 100, 1)}% K = {Math.Round(k * 100, 1)}%";});}
}

再建ColorsView自定义控件。

<rxui:ReactiveUserControl xmlns="https://github.com/avaloniaui"xmlns:rxui ="http://reactiveui.net"x:TypeArguments ="vm:ColorsViewModel"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:vm="using:ReactiveUIDemo.ViewModels"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"						  x:Class="ReactiveUIDemo.Views.ColorsView"><Grid RowDefinitions="Auto,*" x:Name="GridRoot"><TextBlock x:Name="ColorsCountTextBlock" Grid.Row="0" FontSize="16"/><ScrollViewer Grid.Row="1"><ItemsControl x:Name="ColorsItemsControl"><ItemsControl.ItemTemplate><DataTemplate DataType="vm:ColorsViewModel"><StackPanel Orientation="Horizontal" Spacing="5"><Rectangle Width="300" Height="30"><Rectangle.Fill><SolidColorBrush Color="{Binding Color}"/></Rectangle.Fill></Rectangle><TextBlock Text="{Binding ColorName}" Width="120"/><TextBlock Text="{Binding Color,Converter={x:Static vm:ColorsViewModel.ToHex}}" Width="80"/><TextBlock Text="{Binding Color,Converter={x:Static vm:ColorsViewModel.ToCMYK}}"/></StackPanel></DataTemplate></ItemsControl.ItemTemplate></ItemsControl></ScrollViewer></Grid>
</rxui:ReactiveUserControl>

注意要先引用xmlns:rxui ="http://reactiveui.net",然后引用ReactiveUI的控件,rxui:ReactiveUserControl,类型参数必须加上 x:TypeArguments ="vm:ColorsViewModel"。
在ColorsView.axaml.cs文件中绑定数据和事件,很有特色。

using Avalonia.ReactiveUI;
using ReactiveUI;
using ReactiveUIDemo.ViewModels;
using System.Reactive.Disposables;namespace ReactiveUIDemo.Views;public partial class ColorsView : ReactiveUserControl<ColorsViewModel>
{    public ColorsView(){    InitializeComponent();this.WhenActivated(disposables =>{this.OneWayBind(ViewModel, vm => vm.Colors.Count, v => v.ColorsCountTextBlock.Text, value => $"Avalonia.Media Colors {value}").DisposeWith(disposables);this.BindCommand(ViewModel, vm => vm.InitCommand, v => v.GridRoot, nameof(GridRoot.Loaded)).DisposeWith(disposables);this.OneWayBind(ViewModel, vm => vm.Colors, v => v.ColorsItemsControl.ItemsSource).DisposeWith(disposables);          });}
}

我们发现绑定命令到事件非常容易,不像Xaml平台,需要引用包或者定义附加属性。this.BindCommand(ViewModel, vm => vm.InitCommand, v => v.GridRoot, nameof(GridRoot.Loaded))这样的写法是为了有智能提示,也可以直接写事件名,this.BindCommand(ViewModel, vm => vm.InitCommand, v => v.GridRoot, “Loaded”)也是可以的。
再建AboutViewModel。

using ReactiveUI.SourceGenerators;
using System.Reflection;namespace ReactiveUIDemo.ViewModels
{public partial class AboutViewModel : ViewModelBase{[Reactive]private string? _appName;[Reactive]private string? _version;public string Message => "这是采用 Avalonia 框架的应用程序,集成 ReactiveUI,使用 ReactiveUI 方法绑定数据、事件和命令。";public AboutViewModel(){this.AppName = Assembly.GetExecutingAssembly().GetName().Name;this.Version = Assembly.GetExecutingAssembly()?.GetName()?.Version?.ToString();}}
}

在Views文件夹下新建AboutView.axaml。

<rxui:ReactiveUserControl xmlns="https://github.com/avaloniaui"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"						   xmlns:rxui="http://reactiveui.net"x:TypeArguments ="vm:AboutViewModel"xmlns:vm="using:ReactiveUIDemo.ViewModels"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"x:Class="ReactiveUIDemo.Views.AboutView"><StackPanel><StackPanel Orientation="Horizontal"><TextBlock x:Name="AppNameTextBlock" FontSize="20" FontWeight="Bold"/><TextBlock x:Name="VersionTextBlock" FontSize="18" FontStyle="Italic"/></StackPanel><TextBlock x:Name="MessageTextBlock" FontSize="16"/></StackPanel>	
</rxui:ReactiveUserControl>

AboutView.axaml.cs代码后台。

using Avalonia.ReactiveUI;
using ReactiveUI;
using ReactiveUIDemo.ViewModels;
using System.Reactive.Disposables;namespace ReactiveUIDemo.Views;public partial class AboutView : ReactiveUserControl<AboutViewModel>
{public AboutView(){InitializeComponent();this.WhenActivated(disposables =>{this.WhenAnyValue(x => x.ViewModel!.AppName).BindTo(this, v => v.AppNameTextBlock.Text).DisposeWith(disposables);this.OneWayBind(ViewModel, vm => vm.Version, v => v.VersionTextBlock.Text).DisposeWith(disposables);this.OneWayBind(ViewModel, vm => vm.Message, v => v.MessageTextBlock.Text).DisposeWith(disposables);});}
}

在MainWindowViewModel中添加逻辑代码。

using ReactiveUI;
using ReactiveUI.SourceGenerators;
using Splat;
using System.Reactive.Linq;namespace ReactiveUIDemo.ViewModels
{public partial class MainWindowViewModel : ViewModelBase{[Reactive]private ViewModelBase? _currentPage;public MainWindowViewModel(){CurrentPage = Locator.Current.GetService<ColorsViewModel>();_isColor = this.WhenAnyValue(x => x.CurrentPage).Select(page => page?.GetType() == typeof(ColorsViewModel)).ToProperty(this, x=>x.IsColorPage);_isAbout = this.WhenAnyValue(x => x.CurrentPage).Select(page => page?.GetType() == typeof(AboutViewModel)).ToProperty(this, x => x.IsAboutPage);}[ReactiveCommand]private void GotoColors(){if(CurrentPage is not ColorsViewModel){CurrentPage = Locator.Current.GetService<ColorsViewModel>();}}[ReactiveCommand]private void GotoAbout(){if(CurrentPage is not AboutViewModel){CurrentPage = Locator.Current.GetService<AboutViewModel>();}}private readonly ObservableAsPropertyHelper<bool> _isColor;public bool IsColorPage => _isColor.Value;private readonly ObservableAsPropertyHelper<bool> _isAbout;public bool IsAboutPage => _isAbout.Value;}
}

在MainWindow中设计布局。

<rxui:ReactiveWindow xmlns="https://github.com/avaloniaui"x:TypeArguments="vm:MainWindowViewModel"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:vm="using:ReactiveUIDemo.ViewModels"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:rxui="http://reactiveui.net"mc:Ignorable="d" d:DesignWidth="1084" d:DesignHeight="560"Width="1084" Height="560"x:Class="ReactiveUIDemo.Views.MainWindow"x:DataType="vm:MainWindowViewModel"Icon="/Assets/avalonia-logo.ico"Title="ReactiveUIDemo">	<Design.DataContext><!-- This only sets the DataContext for the previewer in an IDE,to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) --><vm:MainWindowViewModel/></Design.DataContext><Grid ColumnDefinitions="Auto,*"><Border Grid.Column="0" x:Name="Menu"><StackPanel x:Name="StackPanelMenu"><TextBlock Text="基  础  导  航" x:Name="Caption"/><Button x:Name="ColorsButton"><StackPanel Orientation="Horizontal" Spacing="10"><Image Source="/Assets/Images/color.png" Width="32" Height="32"/><TextBlock Text="色  彩"/></StackPanel></Button><Button x:Name="AboutButton"><StackPanel Orientation="Horizontal" Spacing="10"><Image Source="/Assets/Images/about.png" Width="32" Height="32"/><TextBlock Text="关  于"/></StackPanel></Button></StackPanel></Border><Border Grid.Column="1" x:Name="Client"><TransitioningContentControl x:Name="TransitioningContent"/></Border></Grid></rxui:ReactiveWindow>

MainWindow.axaml.cs后台代码。

using Avalonia.ReactiveUI;
using ReactiveUI;
using ReactiveUIDemo.ViewModels;
using System;
using System.Reactive.Disposables;
using System.Reactive.Linq;namespace ReactiveUIDemo.Views
{public partial class MainWindow : ReactiveWindow<MainWindowViewModel>{        public MainWindow(){InitializeComponent();this.WhenActivated(disposables => {this.OneWayBind(ViewModel, vm => vm.CurrentPage, v => v.TransitioningContent.Content).DisposeWith(disposables);this.BindCommand(ViewModel, vm => vm.GotoColorsCommand, v => v.ColorsButton).DisposeWith(disposables);this.BindCommand(ViewModel, vm => vm.GotoAboutCommand, v => v.AboutButton).DisposeWith(disposables);this.WhenAnyValue(x => x.ViewModel!.IsColorPage).Subscribe(active =>{var classes = this.ColorsButton.Classes;if (active){if (!classes.Contains("active")){classes.Add("active");}}else{classes.Remove("active");}}).DisposeWith(disposables);this.WhenAnyValue(x => x.ViewModel!.IsAboutPage).Subscribe(active =>{var classes = this.AboutButton.Classes;if (active){if (!classes.Contains("active")){classes.Add("active");}}else{classes.Remove("active");}}).DisposeWith(disposables);});}}
}

在App.axaml中设计样式

<Application xmlns="https://github.com/avaloniaui"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"x:Class="ReactiveUIDemo.App"xmlns:local="using:ReactiveUIDemo"RequestedThemeVariant="Default"><!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. --><Application.DataTemplates><local:ViewLocator/></Application.DataTemplates><Application.Resources><SolidColorBrush x:Key="PrimaryBackground">#14172D</SolidColorBrush><SolidColorBrush x:Key="PrimaryForeground">#cfcfcf</SolidColorBrush><LinearGradientBrush x:Key="PrimaryGradientBackground" StartPoint="0%,0%" EndPoint="100%,0%"><GradientStop Offset="0" Color="#111214"/><GradientStop Offset="100" Color="#151E3E"/></LinearGradientBrush><SolidColorBrush x:Key="PrimaryHoverForeground">White</SolidColorBrush><SolidColorBrush x:Key="PrimaryHoverBackground">#334455</SolidColorBrush><SolidColorBrush x:Key="PrimaryActiveBackground">#115599</SolidColorBrush></Application.Resources><Application.Styles><FluentTheme /><!--设计样式--><Style Selector="Border#Menu"><Setter Property="Background" Value="{DynamicResource PrimaryGradientBackground}"/><Setter Property="Padding" Value="10"/></Style><Style Selector="Border#Client"><Setter Property="Background" Value="{DynamicResource PrimaryBackground}"/>	<Setter Property="Padding" Value="10"/></Style><Style Selector="TextBlock"><Setter Property="Foreground" Value="{DynamicResource PrimaryForeground}"/>	<Setter Property="Margin" Value="5"/><Setter Property="VerticalAlignment" Value="Center"/> </Style>		<Style Selector="TextBlock#Caption"><Setter Property="FontSize" Value="28"/>						<Setter Property="HorizontalAlignment" Value="Center"/></Style><Style Selector="Button"><Setter Property="HorizontalAlignment" Value="Center"/><Setter Property="Margin" Value="5"/><Setter Property="Width" Value="150"/><Setter Property="HorizontalContentAlignment" Value="Center"/></Style><Style Selector="Button /template/ ContentPresenter"><Setter Property="Foreground" Value="{DynamicResource PrimaryForeground}"/><Setter Property="FontSize" Value="20"/>			<Setter Property="Padding" Value="5"/><Setter Property="Transitions"><Transitions><BrushTransition Property="Background" Duration="0:0:0.1"/></Transitions></Setter></Style><Style Selector="Button.active"><Setter Property="Background" Value="{DynamicResource PrimaryActiveBackground}"/></Style><Style Selector="Button:pointerover /template/ ContentPresenter"><Setter Property="Background" Value="{DynamicResource PrimaryHoverBackground}"/><Setter Property="Foreground" Value="{DynamicResource PrimaryHoverForeground}"/>			</Style><Style Selector="StackPanel#StackPanelMenu"><Setter Property="Width" Value="200"/></Style><Style Selector="StackPanel > Rectangle"><Setter Property="Margin" Value="5"/></Style>		</Application.Styles>
</Application>

在App.axaml.cs中使用Splat(斯普拉特)容器。

using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using ReactiveUIDemo.ViewModels;
using ReactiveUIDemo.Views;
using Splat;namespace ReactiveUIDemo
{public partial class App : Application{public override void Initialize(){AvaloniaXamlLoader.Load(this);                     }public override void OnFrameworkInitializationCompleted(){RegisterViewModel();if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop){desktop.MainWindow = new MainWindow{DataContext = new MainWindowViewModel(),};          }base.OnFrameworkInitializationCompleted(); }private void RegisterViewModel(){Locator.CurrentMutable.Register(() => new ColorsViewModel(), typeof(ColorsViewModel));Locator.CurrentMutable.Register(() => new AboutViewModel(), typeof(AboutViewModel));}}
}

运行效果。

屏幕截图 2025-09-16 234740

屏幕截图 2025-09-16 234759

相关文章:

Avalonia:用 ReactiveUI 的方法绑定数据、事件和命令

Avalonia集成了ReactiveUI,使用它的方法绑定数据、事件和命令很特色,据说可以预防内存泄露的风险。 还是在基础导航的基础上,体验一下,先建ColorsViewModel。 using Avalonia.Data.Converters; using Avalonia.Media; using ReactiveUI.SourceGenerators; using System; us…...

【pyQT 专栏】程序设置 windows 任务栏缩略图(.ico)教程

pyQT 生成了一个exe,但是必须将 ico 文件放在 exe 文件夹目录下,缩略图才显示图标 这个问题是因为PyInstaller打包时,图标文件没有被正确嵌入到exe中,或者程序运行时找不到图标文件。以下是几种解决方案: 方案1:使用资源文件系统(推荐) 1. 创建资源文件 resources.qrc&…...

Say 题选记(9.14 - 9.20)

P6619 [省选联考 2020 A/B 卷] 冰火战士 树状数组倍增板子。Code #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 2e6 + 5; #define lowbit(i) ((i) & (-(i))) int a[2][N], n, _x[N], cnt, sum[2]; void add(int a[], int x, …...

vm的配置

问题: 1.系统版本导致的虚拟机运行闪退找多篇文章无果,对照软件发现 2.软件权限不够导致地址无法更改,...

力扣72题 编辑距离

题型:动态规划,难度大 1.确定dp数组以及下标的含义 dp[i][j] 表示以下标i-1为结尾的字符串word1,和以下标j-1为结尾的字符串word2,最近编辑距离为dp[i][j]。 2.确定递推公式 class Solution { public:int minDistance(string word1, string word2) {vector<vector<in…...

数学基本结构框架

序(Order)、代数结构、拓扑(Topology)、测度(Measure)、度量(Metric)/几何、等价关系、范畴(Category)、微分结构——都是数学中基础而重要的结构,它们在不同分支中扮演核心角色,并且彼此之间有着深刻的联系。以下我将简要解释每个概念,并讨论它们如何相互关联,形…...

2025.9.16总结

历经千辛万苦,终于把hbase,zookeeper环境配好,最后产生bug的原因是。 由于配置hadoop hbase,zookeeper不是同一个视频,一个文章,一个作者,导致ip,端口号等有差异。 经过n次问ai,找文章改错,发现hbase不能在hdfs文件读写数据,才发现hbase连接hdfs的端口号应该和配置ha…...

在 Tailscale 中禁用 DNS

Tailscale 中的--accept-dns=false标志用于禁用 Tailscale 管理控制台提供的 DNS 配置。默认情况下,Tailscale 可能会将您的设备配置为使用来自 Tailnet 的 MagicDNS 或其他 DNS 设置。此标志可确保您的设备不接受或应用这些 DNS 设置。示例用法tailscale up --accept-dns=fal…...

【青少年低空飞行玩意】设计图以及项目概况

@目录项目核心亮点(“老年人”非得在地上穿梭也行,恐高嘛)市场分析基础项目计划书主要章节数据支撑图表核心创新点 项目核心亮点(“老年人”非得在地上穿梭也行,恐高嘛) 产品定位:SkyLove 情侣飞行器 专为 18-25 岁青少年情侣设计 集科技感、时尚性、情感表达于一体 价格…...

Python实现对比两个Excel表某个范围的内容并提取出差异

Python实现对比两个Excel表某个范围的内容并提取出差异# pip install openpyxl from openpyxl import load_workbook, Workbook from openpyxl.utils.cell import coordinate_from_string, column_index_from_string, get_column_letter from openpyxl.styles import Font, Pat…...

软件工程实践一:Git 使用教程(含分支与 Gitee)

目录目标一、快速上手1. Windows 安装 Git2. 初始化 / 克隆二、核心概念速览三、常用命令清单1) 查看状态与差异2) 添加与提交3) 历史与回溯4) 撤销与恢复(Git 2.23+ 推荐新命令)5) 忽略文件四、分支与合并(Branch & Merge)1) 创建与切换2) 更新主干与合并3) 推送与合并…...

我用AI给自己做了一整套专属表情包!攻略

本文分享用AI制作专属表情包的实用教程。群聊斗图,关键时刻找不到图,真的太憋屈了! 别再到处“偷”图了,最近发现用AI给自己做表情包,超简单,而且特别爽!😎1️⃣灵感和准备 一切都从一张照片开始。找一张光线好的高清正脸自拍,这是你所有表情包的“灵魂”!越清晰,A…...

20250916 之所思 - 人生如梦

20250916 之所思做的不好的地方:1. 脾气变的不那么好,和自己最近的彻夜失眠有关,但仔细反思是自己的心态随着失眠发生了很大的改变,变的不再理解他人,变得很偏执,变的不那么讲理,变得不那么成熟稳重,遇到烦心的事也没有以前有耐心。缺点太多了,多站在对方的角度看问题…...

Vue3项目开发专题精讲【左扬精讲】—— 在线教育网站系统(基于 Vue3+TypeScript+Vite 的在线教育网站系统系统设计与实现)

Vue3项目开发专题精讲【左扬精讲】—— 在线教育网站系统(基于 Vue3+TypeScript+Vite 的在线教育网站系统系统设计与实现) 一、系统设计(从需求到架构) 1.1、需求分析(明确核心目标与用户场景)1.2、系统功能设计(7个核心页面) 1.2、系统功能结构图 二、​商城网站系统运…...

20250915

20250915T1 ZZH 的游戏 二分答案之后,两个点轮流跳到当前能跳到的最小点。如果没法跳了且不都在 \(1\),那么无解。容易发现这是对的,可以通过建重构树维护。然后发现二分答案不是必要的,只需要每次没法跳的时候手动开大答案即可。复杂度瓶颈在建重构树的并查集。代码 #inc…...

Python Socket网络编程(4)

协程 微线程,切换执行 比如遇到IO等待的时候可以自动切换,提升线程利用率,多用在IO等待你想干点别的...

今日学习 dos命令和Java基础语法

今日学习 dos命令和Java基础语法 dos命令 常用快捷键ctrl+c 复制 ctrl+v粘贴 ctrl+x剪切 ctrl+z撤销 ctrl+s保存 ctrl+f查找 ctrl+shift+ESC 任务管理器(电脑死机时,可用于结束进程,explore,桌面进程) shift+delete永久删除 ALT+F4关闭窗口 ALT+TAB切换窗口/程序 win+R命令…...

课前问题列表

1.3 课前问题列表 方法相关问题static void changeStr(String x) {x = "xyz";}static void changeArr(String[] strs) {for (int i = 0; i < strs.length; i++) {strs[i] = strs[i]+""+i;}}public static void main(String[] args) { String x = &qu…...

switch中初始化变量

在 C++ 的 switch 语句中,switch 是 “跳转式” 控制结构,case 标签并非独立的语句块,若直接在 case 下初始化变量,可能导致变量作用域混乱、未初始化就被使用等问题,甚至触发编译错误。 1.跨 case 的变量作用域冲突 在某个 case 中初始化的变量,其作用域会覆盖后续 case…...

office2024免费永久激活安装包下载安装教程包含(下载安装配置激活)

大家好!最近总有人问我 Office 2024 专业增强版怎么装,今天特意整理这份超详细的 Office 2024 专业增强版下载安装教程,从电脑能不能装、在哪安全下载,到一步步安装激活,再到遇到问题怎么解决,全给大家说清楚,新手也能跟着装成功,建议收藏备用!目录一、Office 2024 专…...

vue2和vue3一时转不过来

以下是 Vue2 和 Vue3 在核心语法和功能上的主要区别,结合具体代码示例说明:一、响应式数据定义方式 1. ​​数据声明位置​​ // Vue2 选项式 API export default {data() {return {name: iwen,list: []}} }// Vue3 组合式 API import { ref, reactive } from vue export def…...

怎么查询电脑的登录记录及密码更改情况? - Li

怎么查询电脑的登录记录及密码更改情况? 写这个随笔的源头是我在一家公司上班,他们自己电脑打不开,一口咬定办公室的电脑莫名其妙打不开了,是我在被他们违规辞退后设定的密码,另将监控室电脑加密,且未告知公司任何人。 莫名其妙,因为本来就没设密码啊!(躺倒) 当然最后…...

C语言结构体中的内存对齐

C语言结构体内存对齐 在C语言编程中,结构体是一种非常重要的数据类型,它允许我们将不同类型的数据组合在一起。然而,当涉及到结构体在内存中的存储时,有一个关键的概念——内存对齐,这往往容易被忽视,但却对程序的性能和内存使用有着重要影响。 一、结构体大小计算的“理…...

该练习 DP 了!

区间DP 洛谷P3147Problem 定义 \(f[i][j]\) 存储从左端点 \(j\) 开始,能合并出 \(i\) 的右端点位置,将其设为 \(k\) 。 下面我们推转移方程。从题意可以看出,两个相邻的 \(i-1\) 能够合并出 \(i\) 。那么在 \(f[i][j]\) 后所对应的就是 \(f[i][k]\),这两个 \(i\)合并能够得…...

本周计划

周三: 上午 8:00~10:30 新领军 10:30~11:30 ZR NOIPD3 T4 下午模拟赛 晚上新领军习题课两节 周四: 上午 8:00~11:30 补好题分享 2 道 下午 2:00~4:30 补模拟赛 晚上 6:30~8:00 补模拟赛或好题分享 周五 上午 8:00~11:30 补好题分享 2 道 下午 2:00~5:30 准备下个周好题分享,…...

PPT文件太大?一招「无损」压缩图片,秒变传输小能手!

本文介绍的方法基于「PPT百科网」提供的在线分析工具,可智能评估并指导压缩过程,确保最佳效果。 PPT文件体积暴涨,99%的根源在于内部图片分辨率过高。直接使用PowerPoint自带的“压缩图片”功能虽然简单,但如同一刀切,可能导致在其他设备上播放时图片模糊,风险不可控。 「…...

9月16模拟赛

题目很难 主要是没有找对策略 就是没有及时去想部分分 怎么说呢 实力太弱 其实部分分拿完也会有个不错的成绩 无所谓 csp rp++!...

C++ 单例 Meyers Singleton(迈耶斯单例)

Meyers Singleton(迈耶斯单例)是 C++ 中实现单例模式的一种简洁高效的方法,由 C++ 专家 Scott Meyers 提出。其核心原理是利用局部静态变量的初始化特性保证单例的唯一性和线程安全性(C++11 及以后标准)。 1、核心原理局部静态变量的初始化特性 在 C++ 中,函数内的局部静…...

EF Core 与 MySQL:查询优化详解

EF Core 与 MySQL:查询优化详解 1. 使用 AsNoTracking 提高查询性能 基本用法// 常规查询(会跟踪实体变更) var products = context.Products.Where(p => p.Price > 100).ToList();// 使用 AsNoTracking(不跟踪实体变更,性能更好) var products = context.Product…...

短视频营销运营资深导师张伽赫,东莞绳木传媒创始人

东莞绳木传媒创始人张伽赫,短视频营销运营领域的资深导师。凭借其对行业趋势的敏锐洞察与实战经验,已成为企业数字化转型中短视频营销领域的标杆人物。他深耕短视频赛道多年,不仅构建了从账号定位、内容创作到流量转化的完整方法论,更通过绳木传媒为企业提供“AI+短视频”全…...

20250913

T4。T1 查询被包含的区间 将区间视为平面上的点 \((l, r)\),则每次询问的合法范围容易表示,是一个三角形。可以通过两步容斥转化为一个一维偏序和三个二维偏序。直接做就好了。代码 #include <iostream> #include <algorithm> #define lowbit(x) ((x) & (-(…...

9.13日总结

整体总结: 1.在自己的大样例出问题时要及时找老师考大样例 不要对着不对的大样例虚空调试 2.在考场上要自己造大样例 要造极限数据 这样可以防止数组越界 3.在数据不超过5e6的情况下 单log都是可以过的 只要极限数据跑的不是很慢就不用担心常数问题 4.在考场上要留一个小时以上…...

哇哇哇下雨了!——2025 . 9 . 16

哇哇哇下雨了! 感觉我从小就不喜欢晴天,反而钟爱雨天,其实每次下雨我心里就在想“哇哇哇又下雨了”。 可能跟打小的性格有关,也可能跟那个人有关。 当时我写了好多关于雨的小诗,无论是给她的还是给我自己的,内容也想不起来几句了。那会儿虽然每天的生活是无味的严苛的,但…...

奇思妙想(胡思乱想)

前言: 作为一个想象力 丰富 夸张的人,总有一些奇思怪想,浅浅记录一下呀~~ 可能会很奇怪以及不符合实际,毕竟是想象的【逃】 正文:圈养的猪会不会觉得人类的是自己的奴隶(因为一直好吃好喝的供着它们) 睡觉会不会就是脑电波以第一视角或第三视角的方式观察到平行宇宙的自…...

AI Compass前沿速览:GPT-5-Codex 、宇树科技世界模型、InfiniteTalk美团数字人、ROMA多智能体框架、混元3D 3.0

AI Compass前沿速览:GPT-5-Codex 、宇树科技世界模型、InfiniteTalk美团数字人、ROMA多智能体框架、混元3D 3.0AI Compass前沿速览:GPT-5-Codex 、宇树科技世界模型、InfiniteTalk美团数字人、ROMA多智能体框架、混元3D 3.0 AI-Compass 致力于构建最全面、最实用、最前沿的AI…...

C++中set与map的自定义排序方法详解

在C++标准模板库(STL)中,set和map是两种常用的关联容器,它们默认按照键的升序进行排序。但在实际开发中,我们经常需要根据特定需求对元素进行自定义排序。本文将详细介绍如何为set和map实现自定义排序。 默认排序行为 在深入了解自定义排序之前,我们先看一下set和map的默认…...

id

卷姬神经瓦特 2025.09.16本文来自博客园,作者:transformert,转载请注明原文链接:https://www.cnblogs.com/ac-network/p/19095883...

【汇总】Qt常用模块头文件

一、变量、命令、参数排序 项目.pro文件 模块导入 include 文件 中文说明 备注、示例ABCDEFGHIJKLM#include <QMessageBox> 信息提示窗口QMessageBox::about(this, "关于",“关于说明”);NOPQRSQT += serialport #include <QSerialPort> 串口控制类#inc…...

Advanced Algorithm —— Hashing and Sketching

Birthday Problem \(m\) 个人,\(n\) 天,没有两个人生日相同的概率为: \[\displaystyle{ \begin{align*} \Pr[\mathcal{E}]=\left(1-\frac{1}{n}\right)\cdot \left(1-\frac{2}{n}\right)\cdots \left(1-\frac{m-1}{n}\right) &= \prod_{k=1}^{m-1}\left(1-\frac{k}{n}\r…...

CF2136 Codeforces Round 1046 (Div. 2) 补题

题目标签B笛卡尔树的应用C有思维难度的 dp / 递推D交互题 利用曼哈顿距离反过来解坐标:二元线性方程组 考虑“问最值/极限情况”E二分图,边双连通分量 两条路径 -> 环 异或运算的性质 (见题解)题解:E. By the Assignment观察1:对于本题,每个边双连通分量内部的点权可…...

【IEEE出版、EI检索稳定】第四届云计算、大数据应用与软件工程国际学术会议(CBASE 2025)

第四届云计算、大数据应用与软件工程国际学术会议(CBASE 2025) 2025 4th International Conference on Cloud Computing, Big Data Application and Software Engineering 在这里看会议官网详情 2025年10月24-26日丨中国-成都(线上同步举办) 截稿日期:看官网 检索类型:IE…...

缺省源

自用,你不见得会用。 快读:点击查看代码 #define getc() getchar_unlocked() #define putc(a) putchar_unlocked(a) #define en_ putc(\n) #define e_ putc( )template<class T> inline T in() { T n = 0; char p = getc();while (p < -) p = getc();bool f = p == …...

97. 交错字符串

题目链接:97. 交错字符串 - 力扣(LeetCode)‘解析:二维dp dp[i][j]代表s1前i个和s2前j个是否能组成s3的i+j个 状态转移方程就很简单了, 但这一题要求空间限制,可以观察到dp其实只记录一维就可以,因为用到了i-1或者j-1class Solution { public:bool isInterleave(string …...

MODint(自动取模)

主要来自here,我就只是补充了点东西,修改了一点东西,改了点 re 判断。 建议和我的快读一同使用,兼容的。 in,out兼容,不过建议in(a.val),快一些。同理,建议out(a.val) 不行的话也有流输入输出的兼容。 除法是 \(O(\log mod)\) 的,嫌慢可以自行修改 inv() 函数内容。 t…...

BFD实验

动态bfd+OSPF: bfd q ospf 1 bfd all-interfaces enable net .... net .......

2025.9.16——卷1阅读程序1、2

阅读程序2 vector容量与大小 容量表示在不申请内存的情况下vector还可以添加多少元素,通常超过限制之后容量会增加>=1,具体看算法实现 大小表示vector中有多少元素 .assign(n,val) 将vector的内容替换为n个val值的元素...

25/9/15(补)

来的比较晚,把ABC题改了,随机跳了一道贪心+数学题,学习了一下题解思路。然后做了下2020csps单选,错了2道。不知道今年没有小学生s分数线会不会巨高,后面几天就练练第一轮。...

[Paper Reading] DINOv3

目录DINOv3TL;DRMethodDataArchitectureLearning ObjectiveGram Anchoring ObjectiveLeveraging Higher-Resolution Featurespost-hoc strategiesExperiment相关链接 DINOv3 link 时间:25.08 单位:Meta 相关领域:Self Supervised Learning 作者相关工作: 被引次数:7 项目主…...

25/9/16

作业比较多,来的时候就剩25分钟了,于是补了一下博客,复习了一下之前写的题。然后又研究了一下昨天的P11205(贪心+数学),稍微参悟到了一些。...

JavaDay5

增强for循环 Java增强for循环语法格式如下: for(声明语句:表达式) {//代码句子 }声明语句:声明新的局部变量,该变量的类型必须和数组元素的类型匹配。其作用域限定在环语句块,其值与此时数组元素的值相等。 表达式:表达式是要访问的数组名,或者是返回值为数组的方法 packag…...