zoukankan      html  css  js  c++  java
  • 10-18 noip提高组模拟赛(codecomb)T1倍增[未填]

    T1只想到了找环,> <倍增的思想没有学过,所以看题解看得雨里雾里的(最近真的打算学一下!

    题目出的挺好的,觉得noip极有可能出现T1T2T3,所以在此mark

    刚开始T1以为是模拟,还妄想这可以一遍处理出所有的环,和各个数之间的关系(> <结果自己把自己绕进去了,因为根本不可以!)

    然后后面改了暴力,每问一次就处理一次;

    正解没看懂QAQ..应该是不太懂思想的缘故

    暴力:

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <iostream>
    using namespace std;
    const int maxn=100005;
    int n,m,x;
    long long k;
    int a[maxn];
    bool v[maxn];
    int main(){
    	scanf("%d%d",&n,&m);
    	for(int i=1;i<=n;i++){
    		scanf("%d",&a[i]);
    	}
    	for(int i=1;i<=m;i++){
    		cin>>x>>k;
    	    for(int i=1;i<=n;i++) v[i]=0;
    	    int temp;
    		for(int i=x;!v[i];i=a[i]){
    	    	v[i]=1;
    	    	temp=a[i];
    	    }
    	    while(k && x!=temp){
    	    	x=a[x];
    	    	k--;
    	    }
    	    if(k){
    	    	int cnt=1;
    	    	while(a[temp]!=x){
    	    		cnt++;
    	    		temp=a[temp];
    	    	}
    	    	k%=cnt;
    	    }
    		while(k--) x=a[x];
    		cout<<x;
    	}
    	return 0;
    }
    

      

      

  • 相关阅读:
    微信支付退款部分代码
    Raspberry PI 点亮LED
    Raspberry PI 摄像头
    RaspberryPI 3B系统烧录
    MySQL基础使用
    MySQL数据库管理系统概述
    Eclipse创建JAVA项目
    Brup Suite拦截https请求
    Github 第一个仓库
    python os模块主要函数
  • 原文地址:https://www.cnblogs.com/polebug/p/4034402.html
Copyright © 2011-2022 走看看