玲珑学院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:如果之前走过的时间小于这一次, ...
随机推荐
- Android 四大组件学习之BroadcastReceiver一
本节课学习四大组件最后一个, 广播接受者. 顾名思义广播接受者就是接受广播呗.比方在现实社会中,曾经每一个人家都有一台收音机,这可就能够去接受广播发出来的消息.大家都知道.程序世界也是參照的显示生活设 ...
- 查看客户端java日志
通过 Java 控制面板启用 Java 控制台 Windows 8 使用搜索来查找控制面板 按 Windows 徽标键 + W 以打开搜索框来搜索设置,或者将鼠标指针拖动到屏幕的右下角,然后单击搜索图 ...
- 九度OJ 1105:字符串的反码 (翻译)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:4929 解决:1529 题目描述: 一个二进制数,将其每一位取反,称之为这个数的反码.下面我们定义一个字符的反码.如果这是一个小写字符,则它 ...
- vue web开发
https://www.szzhdj.gov.cn/js/pagejs/assemblyHall_dzs1.js https://www.szzhdj.gov.cn/js/pagejs/assembl ...
- a REST API
https://spring.io/guides/tutorials/bookmarks/ http://roy.gbiv.com/untangled/2008/rest-apis-must-be-h ...
- Linux环境下安装MySQL(解压方式)
1.将安装包放在服务器上:mysql-5.6.37-linux-glibc2.12-x86_64.tar.gz 2.将安装包解压:tar -zxvf mysql-5.6.37-linux-glibc2 ...
- wireshark 学习 2
使用wireshark抓到的wifi数据包如果是加密的,就只能显示密文,无法得到真正的数据. 如果知道AP和SSID和key,就可以解密wifi数据包,显示上层协议的数据. 在wireshark中设置 ...
- SQL 关联操作
- Could not find com.android.tools.lint:lint-gradle:26.1.2.
allprojects { repositories { flatDir { dirs 'libs' } jcenter() google() }}
- UIVisualEffectView
UIBlurEffect 只支持到iOS 8.0+.系统给予的一个自动生成滤镜的方法 UIVisualEffectView *effectView = [[UIVisualEffectView all ...