vis

Dudu's maze

≯℡__Kan透↙ 提交于 2019-11-29 15:07:06
23.7% 1000ms 262144K To seek candies for Maomao, Dudu comes to a maze. There are n n rooms numbered from 1 1 to n n and m m undirected roads. There are two kinds of rooms in the maze -- candy room and monster room. There is one candy in each candy room, and candy room is safe. Dudu can take the only candy away when entering the room. After he took the candy, this candy room will be empty. A empty room is also safe. If Dudu is in safe, he can choose any one of adjacent rooms to go, whatever it is. Two rooms are adjacent means that at least one road connects the two rooms. In another kind of

[USACO5.3]巨大的牛棚Big Barn

喜你入骨 提交于 2019-11-29 15:06:43
[TimeGate] https://www.luogu.org/problem/P2701 【解题思路】 f[i][j]=min(min(f[i][j-1],f[i-1][j]),f[i-1][j-1])+1; f(i, j)表示以(i, j)为右下角的最大正方形的边长。 【code】 1 #include <cstdio> 2 #include <iostream> 3 #include <algorithm> 4 using namespace std; 5 int n,t,x,y,ans=-1<<29; 6 bool vis[1005][1005]; 7 int f[1005][1005]; 8 int main(){ 9 //freopen("2701.in","r",stdin); 10 //freopen("2701.out","w",stdout); 11 scanf("%d%d",&n,&t); 12 while(t--){ 13 scanf("%d%d",&x,&y); 14 vis[x][y]=true; 15 } 16 for(register int i=1;i<=n;i++){ 17 for(register int j=1;j<=n;j++){ 18 if(!vis[i][j]) 19 f[i][j]=min(f[i-1][j-1],min(f[i]

2019沈阳网选——模拟

一曲冷凌霜 提交于 2019-11-29 14:27:53
1 #include <bits/stdc++.h> 2 using namespace std; 3 4 struct Node{ 5 string name; 6 int straight; 7 pair<int,int> four; 8 pair<int,int> full; 9 pair<int,int> three; 10 pair<pair<int,int>,int> twopair; 11 pair<int,int> pairr; 12 int handcard; 13 }a[100005]; 14 15 bool cmp(Node a,Node b){ 16 if(a.straight == b.straight){ 17 if(a.four.first == b.four.first){ 18 if(a.four.second == b.four.second){ 19 if(a.full.first == b.full.first){ 20 if(a.full.second == b.full.second){ 21 if(a.three.first == b.three.first){ 22 if(a.three.second == b.three.second){ 23 if(a.twopair.first.first == b.twopair.first

强连通分量

限于喜欢 提交于 2019-11-29 14:20:15
tarjan 基于深度优先搜索,用于寻找有向图中的连通块。 主要代码如下: inline void tarjan(int x){ dfn[x]=low[x]=++idx; vis[x]=1; sta[++top]=x; for(int i=head[x];i;i=e[i].nxt){ int v=e[i].v; if(!dfn[v]){//还未访问过这个节点 tarjan(v); low[x]=min(low[x],low[v]); } else if(vis[v]==1){//这个节点在栈中 low[x]=min(low[x],dfn[v]); } } if(dfn[x]==low[x]){//找到一个强联通分量 ++cnt; while(x!=sta[top]){ vis[sta[top]]=0; qlt[sta[top]]=cnt;//染色,标记这个节点属于第几号强联通分量 siz[cnt]++;//记录这一个连通块的节点数 top--; } vis[x]=0;//还要将这个节点弹出来 qlt[x]=cnt; siz[cnt]++; top--; } } 如果是要遍历整张图找到所有的连通块,通常还要加这句 for(int i=1;i<=n;i++){ if(!dfn[i]) tarjan(i); } 因为图中不一定全部都是联通的。 每一个点只访问了一次

[转载] $CF543B$ 题解

一笑奈何 提交于 2019-11-29 14:19:37
阅读原文 背景: \(Codeforces\) \(Round\) \(\#302\) \((Div. 1)\) \(B\) 题, \(Codeforces543B\) 给定一张边权全为 \(1\) 的图。在保证点 \(s_1\) 到点 \(t_1\) 的距离不超过 \(l_1\) 且点 \(s_2\) 到点 \(t_2\) 的距离不超过 \(l_2\) 的条件下,求最多能删去的边数。如果没有合法方案,输出 \(-1\) 。 这题最关键的就是转化模型。一开始我死都没想到正解就是因为忽略了边权全为 \(1\) 。 设点 \(i\) 到点 \(j\) 的最短长度为 \(dis[i][j]\) 。这时原条件就可以转化成求点 \(s_1\) 到点 \(t_1\) 的最短路上和点 \(s_2\) 到点 \(t_2\) 的最短路上经过的路径边数之和。 当然,这其中有 \(3\) 种情况: 第一种是点 \(s_1\) 到点 \(t_1\) 的最短路和点 \(s_2\) 到点 \(t_2\) 的最短路没有重叠部分。这个时候两个最短路值直接相加就行。 第二种是点 \(s_1\) 到点 \(t_1\) 的最短路和点 \(s_2\) 到点 \(t_2\) 的最短路在点 \(i\) 和点 \(j\) 之间重叠。这个时候可以 \(O(n^2)\) 枚举重叠点 \(i\) 和 \(j\)

三鑫普及组模拟赛

99封情书 提交于 2019-11-29 13:59:00
韬韬抢苹果: 题目: 又到了收获的季节,树上结了许多韬韬,错了,是许多苹果,有很多个小韬韬都来摘苹果。每个韬韬都想要最大的苹果,所以发生了争执,为了解决他们的矛盾,出题人定了一项特殊的规则,按体重的大小来定顺序,每一轮都是先由胖的先摘(照顾胖子),每个韬韬都是很聪明的,不会错过眼前最大的苹果。现在问题来了,一共有n个苹果,m个韬韬,要你按原顺序输出每个韬韬可以抢到的苹果的总大小。 思路: 大水题!!!直接模拟。 code: 1 #include<cstdio> 2 #include<algorithm> 3 using namespace std; 4 typedef long long ll; 5 6 int n,m; 7 int app[100001]; 8 ll sum[100001]; 9 struct ozj { 10 int wei,num; 11 } tt[100001]; 12 13 bool cmd(int x,int y) { 14 return x>y; 15 } 16 bool cmp(ozj x,ozj y) { 17 return x.wei>y.wei; 18 } 19 int main() { 20 scanf("%d%d",&n,&m); 21 for(int i=1; i<=n; ++i) { 22 scanf("%d",&app[i]); 23

树的重心专题

白昼怎懂夜的黑 提交于 2019-11-29 13:40:12
解题思路:选择一个节点作为根,设dp[i]表示以i为根的树的总节点个数,dp[i]=满足j为其子节点的的d[j]之和再加1(根节点)。只需在dfs过程中找到最大的子树节点,并与其上方的节点数做比较,就可以找出树的重心了。 题目大意:对于一棵无根树,找到一个点使得树以该点为根的有根树,最大子树(选择该节点后其子树的最大节点)的节点数最小。 https://blog.csdn.net/qq_41289920/article/details/83933631 https://blog.csdn.net/llzhh/article/details/78146548 https://blog.csdn.net/imzxww/article/details/81776219 模板: #include<iostream> #include<cstdio> #include<vector> #include<queue> #include<utility> #include<stack> #include<algorithm> #include<cstring> #include<string> #include<cmath> #include<set> #include<map> using namespace std; const int maxn = 5e4 + 5; int head

计蒜客 王子救公主 dfs

℡╲_俬逩灬. 提交于 2019-11-29 12:18:09
题意;如上,注意王子有可能跨越墙,前提使正好挨着墙。 思路:dfs王子和公主,开一个三维数组分别用vis[x][y][0],vis[x][y][1]标记王子和公主走到的点。 若存在二点相交即(vis[x][y][0]&&vis[x][y][1])==1,则说明王子可以预见公主。 # include <iostream> # include <cstring> # include <algorithm> # include <cstdio> # include <cstdlib> # include <queue> # include <cmath> # include <cctype> # include <stack> # include <map> # include <string> # include <cstdlib> # define ll long long # define N 100010 using namespace std ; const ll maxn = 1e2 + 5 ; //ll a[maxn],b[maxn]; //bool vis[maxn]; int ans [ maxn ] ; vector < int > v [ maxn ] ; int n , m ; bool vis [ maxn ] [ maxn ] [ 2 ] ; bool

Above the Median&Dueling GPSs

蓝咒 提交于 2019-11-29 11:41:58
2557: Above the Median 时间限制: 1 Sec 内存限制: 64 MB 提交: 14 解决: 9 [ 提交 ] [ 状态 ] [命题人: admin ] 题目描述 Farmer John has lined up his N (1 <= N <= 100,000) cows in a row to measure their heights; cow i has height H_i (1 <= H_i <= 1,000,000,000) nanometers--FJ believes in precise measurements! He wants to take a picture of some contiguous subsequence of the cows to submit to a bovine photography contest at the county fair. The fair has a very strange rule about all submitted photos: a photograph is only valid to submit if it depicts a group of cows whose median height is at least a certain threshold X (1 <

最小斯坦纳树

陌路散爱 提交于 2019-11-29 10:00:38
$dp[i][state]$ 表示以$i$为根,指定集合中的点的连通状态为state的生成树的最小总权值 有两种转移方向: 1、先通过连通状态的子集进行转移。 2、在当前枚举的连通状态下,对该连通状态进行松弛操作。 P4294 [WC2008]游览计划 注意景点的个数不超过10个。 $dp[i][j][state]$ 表示在$[i, j]$这个点与state中对应点连通的最小代价。 那么就可以用状压DP + spfa求解。 由于要输出方案,可以记录每个状态的前一个状态,最后dfs跑一遍就行了。 // #pragma GCC optimize(2) // #pragma GCC optimize(3) // #pragma GCC optimize(4) #include <algorithm> #include <iterator> #include <iostream> #include <cstring> #include <cstdlib> #include <iomanip> #include <bitset> #include <cctype> #include <cstdio> #include <string> #include <vector> #include <stack> #include <cmath> #include <queue> #include