思路: 要用优势队列,因为有的+2,有的+1,所以队列中的步长是不单调的,所以找到一个答案但不一定最小,所以用优势队列把小的放在队首. 要记录状态,所以开了三维,题目和昨天做的那道小明差不多 vis开的int型赋值bool型WA了半天 代码: #include<iostream> #include<algorithm> #include<cstring> #include<queue> #define ll long long using namespace…
1356: Catch Time Limit: 2 Sec Memory Limit: 128 MBSubmit: 96 Solved: 40[Submit][Status][Web Board] Description A thief is running away!We can consider the city where he locates as an undirected graph in which nodes stand for crosses and edges stand…
Given a set of distinct integers, S, return all possible subsets. Note: Elements in a subset must be in non-descending order. The solution set must not contain duplicate subsets. For example, If S = [1,2,3], a solution is: [ [3], [1], [2], [1,2,3], […
题目链接 双端队列跑边,颜色相同的边之间的花费为0,放进队首:不同的花费为1,放进队尾. 用Dijkstra+常数优化也能过 #include<bits/stdc++.h> using namespace std; typedef long long ll; ,mod=1e9+; int n,m,hd[N],ne,dp[N]; struct E {int v,c,nxt;} e[N]; void addedge(int u,int v,int c) {e[ne]= {v,c,hd[u]},hd…
1053 Path of Equal Weight (30 分) Given a non-empty tree with root R, and with weight Wi assigned to each tree node Ti. The weight of a path from R to L is defined to be the sum of the weights of all the nodes along the path from R to any leaf…
Inversion Sequence Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%lld & %llu Description For sequence i1, i2, i3, … , iN, we set aj to be the number of members in the sequence which are prior to j and greater to j at the same time.…
Problem Description 给定一个m × n (m行, n列)的迷宫,迷宫中有两个位置,gloria想从迷宫的一个位置走到另外一个位置,当然迷宫中有些地方是空地,gloria可以穿越,有些地方是障碍,她必须绕行,从迷宫的一个位置,只能走到与它相邻的4个位置中,当然在行走过程中,gloria不能走到迷宫外面去.令人头痛的是,gloria是个没什么方向感的人,因此,她在行走过程中,不能转太多弯了,否则她会晕倒的.我们假定给定的两个位置都是空地,初始时,gloria所面向的方向未定,她可…