题意异常的简单.就是给定一个邻接矩阵,让你判定是否为树.算法1:O(n^3).思路就是找到树边,原理是LCA.判断树边的数目是否为n-1.39-th个数据T了,自己测试2000跑到4s.算法2:O(n^2).思考由图如何得到树,显然MST是可行的.因此,题目变为直接找到MST.然后通过树边构建目标矩阵.判定矩阵是否相等. /* 472D */ #include <iostream> #include <string> #include <map> #include &l…
http://codeforces.com/contest/472/problem/D D. Design Tutorial: Inverse the Problem time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There is an easy way to obtain a new task from an old on…
D. Design Tutorial: Inverse the Problem time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There is an easy way to obtain a new task from an old one called "Inverse the problem": we give…
Codeforce 472D Design Tutorial: Inverse the Problem 解析含快速解法(MST.LCA.思維) 今天我們來看看CF472D 題目連結 題目 給你一個\(n\times n\)的矩陣代表點\(i\)到點\(j\)的最短距離.問是否可以造出一棵邊權為正的樹. 前言 這題的輸入,輸入3e6個Integer經過實測就大概需要700ms以上了(如果沒開輸入優化好像還會直接TLE的樣子).並且我一開始是用Prim's Algo去寫MST的,priority_q…
题意:给定一个矩阵,表示每两个节点之间的权值距离,问是否可以对应生成一棵树, 使得这棵树中的任意两点之间的距离和矩阵中的对应两点的距离相等! 思路:我们将给定的矩阵看成是一个图,a 到 b会有多条路径, 如果存在一棵树,那么 这个树中a->b的距离一定是这个图中所有a->b中路径长度最短的一条!所以我们根据边权, 建立一棵MST树!再将MST树中的任意两点之间的距离求出来,看是否和矩阵中的对应的节点 对距离相同! #include<iostream> #include<cst…
题意:给出一个距离矩阵,问是不是一颗正确的带权树. 解法:先按找距离矩阵建一颗最小生成树,因为给出的距离都是最短的点间距离,然后再对每个点跑dfs得出应该的dis[][],再对比dis和原来的mp是否一致即可. 首先还要判断一些东西.具体看代码吧. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #in…
Codeforces Round #270 D:http://codeforces.com/contest/472/problem/D 题意:给以一张图,用邻接矩阵表示,现在问你这张图能不能够是一棵树?(并且边权都是正的) 题解:看了题解才知道.如果这张图是一棵树的话,那么最小生成树一定满足条件.所以可以这样解,求一颗生成树,然后在生成树每个点DFS,求出任意两点之间的距离,看看这两点之间距离在原来的矩阵中,是否一致,如果都是一致的,则说明是可以的,否则就不行. #include<iostrea…
转自:http://mrfufufu.github.io/android/2015/07/01/Codelab_Android_Design_Support_Library.html [翻]Android Design Support Library 的 代码实验——几行代码,让你的 APP 变得花俏 Jul 1, 2015 译者地址:[翻]Android Design Support Library 的 代码实验——几行代码,让你的 APP 变得花俏 原文:Codelab for Androi…
题目链接: http://acm.fzu.edu.cn/problem.php?pid=2238 题目大意: 已知等差数列A(0)的首项a和公差d,求出数列A(0)前n项和,得到新数列A(1);以此类推,最终求A(m)的第i项mod1000000007 题目思路: [动态规划] 不难推出c[i][j]=c[i-1][j]+c[i][j-1] 但是i太大不能直接递推,m<=1000不能矩阵快速幂. 通过推导可以求出c[i][j]=a*C(n+m-1,n-1)+d*C(n+m-1,n-2) 求模时除…
题目描述: Design a simplified version of Twitter where users can post tweets, follow/unfollow another user and is able to see the 10 most recent tweets in the user's news feed. Your design should support the following methods: postTweet(userId, tweetId):…