玲珑学院1072 【DFS】
蛤蛤,略蠢。
priority_queue
自定义优先级 和排序是反的
struct node
{
int x,y;
friend bool operator< (node a,node b)
{
if(a.y<b.y)
return 1;
if(a.y==b.y&&a.x>b.x)
return 1;
return 0;
}
};
priority_queue<node>qu;
思路:
加个优先队列维护一下结点的大小,深度。
#include<bits/stdc++.h>
using namespace std;
typedef long long LL; const int N=1e5+10; struct node
{
int x,y;
friend bool operator< (node a,node b)
{
if(a.y<b.y)
return 1;
if(a.y==b.y&&a.x>b.x)
return 1;
return 0;
}
};
priority_queue<node>qu; map<int,int>kt; struct asd
{
int to;
int next;
};
int n;
asd q[N*4];
int head[N*4],tol; bool vis1[100010]; void add(int u,int v)
{
q[tol].to=v;
q[tol].next=head[u];
head[u]=tol++; node now;
now.x=v;
kt[v]=kt[u]+1;
now.y=kt[v];
qu.push(now);
} void ceshi()
{
node now;
int uu;
scanf("%d",&uu);
for(int i=1;i<=uu;i++)
{
scanf("%d%d",&now.x,&now.y);
qu.push(now);
}
while(!qu.empty())
{
now=qu.top();
printf("%d %d \n",now.x,now.y);
qu.pop();
}
puts("");
} void Delet(int u)
{
vis1[u]=0;
for(int i=head[u]; i!=-1; i=q[i].next)
{
int v=q[i].to;
if(!vis1[v])
continue;
Delet(v);
}
} int main()
{
int T;
int x;
scanf("%d",&T);
while(T--)
{
while(!qu.empty())
qu.pop();
//ceshi(); memset(vis1,0,sizeof(vis1)); memset(head,-1,sizeof(head));
tol=0; kt.clear();//深度啊
kt[1]=1;
node now;
now.x=1;
now.y=kt[1];
qu.push(now);
vis1[1]=1; int num=2; scanf("%d",&n);
for(int i=1; i<=n; i++)
{
scanf("%d",&x);
if(x<0)
{
x=-x;
Delet(x);
}
else
{
add(x,num);
vis1[num]=1;
num++;
}
while(!qu.empty())
{
node now=qu.top();
if(!vis1[now.x])
qu.pop();
else
{
printf("%d\n",now.x);
break;
}
}
}
}
return 0;
}
玲珑学院1072 【DFS】的更多相关文章
- 玲珑学院-ACM比赛1014 - Absolute Defeat
1014 - Absolute Defeat Time Limit:2s Memory Limit:64MByte Submissions:257Solved:73 DESCRIPTION Eric ...
- 玲珑学院oj 1152 概率dp
1152 - Expected value of the expression Time Limit:2s Memory Limit:128MByte Submissions:128Solved:63 ...
- 玲珑学院OJ 1023 - Magic boy Bi Luo with his excited math problem 树状数组暴力
分析:a^b+2(a&b)=a+b so->a^(-b)+2(a&(-b))=a-b 然后树状数组分类讨论即可 链接:http://www.ifrog.cc/acm/probl ...
- 玲珑学院OJ 1028 - Bob and Alice are playing numbers 字典树,dp
http://www.ifrog.cc/acm/problem/1028 题解处:http://www.ifrog.cc/acm/solution/4 #include <cstdio> ...
- 玲珑学院 1010 - Alarm
1010 - Alarm Time Limit:1s Memory Limit:128MByte DESCRIPTION Given a number sequence [3,7,22,45,116, ...
- 玲珑学院 1050 - array
1050 - array Time Limit:3s Memory Limit:64MByte Submissions:494Solved:155 DESCRIPTION 2 array is an ...
- 玲珑学院 1052 - See car
1052 - See car Time Limit:2s Memory Limit:64MByte Submissions:594Solved:227 DESCRIPTION You are the ...
- 玲珑学院 1014 Absolute Defeat
SAMPLE INPUT 3 2 2 2 1 1 5 1 4 1 2 3 4 5 4 10 3 1 2 3 4 SAMPLE OUTPUT 1 0 15 前缀和,每个元素都判断一下. #include ...
- hdu - 1072(dfs剪枝或bfs)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1072 思路:深搜每一个节点,并且进行剪枝,记录每一步上一次的s1,s2:如果之前走过的时间小于这一次, ...
随机推荐
- 2016/07/07 wamp中apache2.4.9允许外部访问的配置 重点是版本 版本不同配置效果不同
wamp安装包中安装好服务器之后只能使用127.0.0.1来访问了,如果我们要设置多个站点或其它像192.168.1.1这种就需要进行一下修改,具体步骤如下. wamp-apache2.4.9允许 ...
- Hibernate中的Sesson操作
一.Session概述 Session是应用程序与数据库之间的一个会话,是Hibernate运作的中心,持久层操作的基础,相当于JDBC中的Connection.Session对象是通过Session ...
- asp.net 列表控件
web空间类都被放置在System.Web.UI.WebControls命名空间下1.ListBox ListBox控件用于创建多选的下拉列表,而可选项是通过ListItem元素来定义的.示例代码如 ...
- Local Response Normalization 60 million parameters and 500,000 neurons
CNN是工具,在图像识别中是发现图像中待识别对象的特征的工具,是剔除对识别结果无用信息的工具. ImageNet Classification with Deep Convolutional Neur ...
- JS中正则匹配开头不带空格,结尾也不带空格的字符串
在做项目的时候,要求限制SSID的长度.以及开头和结尾不能是空格. var reg = /^\S.{0,30}\S$/ "$$$ $$".match(reg); ==> ...
- Hadoop实战-MapReduce之分组(group-by)统计(七)
1.数据准备 使用MapReduce计算age.txt中年龄最大.最小.均值name,min,max,countMike,35,20,1Mike,5,15,2Mike,20,13,1Steven,40 ...
- Hadoop集群搭建-Hadoop2.8.0安装(三)
一.准备安装介质 a).hadoop-2.8.0.tar b).jdk-7u71-linux-x64.tar 二.节点部署图 三.安装步骤 环境介绍: 主服务器ip:192.168.80.128(ma ...
- mongodb学习之:GridFS
GridFS是一种在Mongodb中存储大二进制文件的机制.GridFS 用于存储和恢复那些超过16M(BSON文件限制)的文件(如:图片.音频.视频等). 使用GridFS有如下几个原因: 1 利用 ...
- java内存泄露具体解释
非常多人有疑问,java有非常好的垃圾回收机制,怎么会有内存泄露?事实上是有的,那么何为内存泄露?在Java中所谓内存泄露就是指在程序执行的过程中产生了一些对象,当不须要这些对象时,他们却没有被垃圾回 ...
- UIButton的selected设为TRUE时在按下时显示自己定义的背景图
在UIButton的selected设为TRUE后.须要在按钮高亮时,显示自己定义的背景图. 经研究hightLighted和selected这两个状态是能够重叠的,就是button能够同一时候处于s ...