ZOJ - 2615 Cells
注意数组别开太小了,代码照着训练经典打的:
#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的更多相关文章
- zoj 2615 Cells 栈的运用
题目链接:ZOJ - 2615 Scientists are conducting research on the behavior of a newly discovered Agamic Cell ...
- UVALive 3486/zoj 2615 Cells(栈模拟dfs)
这道题在LA是挂掉了,不过还好,zoj上也有这道题. 题意:好大一颗树,询问父子关系..考虑最坏的情况,30w层,2000w个点,询问100w次,貌似连dfs一遍都会TLE. 安心啦,这肯定是一道正常 ...
- ZOJ 3122 Sudoku
Sudoku Time Limit:10000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submit Status ...
- 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 ...
- POJ 3076 / ZOJ 3122 Sudoku(DLX)
Description A Sudoku grid is a 16x16 grid of cells grouped in sixteen 4x4 squares, where some cells ...
- 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 ...
- 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 ...
- C#使用Aspose.Cells导出Excel简单实现
首先,需要添加引用Aspose.Cells.dll,官网下载地址:http://downloads.aspose.com/cells/net 将DataTable导出Xlsx格式的文件下载(网页输出) ...
- Aspose.Cells导出Excel(2)
DataTable dtTitle = ds.Tables[]; DataTable dtDetail = ds.Tables[]; int columns = dtTitle.Columns.Cou ...
随机推荐
- Bootstrap--全局css样式之图片
好久没有更新博客了,在这里跟大家分享一下生活的小乐趣,作为程序员,整天对着电脑是很不爽的,加班也是常有的,所以连续工作对身体是很不爽的,而且随着年龄的增加,程序员身体状况会越来越差,还是建议大家要常去 ...
- ACM——搜索(一)
南邮OJ——1108 搜索(一) 时间限制(普通/Java):3500MS/10500MS 运行内存限制:65536KByte总提交:1023 测试通过:367 ...
- 【转】prototype扩展的JavaScript常用函数库
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> ...
- SharePoint 学习记事(一)
记录背景: 随着公司业务的拓展,为拿到更多的项目,让原本不太信任我们的美国大佬相信我们的实力,让在美国的销售发挥他的能力,所以公司在13年下半年筹划收购了一家美国本土的公司.大约400人的规模,这个公 ...
- UDP 广播 Java
1.服务端 public class UdpBroadcastServer { /** * @param args */ public static void main(String[] args) ...
- Python快速入门学习笔记(一)
本篇文章适合有其他高级语言基础的人群阅读 使用的Python版本为python2.7 使用的编辑器为Sublime Text3 世界始于Hello World: print 'Hello world' ...
- java继承实例。
定义了一个点类point,然后线条类line继承了point类,正方形类Suare继承point类. package test; import javax.swing.*; public class ...
- 初学C++,开博第一篇
几个维度相同的数组转置算法,这两种完全相同://注意:如果维度不同,转置会出错误,因为下标会越界...解决办法是把数组的维度调齐,或者是写到另一新数组中. for(int i=0;i<row;i ...
- mysql时间与日期函数
返回日期相关的 Now() || CURRENT_TIMESTAMP();返回当前时间 to_days(date) 返回日期date是西元0年至今多少天(不计算1582年以前) 转换为天数 date是 ...
- CAS原理
JDK5之前Java是靠synchronized关键字保证同步,这种机制存在以下问题: 在多线程竞争下,加锁.释放锁会导致比较多的上下文切换和调度延时,引起性能问题 一个线程持有锁会导致其他需要此锁的 ...