CodeForces 264A Escape from Stones dfs

题目链接:点击打开链接

题意:开始有一个区间[0,1]

每次操作在中间填i,然后选择坐半段或者右半段(给出选择的方案,然后从左到右输出填写的i)

(i=1 2 3···)

#include <cstdio>
char s[1000005];
void dfs(int x){
    if(s[x] == 0)return ;
    if(s[x] == 'l')
    {
    dfs(x+1);
    printf("%d\n", x+1);
    }
    else {
    printf("%d\n", x+1);
    dfs(x+1);
    }
    }
int main(){
    scanf("%s", s);
    dfs(0);
    return 0;
}
时间: 2024-11-03 21:01:33

CodeForces 264A Escape from Stones dfs的相关文章

Codeforces 264A. Escape from Stones

Squirrel Liss lived in a forest peacefully, but unexpected trouble happens. Stones fall from a mountain. Initially Squirrel Liss occupies an interval [0,?1]. Next, n stones will fall and Liss will escape from the stones. The stones are numbered from

Codeforces Round #162 (Div. 1) A. Escape from Stones

A. Escape from Stones time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Squirrel Liss lived in a forest peacefully, but unexpected trouble happens. Stones fall from a mountain. Initially Squ

SPOJ AMR10I Dividing Stones --DFS

题意:给n个石头,分成一些部分(最多n部分,随便分),问分完后每部分的数量的乘积有多少种情况. 分析:可以看出,其实每个乘积都可以分解为素数的乘积,比如乘积为4,虽然可以分解为4*1,但是更可以分解为2*2*1,所以就可以枚举素因子来分解,dfs即可. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm>

CodeForces - 383C Propagating tree(dfs + 线段树)

题目大意: 给出一棵树,树上每个节点都有权值,然后有两个操作. 1 x val 在结点x上加上一个值val,x的儿子加上 -val,x的儿子的儿子加上 - (-val),以此类推. 2 x 问x节点的值. 思路分析: 每个节点上加值都是给自己的儿子节点加,而且这个是颗树. 比如样例上的,如果你给node 1加一个值,那么五个节点都加. 再给node 2加个值,2的儿子节点也加了,之前给1加的值也要加到2号节点的儿子. 所以你会发现节点的儿子会存在一个从属的关系. 这样的话,我们可以把所有节点从新

Codeforces --- 982C Cut &#39;em all! DFS加贪心

题目链接: https://cn.vjudge.net/problem/1576783/origin 输入输出: ExamplesinputCopy42 44 13 1outputCopy1inputCopy31 21 3outputCopy-1inputCopy107 18 48 104 76 59 33 52 102 5outputCopy4inputCopy21 2outputCopy0NoteIn the first example you can remove the edge bet

Codeforces 932F - Escape Through Leaf

Problem Link: http://codeforces.com/contest/932/problem/F Problem Statement: F. Escape Through Leaf time limit per test: 3 seconds memory limit per test:256 megabytes input: standard input output: standard output You are given a tree with n nodes (nu

Codeforces 711 D. Directed Roads (DFS判环)

题目链接:http://codeforces.com/problemset/problem/711/D 给你一个n个节点n条边的有向图,可以把一条边反向,现在问有多少种方式可以使这个图没有环. 每个连通量必然有一个环,dfs的时候算出连通量中点的个数y,算出连通量的环中点的个数x,所以这个连通量不成环的答案是2^(y - x) * (2^x - 2). 最后每个连通量的答案相乘即可. 1 //#pragma comment(linker, "/STACK:102400000, 102400000

CodeForces 148B Escape

Escape Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 148B Description The princess is going to escape the dragon's cave, and she needs to plan it carefully. The princess runs at vp mil

zoj 3620 Escape Time II dfs

Escape Time II Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3620 Description There is a fire in LTR ’ s home again. The fire can destroy all the things in t seconds, so LTR has to escape i