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

#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. Android——列表选择框(Spinner)

    通常情况下,如果列表选择框中要显示的列表项是可知的,那么可以将其保存在数组资源文件中,然后通过数组资源来为列表选择框指定列表项.这样就可以在不编写Java代码的情况下实现一个下拉选择框. 1.在布局文 ...

  2. linux中的常用命令

    cat tail -f 日 志 文 件 说 明 /var/log/message 系统启动后的信息和错误日志,是Red Hat Linux中最常用的日志之一 /var/log/secure 与安全相关 ...

  3. $.get

    $('#choice').change(function() { if($(this).val() != '') { $.get( 'data.php', { what: $(this).val() ...

  4. 虚拟光驱 DAEMON Tools Lite ——安装与入门

    DAEMON Tools Lite 是什么?它不仅仅是虚拟光驱.是的,你可以使用它制作.加载光盘映像,但是 DAEMON Tools 产品那么多,Lite版与其他版本究竟有什么不同呢?或者说,是什么让 ...

  5. android 电话拨号器

    电话拨号器(重点)            1.产品经理: 需求分析文档,设计原型图    2.UI工程师: 设计UI界面    3.架构师: 写架构,接口文档    4.码农: 服务端,客户端     ...

  6. [Effective Java读书笔记] 第二章 创建和销毁对象(1~7)

    我的技术博客经常被流氓网站恶意爬取转载.请移步原文:http://www.cnblogs.com/hamhog/p/3537576.html,享受整齐的排版.有效的链接.正确的代码缩进.更好的阅读体验 ...

  7. 九度OJ 1104 整除问题

    题目地址:http://ac.jobdu.com/problem.php?pid=1104 题目描述: 给定n,a求最大的k,使n!可以被a^k整除但不能被a^(k+1)整除. 输入: 两个整数n(2 ...

  8. Poj 1017 / OpenJudge 1017 Packets/装箱问题

    1.链接地址: http://poj.org/problem?id=1017 http://bailian.openjudge.cn/practice/1017 2.题目: 总时间限制: 1000ms ...

  9. Nginx 域名转发

    例如访问www.b.cn直接跳到www.a.cn上去,又不想多域名捆绑一个目录. server { listen 80; server_name www.b.cn; rewrite ^/(.*)$ h ...

  10. .NET研发人员面试题(一)

    1.简述javascript中的“=.==.===”的区别? =赋值 ==比较是否一般相等   "3"==3 //会做类型的隐式转换,true ===比较是否严格相等 " ...