cf472D Design Tutorial: Inverse the Problem】的更多相关文章

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…
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…
Codeforces Round #270 D:http://codeforces.com/contest/472/problem/D 题意:给以一张图,用邻接矩阵表示,现在问你这张图能不能够是一棵树?(并且边权都是正的) 题解:看了题解才知道.如果这张图是一棵树的话,那么最小生成树一定满足条件.所以可以这样解,求一颗生成树,然后在生成树每个点DFS,求出任意两点之间的距离,看看这两点之间距离在原来的矩阵中,是否一致,如果都是一致的,则说明是可以的,否则就不行. #include<iostrea…
题意:给定一个矩阵,表示每两个节点之间的权值距离,问是否可以对应生成一棵树, 使得这棵树中的任意两点之间的距离和矩阵中的对应两点的距离相等! 思路:我们将给定的矩阵看成是一个图,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…
题意异常的简单.就是给定一个邻接矩阵,让你判定是否为树.算法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…
C. Design Tutorial: Make It Nondeterministic time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A way to make a new task is to make it nondeterministic or probabilistic. For example, the hard…
B. Design Tutorial: Learn from Life 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 life. You can choose some experience in real life, formalize it…
A. 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 some random math statement or modify som…
Design Tutorial: Learn from Life 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 life. You can choose some experience in real life, formalize it an…
Qsys 设计流程 ---Qsys System Design Tutorial 1.Avalon-MM Pipeline Bridge Avalon-MM Pipeline Bridge在slave端口接受命令,然后在master端口发送命令.可以把Pipeline Bridge理解为集线器,可以缩减FPGA的管脚. 2.首先搭建一个数据产生系统 csr是处理器用来控制和设置状态寄存器的接口. 3.搭建数据检查系统 4.搭建分层级系统 5.建立顶层系 6.如果不使用Nios II proces…
Codeforces Round #270 B:http://codeforces.com/contest/472/problem/B 题意:n个人在1楼,想要做电梯上楼,只有1个电梯,每次只能运k个人,每移动一层需要1秒.问最小的是时间把所有人送到想去的楼层. 题解:贪心,每次选择楼层数最大k个人,用优先队列维护一下即可. #include<iostream> #include<cstdio> #include<cstring> #include<algorit…
题目链接:http://www.codeforces.com/problemset/problem/472/A题意:给你一个数n,将n表示为两个合数(即非素数)的和.C++代码: #include <iostream> using namespace std; bool isprime(int x) { ; i * i <= x; i ++) ) return false; return true; } int main() { int n; cin >> n; ;i <…
Problem description One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that. For example, there is a statement called the "Goldbach's conj…
题意:有一个电梯,每一个人都想乘电梯到达自己想要到达的楼层!从a层到b层的时间是|a-b|, 乘客上下电梯的时间忽略不计!问最少需要多少的时间....     这是一道神题啊,自己的思路不知不觉的就按照注解的思路走了,想着用优先队列模拟一下,可能还是没有模拟好吧,一直哇!但是同学的优先队列模拟过了! 没想到是greedy算法简单的几行就解决了! #include<iostream> #include<cmath> #include<cstdio> #include<…
题意:将一个数拆成两个合数的和, 输出这两个数!(这道题做的真是TMD水啊)开始的时候不知道composite numbers是啥意思,看了3遍才看懂.... 看懂之后又想用素数筛选法来做,后来决定单个判断一个数是否为素数的方法来写,结果写错了两次,快疯掉了简直.... #include<iostream> #include<cmath> #include<cstdio> #include<algorithm> #include<cmath> #…
题意:每一个人 都有frist name 和 last name! 从每一个人的名字中任意选择 first name 或者 last name 作为这个人的编号!通过对编号的排序,得到每一个人 最终顺序!比较中的序列能否得到给定输出的序列一致! #include<iostream> #include<cstring> #include<cstdio> #include<string> #include<map> #include<algor…
题 题意:给你一个大于等于12的数,要你用两个合数表示出来.//合数指自然数中除了能被1和本身整除外,还能被其他的数整除(不包括0)的数. 分析:我们知道偶数除了2都是合数,给你一个偶数,你减去一个偶数得到的就是偶数啦,因为n>=12,所以减去4的话,得到的是>=8的偶数,肯定也是合数,当然你也可以减去6.8,大于8就不行了. 然后给你奇数呢?你减去一个奇数就得到偶数啦,减去一个是合数的奇数,最小的就是9,奇数时:n>=13,n-9>=4 #include<stdio.h&g…
Codeforces Round #270:C;http://codeforces.com/contest/472 题意:水题 题解:贪心即可. #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> using namespace std; ; int n; ]; ]; int a[N]; int main(){ scanf("%d",&…
题目大意 给出两个\(01\)序列\(A\)和\(B\) 汉明距离定义为两个长度相同的序列中,有多少个对应位置上的数字不一样 \(00111\) 和 \(10101\)的距离为\(2\) \(Q\)次询问,每次询问给出\(p_1,p_2,len\) 求\(a_{p_1},a_{p_1+1}\ldots a_{p_1+len−1}\)和\(b_{p_1},b_{p_1+1}\ldots b_{p_1+len−1}\)两个子串的汉明距离 \(n\leq 2\times{10}^5,q\leq 4\t…
题目链接 \(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\). \(Solution\) 考虑异或的两个基本性质: 异或是可逆的,逆运算就是它本身. 可以交换…
Description 给出两个01序列\(A\)和\(B\) 要求回答\(q\)个询问每次询问\(A\)和\(B\)中两个长度为\(len\)的子串的哈明距离 ​ 哈明距离的值即有多少个位置不相等 ​ \(1 \le |A|,|B| \le 2*10^5\) ​ \(1 \le q \le 4*10^5\) ​ 保证输入合法,序列下标从0开始 Solution ​ 大暴力分块,记录一下思想 ​ 题解做法比较繁琐 ​ 先求出每一个位置开始长度为32的序列状态,压进一个unsigned int ​…
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 some random math statement or modify some theorems to get something new and…
题目大意 给出两个\(01\)序列\(A\)和\(B\) 哈明距离定义为两个长度相同的序列中,有多少个对应位置上的数字不一样 "00111" 和 "10101"的距离为2 \(Q\)次询问,每次询问给出\(p_1,p_2,len\) 求\(a{p_1},a{p_1+1}...a_{p_1+len-1}\) 和 \(b_{p_1},b_{p_1+1}...b_{p_1+len-1}\)两个子串的哈明距离 注意:本题中的序列是从\(0\)开始编号的:\(a_0,a_1,…
题意: N个点.N行N列d[i][j]. d[i][j]:结点i到结点j的距离. 问这N个点是否可能是一棵树.是输出YES,否则输出NO. 思路: 假设这个完全图是由一棵树得来的,则我们对这个完全图求最小生成树,得到原树.(画个图就明白) 故我们对完全图求最小生成树,然后用DFS从这棵树上的每个点出发,判断距离是否和矩阵d相同. 注意: 用vector存与每个点相连树枝的另一端,否则超时.用了vector也耗了1400多秒,限时2s. 代码: #include <cstdio> #includ…
Codeforces Round #270 A - Design Tutorial: Learn from Math 题意:给出n,求出两个合数x和y使x+y=n. 题解:暴力筛合数,然后暴力找 //#pragma comment(linker, "/STACK:102400000,102400000") #include<cstdio> #include<cmath> #include<iostream> #include<cstring&g…
Codeforces Round #270 A. 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 some random math s…
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…
Design Tutorial: Inverse the Problem CodeForces - 472D 给你了一个 n × n最短距离矩阵.(即矩阵中dis[u][v]为u点到v点的最短距离),判断是否存在一个边权皆为正整数的树,恰好满足这个最短距离矩阵 . Input 第一行为一个整数 n (1 ≤ n ≤ 2000) — 表示图中有多少个点. 下面 n 行,每行包括 n 个整数 di, j (0 ≤ di, j ≤ 109) — 点i和点j之间的最短距离. Output 如果存在这样的…