玲珑学院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:如果之前走过的时间小于这一次, ...
随机推荐
- Linux 中权限控制实例
前言 前文对 Linux 中的权限进行了较为透彻的分析.而本文,则在前文的基础上,具体说明如何在代码中进行权限控制. 下面的代码涉及到以下几个方面: 1. 创建文件时设置文件权限 2. 修改文件的默认 ...
- 学习某些API的方法
学习某些 API 的方法 这里的 API 可能是某个系统平台,开发包,开发平台,开发工具等等,因为任何系统和技术方法提供给开发者的打包方式都是一系列 API . 无论你有在哪一层级开发,从硬件驱动到系 ...
- Operation not permitted - /usr/bin/pod
问题描述:执行sudo gem install cocoapods, 提示出错:While executing gem ... (Errno::EPERM) Operation not per ...
- XML解析PULL
解析xml是很经常使用的操作,除了SAX和DOM两种最经常使用的解析xml外,Pull解析器解析XML文件. 在Android的源代码中大量的使用Pull解析.pull不仅更加的面相对象,并且使用速度 ...
- PHP中的面向对象 中的类(class)
2.11 上午讲的是面向对象中的类(class),一个非常抽象的概念, 类里面成员的定义有 public$abc; private$abc(私有变量): protect $abc(受保护的变量): 下 ...
- Redis(三)位图
1.目录 什么是位图 位图的作用 基本使用 2.什么是位图 位图不是一个真实的数据类型,而是定义在字符串类型上的面向位的操作的集合.由于字符串类型是二进制安全的二进制大对象,并且最大长度是 512MB ...
- Struts action
<action name="KnowledgeBankManageAction_*" class="knowledgeBankManageAction" ...
- VVDocument+Appledoc生成文档
在写代码的时候写上适当的注释是一种良好的习惯,方便自己或者别人阅读的方便. **VVDocument**:(Github地址:[VVDocument](https://github.com/onevc ...
- assign,copy,strong,weak,nonatomic的具体理解
例子: NSString *houseOfMM = [[NSString alloc] initWithString:'MM的三室两厅']; 上面一段代码会执行以下两个动作: 1 在堆上分配一段内存 ...
- include vector 编译出错VC++
error C2665: “operator new” : 5个重载中没有一个可以转换参数1(从“const char [71]”类型)这个错误是怎么回事啊,搜索了整个项目好像没有可疑的new操作阿. ...