注意数组别开太小了,代码照着训练经典打的:

#include <iostream>
#include <sstream>
#include <cstdio>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <string>
#include <stack>
#include <map>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#define esp 1e-6
#define pi acos(-1.0)
#define pb push_back
#define mp(a, b) make_pair((a), (b))
#define in freopen("in.txt", "r", stdin);
#define out freopen("out.txt", "w", stdout);
#define print(a) printf("%d\n",(a));
#define bug puts("********))))))");
#define stop system("pause");
#define Rep(i, c) for(__typeof(c.end()) i = c.begin(); i != c.end(); i++)
#define pragma comment(linker, "/STACK:102400000, 102400000")
#define inf 0x0f0f0f0f using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii,int> VII;
typedef vector<int>:: iterator IT;
const int maxn = 20000005;
const int mxn = 300005;
int pre[maxn], post[maxn], start[mxn], c[mxn];
int n; void dfs(int root)
{
stack<int> S;
S.push(root);
pre[root] = 0;
int dfs_clock = 0;
while(!S.empty())
{
int x = S.top();
if(pre[x])
{
post[x] = ++dfs_clock;
S.pop();
continue;
}
pre[x] = ++dfs_clock;
for(int i = start[x]; i < start[x] + c[x]; i++)
if(i < n)
{
pre[i] = 0;
S.push(i);
}
else
{
pre[i] = ++dfs_clock;
post[i] = ++dfs_clock;
}
}
}
int main(void)
{
int T;
scanf("%d", &T);
for(int t = 1; t <= T; t++)
{
printf("Case %d:\n", t);
scanf("%d", &n);
start[0] = 1;
for(int i = 0; i < n; i++)
{
scanf("%d", &c[i]);
if(i>0)
start[i] = start[i-1]+c[i-1];
}
dfs(0);
int m;
scanf("%d", &m);
while(m--)
{
int a, b;
scanf("%d%d", &a, &b);
if(pre[a] < pre[b] && post[a] > post[b])
puts("Yes");
else puts("No");
}
if(t != T)
puts("");
}
return 0;
}

ZOJ - 2615 Cells的更多相关文章

  1. zoj 2615 Cells 栈的运用

    题目链接:ZOJ - 2615 Scientists are conducting research on the behavior of a newly discovered Agamic Cell ...

  2. UVALive 3486/zoj 2615 Cells(栈模拟dfs)

    这道题在LA是挂掉了,不过还好,zoj上也有这道题. 题意:好大一颗树,询问父子关系..考虑最坏的情况,30w层,2000w个点,询问100w次,貌似连dfs一遍都会TLE. 安心啦,这肯定是一道正常 ...

  3. ZOJ 3122 Sudoku

    Sudoku Time Limit:10000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status ...

  4. POJ 2251 Dungeon Master /UVA 532 Dungeon Master / ZOJ 1940 Dungeon Master(广度优先搜索)

    POJ 2251 Dungeon Master /UVA 532 Dungeon Master / ZOJ 1940 Dungeon Master(广度优先搜索) Description You ar ...

  5. POJ 3076 / ZOJ 3122 Sudoku(DLX)

    Description A Sudoku grid is a 16x16 grid of cells grouped in sixteen 4x4 squares, where some cells ...

  6. ZOJ 3780 Paint the Grid Again(隐式图拓扑排序)

    Paint the Grid Again Time Limit: 2 Seconds      Memory Limit: 65536 KB Leo has a grid with N × N cel ...

  7. ZOJ 3781 Paint the Grid Reloaded(BFS+缩点思想)

    Paint the Grid Reloaded Time Limit: 2 Seconds      Memory Limit: 65536 KB Leo has a grid with N rows ...

  8. C#使用Aspose.Cells导出Excel简单实现

    首先,需要添加引用Aspose.Cells.dll,官网下载地址:http://downloads.aspose.com/cells/net 将DataTable导出Xlsx格式的文件下载(网页输出) ...

  9. Aspose.Cells导出Excel(2)

    DataTable dtTitle = ds.Tables[]; DataTable dtDetail = ds.Tables[]; int columns = dtTitle.Columns.Cou ...

随机推荐

  1. 数据库字段出现科学计数法e+的情况分析

    问题: 有时候,我们在将excel表格中数据导入数据库中时,对于表格中的数字会默认为float的数据类型,这个时候导入到数据库中的这个表的值是正常显示的: 然而如果你要把导入到数据库中的表,再插入到另 ...

  2. 文本框限制输入类型<input>的输入框

    最近在开发完一个项目后,又测试人员测试bug,然后我根据他们测试出来的bug一个一个的改,然后就遇到了一个问题,文本框是用来搜索,但是,比如这个文本框是用来搜索年龄的区间,输入条件的时候,如果输入了非 ...

  3. 7zip self-extracted executable: To extract file to specific directory

    1) Install 7-zip (7zS.sfx will be installed to C:\Program Files\7-Zip): http://7zsfx.solta.ru/en/ 2) ...

  4. VS2010 error RC2135: file not found

    VS2010 C++ win32 DLL 工程, 添加 rc 文件, 编辑 String Table. 默认情况下英文版本的 rc 文件能够顺序编译通过,为了让工程支持多语言,将字符串修改为其他语言时 ...

  5. 基于libuv库的UDP收/发广播消息代码实现

    uv_send(发送端): #include "uv.h" #include "task.h" #include <stdio.h> #includ ...

  6. 【HeadFirst设计模式】13.与设计模式相处

    模式: 是在某情境下,针对某问题的某种解决方案. 要点: 让设计模式自然而然地出现在你的设计中,而不是为了使用而使用. 设计模式并非僵化的教条,你可以依据自己的需要采用或者进行调整. 总是使用最简单的 ...

  7. IE兼容性问题

    1.H5标签兼容.解决:js:document.createElement("footer");css:display: block;或者直接使用    html5shiv.js ...

  8. 简单重置Centos服务器中Mysql的root密码

    1.编辑MySQL配置文件my.cnf vi /etc/my.cnf #编辑文件,找到[mysqld],在下面添加一行skip-grant-tables [mysqld] skip-grant-tab ...

  9. java根据url获取json对象

    package test; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; ...

  10. Html学习_简易个人网页制作

    应用学到的内容,制作简易个人网页 <!DOCTYPE html> <html> <head> <title>Jane.liu</title> ...