zoukankan      html  css  js  c++  java
  • P3083 [USACO13OPEN]豪华游船Luxury River Cruise

    瞎模拟.
    模拟的时候顺便把每次指令完成后到达的点记下来, 假如之前经过说明遇到了循环, 直接mod就ok.
    时间复杂度 (O(NM))

    #include <vector>
    #include <cstdio>
    #include <cstring>
    #include <cassert>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    const int MAXN = 1e3 + 10;
    const int MAXM = 5e2 + 10;
    inline int read()
    {
    	int x = 0; char ch = getchar();
    	while(!isdigit(ch)) ch = getchar();
    	while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
    	return x;
    }
    
    struct Node
    {
    	bool vis;
    	int l, r;
    }node[MAXN];
    
    int N, M, K;
    char dir[MAXM];
    
    vector<int> pos;
    int main()
    {
    	// freopen("p3083.in", "r", stdin);
    	cin>>N>>M>>K;
    	for(int i = 1; i <= N; i++){
    		int l = read(), r = read();
    		node[i].l = l, node[i].r = r;
    	}
    	for(int i = 0; i < M; i++)
    		scanf(" %c", dir + i);
    
    	int p = 1; bool flag = false;
    	pos.push_back(1), node[1].vis = true;
    	for(int i = 1; i <= K; i++){
    		for(int j = 0; j < M; j++){
    			if(dir[j] == 'L') p = node[p].l;
    			else p = node[p].r;
    		}
    		if(node[p].vis) flag = true;
    		node[p].vis = true; pos.push_back(p);
    		if(flag) break;
    	}
    	if(!flag) cout<<*pos.rbegin()<<endl;
    	else{
    		K -= pos.size();
    		pos.erase(pos.begin(), find(pos.begin(), pos.end(), *pos.rbegin()) + 1);
    		cout<<pos[K % pos.size()]<<endl;
    	}
    	return 0;
    }
    
    
  • 相关阅读:
    vue token使用 参考
    token 的作用与使用
    jq 绑定实时监听 input输入框
    认识java
    java基础语法
    java虚拟机笔记 运行时内存区域划分
    spring全家桶
    利用python脚本统计和删除redis key
    MySQL中count(字段) ,count(主键 id) ,count(1)和count(*)的区别
    编写shell脚本的一些规范
  • 原文地址:https://www.cnblogs.com/wsmrxc/p/9594041.html
Copyright © 2011-2022 走看看