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 ...
随机推荐
- increment/decrement/dereference操作符
标题以上分别对于++/--/* #include <iostream> #include <cstddef> using namespace std; class INT { ...
- 开发问题及解决--java.lang.IllegalStateException: Circular dependencies cannot exist in RelativeLayout
<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android=" ...
- RS485 / RS422
RS422可以变为RS485:A和Y短路(然后接T/R+),B和Z短路(然后接T/R-) RS485是半双工,只有两根线通信线,要么接收状态,要么发送状态 RE为低电平,作为接收器 DE为高电平,作为 ...
- C#:TextBox数据绑定
经常写用一个TextBox显示某个对象,然后编辑之后再保存的程序.以前都是在TextBox_TextChanged事件中修改对象的值,或者保存的时候再读取TextBox.Text属性保存对象的值.这样 ...
- Linux系统IO分析工具之iotstat常用参数介绍
Linux系统IO分析工具之iotstat常用参数介绍 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 1>.安装iostat [root@flume115 ~]# yum - ...
- Java Web之上传文件
本篇文章你会学到 1. Apache FileUpload组件 2.上传文件保存的路径和名称问题 3.缓存大小和临时目录 4.控制文件上传的格式 先讲一个简单的例子,一个注册页面,有账号,邮箱,和头像 ...
- JAVA-Clone 对象拷贝
JAVA 中对象的赋值是复制对象的引用,即复制引用 public static void main(String[] args) { User user = new User(1,"asds ...
- python 字符串 切片
####################概念######################''' int 整数 str 字符串 一般不存放大量的数据 bool 布尔值,用来判断. True,False ...
- 转 G1垃圾收集器入门
转自:http://blog.csdn.net/zhanggang807/article/details/45956325 最近在复习Java GC,因为G1比较新,JDK1.7才正式引入,比较艰难的 ...
- [复现]蝉知cms 5.6 前台注入
https://share.weiyun.com/5cbff06337d32a9748d0f1bead5ddbd5 前台注入 在/chanzhieps/system/module/cart/contr ...