CodeForces 472 D ,E,F (MST,构造,线性代数)(待补)

RTX 50系显卡实战3DGS:从源码编译到避坑指南 本文详细介绍了在RTX 50系显卡上成功运行3D Gaussian Splatting(3DGS)的完整实战指南。针对新显卡架构与旧版预编译包不兼容的核心问题,文章提供了从源码编译CUDA扩展的清晰步骤,包括环境配置、依赖安装、核心模块diff-gaussian-rasterization和simple-knn的编译避坑方法,并涵盖了数据准备、模型训练与实时预览的全流程,帮助开发者高效利用新硬件进行3D重建。 阅读详情

官方题解:http://codeforces.com/blog/entry/14028
E题:http://codeforces.com/contest/472/problem/E
F题:http://codeforces.com/contest/472/problem/F

There is an easy way to obtain a new task from an old one called “Inverse the problem”: we give an output of the original task, and ask to generate an input, such that solution to the original problem will produce the output we provided. The hard task of Topcoder Open 2014 Round 2C, InverseRMQ, is a good example.

Now let’s create a task this way. We will use the task: you are given a tree, please calculate the distance between any pair of its nodes. Yes, it is very easy, but the inverse version is a bit harder: you are given an n × n distance matrix. Determine if it is the distance matrix of a weighted tree (all weights must be positive integers).

Input
The first line contains an integer n (1 ≤ n ≤ 2000) — the number of nodes in that graph.

Then next n lines each contains n integers di, j (0 ≤ di, j ≤ 109) — the distance between node i and node j.

Output
If there exists such a tree, output “YES”, otherwise output “NO”.

Example
Input
3
0 2 7
2 0 9
7 9 0
Output
YES
Input
3
1 2 7
2 0 9
7 9 0
Output
NO
Input
3
0 2 2
7 0 9
7 9 0
Output
NO
Input
3
0 1 1
1 0 1
1 1 0
Output
NO
Input
2
0 0
0 0
Output
NO
Note
In the first example, the required tree exists. It has one edge between nodes 1 and 2 with weight 2, another edge between nodes 1 and 3 with weight 7.

In the second example, it is impossible because d1, 1 should be 0, but it is 1.

In the third example, it is impossible because d1, 2 should equal d2, 1.

大致题意:
告诉你一棵树有n个节点,然后以矩阵的形式告诉你每两个节点间的距离,问是否能构成一最小生成树。

思路:首先,我们可以排除掉一些错误答案,比如arr[i][i]!=0,arr[i][j]!=arr[j][i],arr[i][j]=0(i!=j)这几种我们可以直接输出NO。否则我们每次选择最短边然后构建一颗最小生成树,然后计算一遍两两节点之间的距离,如果和输入的矩阵不同怎输出NO。
节点间的距离我们可以先用LCA(最近公共祖先)的算法计算出i,j的最近公共祖先
那么dist[i][j] = dist[root][i] + dist[root][j] - 2 * dist[root][LCA[i][j]]

。

#include<iostream>
#include<algorithm>
#include<string>
#include<cstdio>
#include<cstring>
#include<queue>
#include<vector>
#include<cstring>
#include<cmath>
#define LL long long  
#define ULL unsigned long long  
using namespace std;
LL gcd(LL a,LL b)
{
    if(b==0)return a;
    else return gcd(b,a%b);
}
LL lcm(LL a,LL b)
{
    return a/gcd(a,b)*b;
}
const int N=2005;
struct Edge{
    int  from ,to,v;
    Edge(int a,int b,int c):from(a),to(b),v(c) {}
    bool operator <(const Edge &e) const {
        return v<e.v;
    }
};
int n;
vector<Edge> edges;
vector<Edge> tree[N];
int arr[N][N];
int pre[N];
int father[N];
int vis[N];
int lca[N][N];
int dp[N];
int find(int x)
{
   int r=x;
   while (pre[r]!=r)
   r=pre[r];
   int i=x; int j;
   while(i!=r)
   {
       j=pre[i];
       pre[i]=r;
       i=j;
   }
   return r;
}
void join(Edge e)
{
    if(find(e.from)!=find(e.to))
    {
        pre[find(e.from)]=find(e.to);
        tree[e.from].push_back(Edge(e.from,e.to,e.v));
        tree[e.to].push_back(Edge(e.to,e.from,e.v));
    }
}
int getfather(int x)
{
    int r=x;
   while (father[r]!=r)
   r=father[r];
   int i=x; int j;
   while(i!=r)
   {
       j=father[i];
       father[i]=r;
       i=j;
   }
   return r;
}
void LCA(int x){
    vis[x]=1;
    for(int i=0;i<tree[x].size();i++){
        Edge e=tree[x][i];
        if(!vis[e.to])
        {
            LCA(e.to);
            father[e.to]=x;
         } 
    }
    for(int i=1;i<=n;i++)
    {
        if(vis[i]&&!lca[i][x])
        {
            lca[i][x]=lca[x][i]=getfather(i);
        }
    }
}
void dfs(int x,int pre)
{
    for(int i=0;i<tree[x].size();i++)
    {
        Edge e=tree[x][i];
        if(e.to==pre) continue;
        dp[e.to]=dp[x]+e.v;
        dfs(e.to,x);
     } 
}
int main()
{
    int flag=1;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        pre[i]=father[i]=i;
        for(int j=1;j<=n;j++)
        {
            scanf("%d",&arr[i][j]);
            if ((i == j && arr[i][j]) || (i != j && !arr[i][j]) || (i > j && arr[i][j] != arr[j][i])) {  
                flag=0;
            }
            if(i<j)
            edges.push_back(Edge(i,j,arr[i][j]));
        }
    }
    if(flag==0)
    {
        printf("NO\n");
        return 0;
    }
    sort(edges.begin(),edges.end());
    for(int i=0;i<edges.size();i++)
    {
        join(edges[i]);
    }
    LCA(1);
    dfs(1,0);
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++){
            int dist=dp[i]+dp[j]-dp[lca[i][j]]*2;
            if(dist!=arr[i][j]){
                printf("NO\n");
                return 0;

            }       
        }
    }
    printf("YES\n");
    return 0; 
}

472D - Design Tutorial: Inverse the Problem

Let’s think it in the following way: for the minimal length edge, it must belong the the tree, …, for the k-th minimal length edge(a, b), if there is already an path between a-b, then it can not be an edge of tree anymore, otherwise it must be edge of tree, why? Because otherwise there must be a path from a to b in the tree, that means a and b can be connected by edges with less length, but a and b is not connected.

So this Kruskal style analysis gives us this theorem: if there is an answer, then the answer must be the MST of that graph. (You can also guess this theorem and try to prove it.)

You can solve MST in O(n^2 log n), and then there are many way to check distance between notes on tree: you can just simply do dfs or bfs from each node, it can run in O(n^2). Or if you have pre-coded LCA algorithm, it can run in O(n^2 log n).

472E - Design Tutorial: Learn from a Game

First let’s solve some special cases:

If the initial board and the target board contains different orbs, then there can’t be a solution.

If n = 1 (or m = 1), then we can try all O(m^2) (or O(n^2)) possible moves.

And for the other cases, there always have solution. We first hold the orb with number target[1][1] in initial board. Then we want to move other orbs to their position.

So let’s come up with a process to move orb from (a, b) to (c, d): it must be some continue path from (a, b) to (c, d), so we want to build a single move: it will move an orb from (a, b) to an adjacent cell (c, d). How to do that? We can move our touching orb to (c, d) first, and then move to (a, b). But there are some concerns: in this move, the touching orb shouldn’t pass any already-done cells, and it shouldn’t pass (a, b) when we get to (c, d).

That means we need a good order to move orbs. We can do it in this way: first, as long as there are more than 2 rows, we move the orbs to last row (from left to right or right to left). And then it must be 2xm boards: we do it column by column from right to left. We can find that in this order, there always exist paths for our touching orb to get (c, d).

472F - Design Tutorial: Change the Goal

You need to know some knowledge about linear algebra and notice the operation of xor on 32 bit integers equals to + operation in a 32 dimension linear space. If you don’t know, you should learn it from the editorial of similar tasks, for example, Topcoder SRM 557 Div1-Hard.

We need to know some basic properties of our operation:

we can swap two number a and b by: a^=b, b^=a, a^=b.

This operation is inversible, the inverse is itself.

By property 1 we can do the Gaussian elimination of each set of vectors.

By property 2 we can use this way to build an answer: use some operation to make A[] into a base (linear independent vectors that the span will be A[]), then transfer it into a base of B[], then use the inverse of Gaussian elimination to recover B[].

So now we have two bases: {a1, a2, …, ax} and {b1, b2, …, by}. If there exists some bi such that it can’t be expressed as a linear combination of {a1, a2, …, ax}, the solution can’t exists.

Otherwise there always exists a solution: first we build b1 and put it in the first position. Suppose b1 = a2 ^ a3 ^ a8, then we swap any of them, say, a2 into position one, and then xor it with a3 and a8, then we get b1. Note that after this operation {a1, a2, …, ax} will remain a base. And we need to ensure we don’t erase already-done numbers in a.

j

禁止使用服务器 IP 访问 Apache 环境下的 Web 站点 通过在 Apache 的配置文件中添加适当的指令,我们可以轻松地禁止使用服务器 IP 地址访问我们的 Web 站点。在 Apache 环境下,有时我们希望禁止用户使用服务器的 IP 地址直接访问我们的 Web 站点,而只允许使用域名进行访问。现在,当用户尝试使用服务器的 IP 地址来访问你的网站时,他们将会被拒绝访问,只有通过域名才能正常访问。为了实现这个目标,我们可以通过 Apache 的配置文件进行相应的设置。表示禁止对根目录的访问权限,即禁止使用服务器的 IP 地址进行访问。 阅读详情

相关推荐

海波龙(Oracle Hyperion)单点登陆问题记录

Oracle海波龙套件已经多年未更新,按Oracle官方文档实施单点登陆启用之后,SmartView工具通过专用链接方式无法登陆系统。 在抓包逆向分析之后 定位到HspSmartViewServlet类在执行以下代码时获得的ssotoken无效导致,在某大厂工作的时候曾通过在filter中截获请求的方式植入Attribute,保留账号密码并在单点程序中处理实现登陆。 但在完美世界的环境中...

cainiaoEzu的专栏 1970

Codeforces.472F.Design Tutorial: Change the Goal(构造 线性基 高斯消元)

题目链接 \(Description\) 给定两个长为\(n\)的数组\(x_i,y_i\)。每次你可以选定\(i,j\),令\(x_i=x_i\ \mathbb{xor}\ x_j\)(\(i,j\)可以相等)。要求若干次操作后使得\(x\)变成\(y\),输出方案。操作次数不能多于\(10^6\),无解输出\(-1\)。 \(n\leq10^4,\ 0\leq x_i,y_i\leq10^9...

weixin_30616969的博客 200

【移动APP测试】Firebase Test Lab (FTL) 实战指南:从零搭建自动化测试流水线

本文详细介绍了Firebase Test Lab (FTL) 在移动APP测试中的实战应用,从零搭建自动化测试流水线。通过真实设备、虚拟设备和iOS设备的全面覆盖,FTL帮助开发者高效进行兼容性测试、性能监控和崩溃分析,显著提升应用质量。文章还提供了设备选择策略、成本控制技巧和CI/CD集成的最佳实践,助力团队优化测试流程。

weixin_29281915的博客 254

[构造 八数码] Codeforces 472E #270 E. Design Tutorial: Learn from a Game

n=1n=1或m=1m=1的时候特判 不然就是有解的 需要前置技能手玩八数码 然后就可以不断把nn和mm缩小 直到n=2,m=2n=2,m=2 这时候 因为可以斜着走 就可能有解 写起来一点不愉悦#include<cstdio> #include<cstdlib> #include<algorithm> #include<vector> #define pb push_back using

雯舞 690

全网最全医学图像数据汇总

本仓库汇总了多个领域的医学图像开源数据集,涵盖CT、MRI、超声、内窥镜、病理、多模态、PET、OCT以及皮肤镜等多种成像技术。每个数据集均详细列出了任务类型、部位、格式、数量及下载链接,旨在为医学图像研究者提供便捷的资源导航。⚠️:这些数据集仅适用于学术研究用途。

2401_83173765的博客 3319

三极管NPN与PNP的工作原理及快速识别技巧

本文深入浅出地解析了三极管NPN与PNP的核心工作原理。通过“水龙头”比喻,阐明其以小电流控制大电流的放大与开关本质。文章重点对比了NPN与PNP在电流方向、电位关系和控制逻辑上的根本区别,并提供了快速识别技巧与实用的选型、应用指南,帮助电子爱好者与工程师快速掌握这两种基础元件的关键知识。

neovim7hacker的博客 454

Codeforces Round #270 F Design Tutorial: Change the Goal 高斯消元

因为操作是可逆的而且可以随意交换,那么我们把每n个数消掉其他位保留最高位即可,然后判断一下。 #include #include #include #include #include #define mp(a,b) make_pair(a,b) using namespace std; const int maxn=10005; typedef pairp1; vectorg,g1; int a

huantwofat 433

智能座舱通信技术解析:从CAN总线到车载以太网与V2X

在汽车电子与智能网联快速融合的背景下,座舱智能化已不再是简单的屏幕堆砌,而是依赖底层通信技术构建的复杂系统。CAN总线因高可靠性与确定性传输,持续承担车身控制与安全信号的传递;车载以太网则凭借高带宽优势,成为多屏高清视频与OTA升级的核心通道;V2X车路协同技术进一步将座舱与外界的实时信息互联。理解这些技术的分工协作,是掌握智能座舱架构、开展座舱测试与故障排查的关键。本文从实际测试经验出发,梳理不同总线在座舱内部及外部的应用逻辑,结合低成本的实验台架搭建指南,展示从信号采集、网关转发到多媒体流传输的完整链路

weixin_29284657的博客 344

最小生成树(kruskal)Codeforces 472D

D. Design Tutorial: Inverse the Problem There is an easy way to obtain a new task from an old one called "Inverse the problem": we give an output of the original task, and ask to generate an in

龙崎的专栏 1130

验证 helm Chart 的正确性

验证 helm Chart 的正确性

小橙子的笔记屋 281

HTML满屏跳动的爱心(完整代码)

HTML语言实现满屏跳动爱心的完整代码。

AIGC 12万+

CodeForces - 1108 F MST Unification【MST最小生成树】

F. MST Unification time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output You are given an undirected weighted connected graph with nn v...

微微风簇浪,散作满河星 589

【系统架构设计师】论文:论虚拟现实技术的应用与发展

虚拟现实技术是当前科学研究的热点,同时也是国家大力支持发展的核心技术之一。所谓虚拟现实,就是通过计算机等虚拟手段来构造一个非常接近真实世界的虚拟环境,它主要体现在视觉、触觉、嗅觉等方面的逼真模拟来达到高度的沉浸性,也就是如我们通常所说的“身临其境”。

数据知道的博客 1万+

Codeforces 160D Edges in MST(最小生成树+tarjan)

题目链接:Edges in MST 题意:给定n(1<=n<=1e5)个点,m(n-1=<m<=min(1e5,))条边,判断每条边是否存在所有最小生成树(MST)中,或存在至少一颗中,或不存在任何最小生成树中 题解:判断是否存在最小生成树中可以将边权从小到大排序,按照正常求最小生成树的方式,从小到大枚举边,不过这里把边权相同的边放一起处理,对于每个边如果连的两个点已经在一个块中,说明这条边就一定不存在任何MST(最小生成树)中,因为在之前有更小的边已经能替代当前边,否则当前

m0_56280274的博客 629

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

codeforces 472A. Design Tutorial: Learn from Math

time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output One way to create a task is to learn from math. You can generate

jjs98 1769

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

codeForces 472D 最小生成树

题目大意:给出一个图中点的两两距离,问是否是一棵树,若是,求出平均边权最大的点 prim最小生成树,若原图是树,则最小生成树的距离就是原距离。否则不是。 搞出来树了,第二问随便dfs就好了。 #include<cstdio> #include<cstring> #include<iostream> #include&...

aida9573的博客 197

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

codeforces472D Design Tutorial: Inverse the Problem 最小生成树+dfs

题意:

AC_kereo的专栏 1094

Codeforces Round #472 A-D

A. Tritonic Iridescence题目链接:点击打开链接题意:使用CMY对字符串进行填充,要求相邻的两个不能相同,如果有两种以上可行填充方法就输出“YES”否则输出“NO”。思路:对每一个问号进行判定,最后的结果就是所有问号的可行方案数的乘积,当然可能会超出数据范围,因此只要大于2不再变大。此外, 还要判断是否有连续两个相同。AC代码:#include &lt;iostream&gt;...

LFhase‘s Blog 642

codeforces472D

Design Tutorial: Inverse the Problem CodeForces - 472D 给你了一个n × n最短距离矩阵。(即矩阵中dis[u][v]为u点到v点的最短距离),判断是否存在一个边权皆为正整数的树,恰好满足这个最短距离矩阵 。 Input 第一行为一个整数n(1 ≤ n ≤ 2000) — 表示图中有多少个点. 下面n行,每行包括...

weixin_30819085的博客 192

Codeforces 472D

看官方题解提供的是最小生成树,怎么也想不明白,you can guess and prove it! 看了好几个人的代码,感觉实现思路全都不一样,不得不佩服cf题目想法的多样性 下面说说我自己的理解,将1作为根,对于任意两点存在两种关系: 1.一个点位于另一个点的子树上。两点到1的距离之差绝对值等于两点距离。 2.两个点在某一个点的不同子树上。两点到1距离之和减去两点距离等于两倍某个点到1

无名山丘,崛起成峰 2415

CodeForces 472D Design Tutorial: Inverse the Problem (最小生成树)

题意:给出一个树中每两个节点的距离,问是否能构成一颗加权树。 思路: 以下几种情况可以直接输出NO:arr[i][i]!=0, arr[i][j] == 0(i != j), arr[i][j]!=arr[j][i]. 否则,每次选最小的边,加入生成树,最后在算一遍节点两两之间的距离,如果与输入矩阵不同则输出NO。 节点两两距离dist[i][j] = dist[root][i] + di

Shion的专栏 1047

Codeforces 947E Perpetual Subtraction (线性代数、矩阵对角化、DP)

呜啊怎么又是数学了啊。。。数学比例1633=0.4848\frac{16}{33}=0.48483316​=0.4848 题目链接: https://codeforces.com/contest/947/problem/E 题意: 有一个[0,n][0,n][0,n]的随机数xxx初始为iii的概率为pip_ipi​. mmm次操作每次从[0,x][0,x][0,x]中等概率随机选择一个数yyy把...

suncongbo's blog 798

【比赛总结】Codeforces472 Div1

前言: 第一次打Div1的比赛,本来准备睡到11:30再打,结果睡过头了。还忘了注册,赣。 慌里慌张的,题都没看明白就开始交,企图挽回失误,结果受到天罚了:B题Wa了两次,调了一个小时就因为看错题意。也直接导致了最后C题也没能调出来。果然掉回蓝名去了,爽翻(话说CF评测机停电是什么操作。。。) 不过简单题还是比较好做的(ABC),后面的还没来得及看。。现在时间紧就弃了。 A: C...

氧化钠的博客 319

codeforces736D. Permutations(线性代数)

题意 $m \leqslant 500000$,题目打错了   Sol 神仙题Orz 构造矩阵$B$,使得$B[b[i]][a[i]] = 1$ 那么他的行列式的奇偶性也就对应了生成排列数列数量的奇偶性(定义) 删除一个位置相当于去掉对答案的贡献,也就是代数余子式的值 代数余子式可以由伴随矩阵求出$A^{*} = |A| A^{-1}$ 这里只需要奇偶性,因此不需要求出实际行...

weixin_34378922的博客 309

置换群Polya定理

Polya定理通常用来解决置换群中的等价类

ZT在努力 1165

Codeforces 1095 F. Make It Connected (MST)

F. Make It Connected time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given an undirected graph consisting ofnnvertices. A number is written on each vertex; the number on verte..

OlaMins 310
上一篇: Homework of PE dp 正难则反
下一篇: BZOJ 4636: 蒟蒻的数列 分块 (未敲)
sega_handsome
博客等级 码龄10年 7粉丝 164原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值