E. Dima and Horses Dima came to the horse land. There are n horses living in the land. Each horse in the horse land has several enemies (enmity is a symmetric relationship). The horse land isn't very hostile, so the number of enemies of each horse is…
emmmm.... 在被新生暴打后,我花了很久才补出这道DFS.由于WA1检查了半天,最后竟然是输出少了一个: ,心态小崩. 这里普通的dfs算出的连通区域并不能直接当做最后的答案.所以需要类似模拟的DFS来处理. 代码如下: #include<iostream> using namespace std; int q[12][12];//用数组标记该位置是空地.食物.还是障碍. int pd[12][12];//判断有没有走过 int maxx=0;//记录最大路径长度 int a,b,m…
B. Dima and Sequence Dima got into number sequences. Now he's got sequence a1, a2, ..., an, consisting of n positive integers. Also, Dima has got a function f(x), which can be defined with the following recurrence: f(0) = 0; f(2·x) = f(x); f(2·x + 1)…
C. Dima and Staircase 线段树维护区间最大值. D. Dima and Two Sequences 由于模数不一定为质数,所以通过拆分质因数来做阶乘取模. E. Dima and Horses 假设一开始所有人都在一个党派里,如果存在不合法的点则改变点的颜色,改变后颜色后与当前颜色相同的点最多只有一个,则继续判断对应点,显然走过去后不会再走回这条边,所以时间复杂度为\(O(M)\).…
Graph Valid Tree Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), write a function to check whether these edges make up a valid tree. For example: Given n = 5 and edges = [[0, 1], [0, 2], [0, 3], [1…
C. Dima and Staircase 线段树维护区间最大值. D. Dima and Two Sequences 由于模数不一定为质数,所以通过拆分质因数来做阶乘取模. E. Dima and Horses 假设一开始所有人都在一个党派里,如果存在不合法的点则改变点的颜色,改变后颜色后与当前颜色相同的点最多只有一个,则继续判断对应点,显然走过去后不会再走回这条边,所以时间复杂度为\(O(M)\). D. Dima and Figure 根据题意,构成的连通块是凸的,考虑一行行放,如果某行的…
有些时候,我们在实际的无线网络中,会遇到无线信道一致flapping的情况,即便我们自定义了信道的,发现也会出现flapping.如果这种情况,可能需要确认是否你使用的信道上检测到了雷达. 这里记录一些关键的信息: 1.关于固定频率与跳频 固定频率一般是使用在天气雷达,5600至5650 MHz频段已分配给天气雷达. 一些军用雷达使用跳频技术. 2.IEEE 信道分配 关于更多的信息,可以参考Spectrum Sharing in the 5 GHz Band DFS Best Practice…
A tournament is a directed graph without self-loops in which every pair of vertexes is connected by exactly one directed edge. That is, for any two vertexes u and v (u ≠ v) exists either an edge going from u to v, or an edge from v to u. You are give…
You all know the Dirichlet principle, the point of which is that if n boxes have no less than n + 1 items, that leads to the existence of a box in which there are at least two items. Having heard of that principle, but having not mastered the techniq…
Pavel 喜欢网格迷宫.一个网格迷宫是一个 n × m 的长方形迷宫,其中每个单元格要么是空白的,要么是墙体.您可以从一个单元格走到另一个单元格,只要两个单元格均是空白的,且拥有一条公共的边. Pavel 绘制了一个网格迷宫,包含的全部空白单元格形成了一个连通区域.换言之,您可以从任何一个空白的单元格,走到其它任意的空白单元格.Pavel 的迷宫如果墙体太少,他就不喜欢这个迷宫.他希望将 k 个空白的单元格转换为墙体,使得剩余的全部单元格仍然能够形成一个连通区域.请帮助他实现这个任务. 输入…
http://codeforces.com/contest/366/problem/D 遍历下界,然后用二分求上界,然后用dfs去判断是否可以. #include <cstdio> #include <cstring> #include <algorithm> #define maxn 10000 using namespace std; int n,m; int head[maxn]; bool vis[maxn]; int e; int pl[maxn],pr[ma…
E. Three Swaps time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Xenia the horse breeder has n (n > 1) horses that stand in a row. Each horse has its own unique number. Initially, the i-th le…
问题来源:leetCode Sudoku Solver Write a program to solve aSudoku puzzle by filling the empty cells. Empty cells are indicated by the character *.*. You may assume that there will be only one unique solution. 问题链接: https://oj.leetcode.com/problems/sudoku-…
传送门:Kahn算法拓扑排序 摘录一段维基百科上的伪码: L ← Empty list that will contain the sorted nodes S ← Set of all nodes with no outgoing edges for each node n in S do visit(n) function visit(node n) if n has not been visited yet then mark n as visited …
374C - Inna and Dima 思路:dfs+记忆化搜索 代码: #include<bits/stdc++.h> using namespace std; #define ll unsigned long long #define pb push_back #define mem(a,b) memset(a,b,sizeof(a)) const int INF=0x3f3f3f3f; ][]; ][]; ][]; ][]={,,,,,-,-,}; int n,m; int dfs(i…