和书上的方法不一样。。。

因为我不知道节点,所以就直接用map来存左右了。

#include<bits/stdc++.h>

using namespace std;

map <int, int> m;
int l, r;
int cnt; void dfs(int pos){
int t1;
scanf("%d", &t1);
if (t1 != -){
dfs(pos - );
l = min(l, pos - );
m[pos - ] += t1;
}
int t2;
scanf("%d", &t2);
if (t2 != -){
dfs(pos + );
r = max(r, pos + );
m[pos + ] += t2;
}
} bool read_edge(){
int a;
scanf("%d", &a);
if (a == -) return false;
l = , r = ;
m[] += a;
dfs();
printf("Case %d:\n", ++cnt);
for (int i = l; i <= r; i++){
printf("%d%c", m[i], i == r ? '\n' : ' ');
}
m.clear();
printf("\n");
return true;
} int main(){
while (read_edge()){}
return ;
}

UVA699 dfs and map的更多相关文章

  1. HDU 2094 产生冠军 dfs加map容器

    解题报告:有一群人在打乒乓球比赛,需要在这一群人里面选出一个冠军,现在规定,若a赢了b,b又赢了c那么如果a与c没有比赛的话,就默认a赢了c,而如果c赢了a的话,则这三个人里面选不出冠军,还有就是如果 ...

  2. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)A模拟 B三分 C dfs D map

    A. Andryusha and Socks time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  3. codeforces 633D D. Fibonacci-ish(dfs+暴力+map)

    D. Fibonacci-ish time limit per test 3 seconds memory limit per test 512 megabytes input standard in ...

  4. 1034 Head of a Gang (30分)(dfs 利用map)

    One way that the police finds the head of a gang is to check people's phone calls. If there is a pho ...

  5. Shopping(SPFA+DFS HDU3768)

    Shopping Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  6. 最大联通子数组之和(dfs,记忆化搜索,状态压缩)

    最大联通子数组,这次的题目,我采用的方法为dfs搜索,按照已经取到的数v[][],来进行搜索过程的状态转移,每次对v[][]中标记为1的所有元素依次取其相邻的未被标记为1的元素,将其标记为1,然而,这 ...

  7. poj2386(简单的dfs/bfs)

    题目链接:http://poj.org/problem?id=2386 Description Due to recent rains, water has pooled in various pla ...

  8. ALGO-125_蓝桥杯_算法训练_王、后传说(DFS)

    问题描述 地球人都知道,在国际象棋中,后如同太阳,光芒四射,威风八面,它能控制横.坚.斜线位置. 看过清宫戏的中国人都知道,后宫乃步步惊心的险恶之地.各皇后都有自己的势力范围,但也总能找到相安无事的办 ...

  9. hdu 1983(BFS+DFS) 怪盗Kid

    http://acm.hdu.edu.cn/showproblem.php?pid=1983 首先,题目要求出口和入口不能封闭,那么,只要把出口或入口的周围全给封闭了那盗贼肯定无法成功偷盗,出口或入口 ...

随机推荐

  1. 在textarea的内容后面增加内容

    document.getElementById("result").value+=data+"\n>"; 本文为本人用来记录自己做的一些东西,如有不对的地 ...

  2. tomcat各目录(文件)作用

    以tomcat7.0.50为例,主目录下有bin,conf,lib,logs,temp,webapps,work 7个文件夹 bin目录主要是用来存放tomcat的命令,主要有两大类,一类是以.sh结 ...

  3. 10- python 网络爬虫分析

    Python 网络爬虫简单分析 import urllib2 response = urllib2.urlopen("http://www.baidu.com") print re ...

  4. Cv图像处理

    http://wiki.opencv.org.cn/index.php/Cv%E5%9B%BE%E5%83%8F%E5%A4%84%E7%90%86 看看知识点,虽然是C 版本.

  5. hdu_5742_It's All In The Mind

    题目链接:hdu_5742_It's All In The Mind 题意: 有一个部分的数列,让你找一个满足他给的三个条件的数列,使前两个数的和除这个数列的sum最大 题解: xjb贪心一下就行了. ...

  6. LeetCode OJ 26. Remove Duplicates from Sorted Array

    Given a sorted array, remove the duplicates in place such that each element appear only once and ret ...

  7. OpenCV——mixChannels函数

    mixChannels Copies specified channels from input arrays to the specified channels of output arrays. ...

  8. 递归与DP

    每一个递归问题都可以改成DP来做...只不过DP会浪费一些空间罢了..DP只是把之前的结果存起来以防再算一遍罢了.....

  9. viewpager处理(一):让viewpager不能滑动

    1.实现原理: 自定义viewpager,重写onTouchEvent方法,什么触摸事件都不响应即可让viewpager不能滑动. 2.代码如下 public class NoScrollViewPa ...

  10. Codeforces Round #371 (Div. 2) C 大模拟

    http://codeforces.com/contest/714/problem/C 题目大意:有t个询问,每个询问有三种操作 ①加入一个数值为a[i]的数字 ②消除一个数值为a[i]的数字 ③给一 ...