C - Boss Gym - 101473C (模拟)
题目链接:https://cn.vjudge.net/contest/287775#problem/C
题目大意:给你n个人,然后m条关系,会有k次询问,每一次询问包括两种类型,第一种类型是交换两个人的位置,第二种类型是询问这个人的领导阶层年龄孙是多少、
具体思路:模拟题,我们建立好图之后,通过两个数组来记录当前这个人位置现在是多少。用一个数组是不行的,,举个例子,原来2这个位置变成了4,然后现在4的位置变成了2。如果这个时候要交换2和3,3指向的位置应该是4,而2指向的是3。第一个数组记录现在这个位置是哪个人在,第二个数字记录的是现在这个位置在原图上的位置,因为我们每一次的操作是在原图上进行的,。如果只是一个数组的话,第一次交换没有影响,第二次交换的时候就会有影响了。
father[2]=2.father[3]=3,father[4]=4;
交换3 4
father[2]=2,father[3=4,father[4]=3
交换2 3
father[2]=3,father[3]=2,father[4]=2
这样就有问题了,要连的这个点原来是多少。
AC代码:
#include<iostream>
#include<stack>
#include<stdio.h>
#include<algorithm>
#include<map>
#include<cmath>
#include<queue>
#include<cstring>
using namespace std;
# define ll long long
# define inf 0x3f3f3f3f
const int maxn =2e5+;
vector<int>q[maxn];
int age[maxn];
int father1[maxn];
int father2[maxn];
int vis[+];
int minn=inf;
void ask(int t,int val)
{
minn=min(minn,t==val?inf:age[father2[t]]);
for(int i=; i<q[t].size(); i++)
{
if(vis[q[t][i]])continue;
vis[q[t][i]]=;
ask(q[t][i],val);
}
}
int main()
{
int n,m,k;
scanf("%d %d %d",&n,&m,&k);
for(int i=; i<=n; i++)
{
scanf("%d",&age[i]);
father1[i]=i;
father2[i]=i;
}
int st,ed;
for(int i=; i<=m; i++)
{
scanf("%d %d",&st,&ed);
q[ed].push_back(st);
}
char str[];
while(k--)
{
memset(vis,,sizeof(vis));
scanf("%s",str);
if(str[]=='T')
{
scanf("%d %d",&st,&ed);
swap(father1[st],father1[ed]);
father2[father1[st]]=st;
father2[father1[ed]]=ed;
// cout<<1<<" "<<father1[1]<<" "<<father2[1]<<endl;
// cout<<2<<" "<<father1[2]<<" "<<father2[2]<<endl;
// cout<<3<<" "<<father1[3]<<" "<<father2[3]<<endl;
}
else if(str[]=='P')
{
minn=inf;
scanf("%d",&st);
ask(father1[st],father1[st]);
if(minn==inf)printf("*\n");
else
printf("%d\n",minn);
}
}
return ;
}
C - Boss Gym - 101473C (模拟)的更多相关文章
- Galactic Collegiate Programming Contest Gym - 101572G 模拟
#include<bits/stdc++.h> using namespace std; int n,m; struct node { int id; int slove; int pen ...
- Gym 100952B&&2015 HIAST Collegiate Programming Contest B. New Job【模拟】
B. New Job time limit per test:1 second memory limit per test:64 megabytes input:standard input outp ...
- 【模拟】ECNA 2015 I What's on the Grille? (Codeforces GYM 100825)
题目链接: http://codeforces.com/gym/100825 题目大意: 栅栏密码.给定N(N<=10),密钥为一个N*N的矩阵,'.'代表空格可以看到,'X'代表被遮挡,还有密 ...
- 【模拟】NEERC15 G Generators(2015-2016 ACM-ICPC)(Codeforces GYM 100851)
题目链接: http://codeforces.com/gym/100851 题目大意: n个序列.每个序列有4个值x,a,b,c,之后按照x=(a*x+b)%c扩展无穷项. 求每个序列各取一个数之后 ...
- 【模拟】NEERC15 J Jump(2015-2016 ACM-ICPC)(Codeforces GYM 100851)
题目链接: http://codeforces.com/gym/100851 题目大意: 系统里生成一个字符串C,一开始告诉你字符串的长度N(偶数).接着你需要在n+500次内猜出这个字符串是什么. ...
- 【模拟】NEERC15 E Easy Problemset (2015-2016 ACM-ICPC)(Codeforces GYM 100851)
题目链接: http://codeforces.com/gym/100851 题目大意: N个人,每个人有pi个物品,每个物品价值为0~49.每次从1~n顺序选当前这个人的物品,如果这个物品的价值&g ...
- 【模拟】NEERC15 A Adjustment Office (2015-2016 ACM-ICPC)(Codeforces GYM 100851)
题目链接: http://codeforces.com/gym/100851 题目大意: 一个N*N的矩阵A,Ai,j=i+j,Q次操作,每次分两种,R r取出第r行还未被取的所有数,并输出和.C c ...
- 【模拟】BAPC2014 G Growling Gears (Codeforces GYM 100526)
题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...
- Gym 100952C&&2015 HIAST Collegiate Programming Contest C. Palindrome Again !!【字符串,模拟】
C. Palindrome Again !! time limit per test:1 second memory limit per test:64 megabytes input:standar ...
随机推荐
- JVM调优工具
JMap 首先要知道Java进程的pid. Windows: .. .. .. Linux: ps -ef | grep java 查看堆栈信息(jmap -heap pid) jmap -heap ...
- Android Studio 签名 安全图片
apk 输出地址: /Users/houzhibin/javaself/android/SpgApp/app/build/outputs/apk 上图是debug版的: 发布版的需要在终端输入命令行: ...
- 怎么在linux下创建一个可运行脚本?
1.touch hello.sh 2.vim hello.sh键入i插入#!/bin/shecho hello world;键入:esc:wq3.chmod 700 hello.sh 4. 执行./h ...
- halcon形态学运算
腐蚀.膨胀.开运算(先腐蚀后膨胀).闭运算(先膨胀后腐蚀) 以halcon自带案例ball.hdev为例(开运算),注意代码有所缩减.关于sort_region函数,参考http://blog.sin ...
- feign无法注入service
https://segmentfault.com/q/1010000008531927
- 114. Flatten Binary Tree to Linked List(M)
. Flatten Binary Tree to Linked List Given a binary tree, flatten it to a linked list in-place. For ...
- ps: 图层样式;
图层样式是ps的一项图层处理能力,功能强大,能够简单快捷的制作处立体投影,各种质感以及光影效果. 10种图层样式: (1)投影:将为图层上的对象.文本或形状后面添加阴影效果.投影参数由“混合模式”.“ ...
- CodeForces165E 位运算 贪心 + 状压dp
http://codeforces.com/problemset/problem/165/E 题意 两个整数 x 和 y 是 兼容的,如果它们的位运算 "AND" 结果等于 0,亦 ...
- jmeter5.0 while controller使用总结
while controller 配合sql使用的方式 在while控制器条件中填空,这样当里面的请求断言失败后就会跳出循环 在while控制器条件中填LAST,当里面的请求断言失败后就会跳出循环,如 ...
- git ssh https 踩坑记 ---- 域账号密码更新
前几天突然通知要更新公司的域账号密码,然后git pull就一直报 fatal: Authentication failed for 'https://git ... 很奇怪的是,有一个项目git p ...