玲珑学院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:如果之前走过的时间小于这一次, ...
随机推荐
- beyond compare添加右键快捷方式
如果安装beyond compare后,右键不能出现比较选项,可以通过设置 beyond compare完成. 选择 工具->选项,在资源管理器整合下面,有一个在资源管理器关联菜单中显示beyo ...
- MVC入门——列表页
创建控制器UserInfoController using System; using System.Collections.Generic; using System.Linq; using Sys ...
- JS中小数如何转化为百分数并能四舍五入
<script type="text/javascript">//n表示百分数保留的位数 function toPercent(n){ n = n || 2; retu ...
- g++: command not found的解决
G++没有装或却没有更新 以下方法都可以试试: centos: yum -y update gcc yum -y install gcc+ gcc-c++ ubuntu: apt-get up ...
- java之选择排序
//选择排序(Select Sorting)也是一种简单的排序方法.它的基本思想是:第一次从R[0]-R[n-1]中选取最小值,与R[0]交换,第二次从R[1]-R[n-1]中选取最小值,与R[1] ...
- Linux就该这么学--命令集合5(用户与组管理命令)
1.useradd命令用于创建新用户:(useradd [选项] 用户名) 附录: -d 指定用户的家目录 -D 展示默认值 -e 账号有效截止日期,格式:YYY-MM-DD -g 指定一个初始用户组 ...
- 增删改查,连接数据库UsersDao
package com.abc.dao; import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.Re ...
- 分词系统简介:PHPAnalysis分词程序
分词系统简介:PHPAnalysis分词程序使用居于unicode的词库,使用反向匹配模式分词,理论上兼容编码更广泛,并且对utf-8编码尤为方便. 由于PHPAnalysis是无组件的系统,因此速度 ...
- 20170313 ABAP以jason 格式返回值到http(接口内容返回)
问题1: 返回jason 格式信息给你们这步不通, 这个可以怎么处理, ***得到SCP 系统开发回复,他们需要调整方法: (1)调用函数做RETURN, IT_ZSMLSCPNOTICE-FUNC ...
- Android 属性动画ObjectAnimator和ValueAnimator讲解
区别: ObjectAnimator 是直接对某个view进行更改. ValueAnimator 根据 TimeInterpolator 在不断产生相应的数据,来传进view ,view自己做改变. ...