首页 技术 正文
技术 2022年11月17日
0 收藏 308 点赞 4,530 浏览 1463 个字

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

#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 0x0f0f0f0fusing 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;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,999
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,511
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,357
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,140
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,770
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,848