玲珑学院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:如果之前走过的时间小于这一次, ...
随机推荐
- svn服务器迁移(windows下)
废话不多说,直接上步骤: 服务端: 1.创建一个备份文件夹 如:D:\svn_bak 2.进入cmd,cd命令到你的svn服务器安装目录的bin文件下,本人的安装目录在 D:\Program File ...
- 从前端看JavaWeb软件工程中的解耦合
以下为作者备忘,详情请看 http://www.cnblogs.com/feichengwulai/articles/3412946.html http://blog.csdn.net/piantou ...
- @P0或@P1附近有语法错误
分析:@P0指的是第一个参数附近有错误;为'@P1'指的是第二个参数附近错误语法有错误.
- 【甘道夫】Eclipse+Maven搭建HBase开发环境及HBaseDAO代码演示样例
环境: Win764bit Eclipse Version: Kepler Service Release 1 java version "1.7.0_40" 第一步:Eclips ...
- [数据挖掘课程笔记]SLIQ算法
1.数据结构 主要的数据结构有:1.Attribute List 2.Class List 对于数据集,每一个属性都有一个对应的Attribute List.如上图所示,每个Attribute Li ...
- 找到bashrc
(1)直接sudo gedit ~/.bashrc就可以了,编辑完后关闭就行 (2)主文件夹下ctrl+h就能找到.bashrc文件 之所以要找到bashrc文件,是为了把命令 source /opt ...
- Android wifi 从连接态自动断开的解决办法(dhcp导致)【转】
本文转载自:http://blog.csdn.net/DKBDKBDKB/article/details/38490201 对wifi部分的代码流程已经看了段时间,前两天终于解决了工作中遇到的一个wi ...
- Backbone vs AngularJS
首先 Backbone 没有 AngularJS 那么容易上手. 而且作者并没有想让Backbone草根化的意思. Backbone 比喻成战斗机. 看上去更像是真正的MVC框架, model-vie ...
- 操作Zookeeper
可以通过图形化界面进行操作使用的工具是 zookeeper-dev-ZooInspector.jar 连接到我的zk之后: 1.Java操作zk 依赖: <dependency> < ...
- zabbix常用命令
1. 查看mysql 各数据库大小命令 "Database Size in MB" FROM information_schema.TABLES GROUP BY table_sc ...