zoukankan      html  css  js  c++  java
  • 题解 [POI2013]SPA-Walk

    题目传送门

    题目大意

    给出两个长度为 (n)(01) 串,问是否可以通过某一位把 (s) 变为 (t),但是中途不能变为 (k)(01) 串中任意一个,问是否可行。

    (nle 60,n imes kle 5 imes 10^6)

    思路

    拖了 1 年多,1 年前打了一个双向 BFS ,骗了 (60) 分(为我后面看别人的 AC 代码打下了良好基础 (伦敦雾,1 年后,在看了题解之后成功 A 掉此题,我成功了,我不再是以前的那个我了。

    好吧,还是言归正传,其实这道题就是一个爆搜然后加上一个剪枝,剪枝就是说你最多只搜 (n imes k) 个点,至于为什么我就不知道了。(不过题面都给了 (n imes kle 5 imes 10^5) 难道提示还不明显么?)证明的话可以参考 这篇题解 ,反正我是没有看懂。

    ( exttt{Code})

    using namespace std;
    
    #define Int register int
    #define ll long long
    #define MAXN 5000005
    #define MAXM 1000005
    #define mod 2737321
    
    template <typename T> inline void read (T &t){t = 0;char c = getchar();int f = 1;while (c < '0' || c > '9'){if (c == '-') f = -f;c = getchar();}while (c >= '0' && c <= '9'){t = (t << 3) + (t << 1) + c - '0';c = getchar();} t *= f;}
    template <typename T,typename ... Args> inline void read (T &t,Args&... args){read (t);read (args...);}
    template <typename T> inline void write (T x){if (x < 0){x = -x;putchar ('-');}if (x > 9) write (x / 10);putchar (x % 10 + '0');}
    
    ll a[MAXM],to[MAXN],q[MAXN];
    int n,k,cnt,h,t,nxt[MAXN],head[mod + 5];
    
    ll getins (){
    	ll s = 0;
    	for (Int i = 0,x;i < n;++ i) scanf ("%1d",&x),s = (s << 1) | x;
    	return s;
    }
    
    void ins (ll x){
    	to[++ cnt] = x,nxt[cnt] = head[x % mod],head[x % mod] = cnt;
    }
    
    void add (ll x){
    	for (Int i = head[x % mod];i;i = nxt[i])
    		if (to[i] == x) return ;
    	ins (x),q[++ t] = x;
    }
    
    void BFS (ll S,ll T){
    	h = 1,t = cnt = 0;
    	memset (head,0,sizeof (head));
    	for (Int i = 1;i <= k;++ i) ins (a[i]);
    	add (S);
    	while (h <= t && t <= n * k){
    		ll now = q[h ++];
    		if (now == T) puts ("TAK"),exit (0);
    		for (Int i = 0;i < n;++ i) add (now ^ (1ll << i));
    	}
    	if (t <= n * k) puts ("NIE"),exit (0);
    }
    
    signed main(){
    	read (n,k);ll S = getins (),T = getins ();
    	for (Int i = 1;i <= k;++ i) a[i] = getins ();
    	BFS (S,T),BFS (T,S);
    	puts ("TAK"); 
    	return 0;
    }
    
  • 相关阅读:
    在阿里云上遇见更好的Oracle(三)
    从传统IT快速走向公共云计算
    在阿里云上遇见更好的Oracle(二)
    Oracle 11g 审计跟踪管理
    在阿里云上遇见更好的Oracle(一)
    Elasticsearch中的DocValues
    初识Django —Python API接口编程入门
    为什么mysqld启动报错
    云计算产品的四件套
    说说云计算中的地域和可用区概念
  • 原文地址:https://www.cnblogs.com/Dark-Romance/p/13635505.html
Copyright © 2011-2022 走看看