SGU 321 知道了双端队列,
来源:互联网 发布:大数据项目架构设计 编辑:程序博客网 时间:2024/05/17 04:31
思路: 贪心,
每次删除最上面的边。。
#include<utility>#include<iostream>#include<vector>#include<cstring>#include<deque>#include<cstdio>#include<algorithm>using namespace std;const int M = 200008;deque <int > q;vector <int> vi;int first_edge[M],next_edge[M],to[M],ty[M],sum;void dfs(int u){ if(sum < 0){ sum += 2; ty[q.front()] *= -1; vi.push_back(q.front()); q.pop_front(); } for(int i = first_edge[u] ; i!=-1 ; i = next_edge[i]){ sum += ty[i]; if(ty[i] == -1)q.push_back(i); dfs(to[i]); if(ty[i] == -1){ q.pop_back(); } sum -= ty[i]; }}int main(){ freopen("input.txt","r",stdin); int n,m,u,v; sum = 0; char buf[10]; memset(first_edge,-1,sizeof(first_edge)); scanf("%d",&n); for(int i = 0; i < n-1; i++){ scanf("%d%d%s",&u,&v,buf); next_edge[i] = first_edge[v]; first_edge[v] = i; ty[i] = *buf == 'p' ? 1 : -1; // cout <<ty[i] <<endl; to[i] = u; if(*buf == 'a')scanf("%s",buf); } dfs(1); printf("%d\n",(int)vi.size()); for(int i = 0; i < vi.size(); i++){ printf("%d%c",vi[i]+1, i==vi.size() - 1 ? '\n': ' '); }}
0 0
- SGU 321 知道了双端队列,
- SGU 271 Book Pile 双端队列
- SGU 271 双端队列deque
- SGU 271 双端队列 和 栈 模拟
- SGU 271 Book Pile(双端队列)
- 【SGU】271. Book Pile(双端队列模拟)
- SGU
- SGU
- SGU
- SGU
- SGU
- SGU
- (SGU
- SGU
- SGU
- SGU
- SGU
- SGU
- 瓜与瓜太之旅(2)连保叶则 中年夫妇行摄人世间 持续更新旅游休闲天涯论坛
- KVM 虚拟化安装
- 提倡DNS过滤,减少URL过滤
- 网络通信中的心跳机制的实现!
- 高德地图遇见的问题
- SGU 321 知道了双端队列,
- Log4j.properties配置详解
- Python标准库源码分析:SocketServer.py**********************8
- 基于单个 div 的 CSS 绘图
- DRBD块镜像 + Pacemaker心跳机制实现Active/Passive模式的高可用mysql集群
- 2014.10.10_星网锐捷笔试
- Mac 下 搭建 svn 服务器
- 昆仑叶哲华:企业品牌建设需规避的误区
- 数据挖掘中所需的概率论与数理统计知识、上