Skip to main content
  1. Posts/

hust2015暑假集训 0713 A a dangerous trip

·1 min
Note: This article is available in Chinese only. 本文暂无英文版本。 View original

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82557#problem/A

Zk的解法:拆点,把每一个点存成两份,r[i]和r[n+i]

连边的时候如果u和v相连,我们就分别连 u&&v; 和 u+n&&v;+n 和 u&&v;+n 其中最后一个存法是要使用魔法的情况…

最后求从1到n+n的最短路径即可

如图

斜着的边表示使用魔法的情况。

由1到n+n,只经过一次斜边,这是与题干中只使用一次魔法相对应的….

由于权值变成一半可能出现浮点数…

我们不妨先 权值先整体*2

最后结果的时候再/2

zk好聪明(逃)

然后还有一种是鲍佳学长的dp思想的算法…..

http://www.cnblogs.com/chensunrise/p/3721427.html

然而dp渣…..

Related

cf 556C Case of Matryoshkas

·1 min
http://codeforces.com/contest/556/problem/C 果然一晚上不睡觉会导致读错题么… 需要注意的是 如果有一个是 1 2 4 6 那么 1,2是不必拆开的….

最大连续区间和的算法总结

·2 mins
最大连续区间和是一个经典的问题。给定一个长度为 n 的序列 a[1],a[2]…a[n-1],a[n],求一个连续的子序列 a[i],a[i+1]…a[j-1],a[j],使得 a[i]+a[i+1]…a[j-1]+a[j]最大。

cf 535B Tavas and SaDDas

·1 min
B. Tavas and SaDDas time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn’t stop doing that. That’s why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas’ headphones and told him: “If you solve the following problem, I’ll return it to you.”

poj 3278 catch that cow

·1 min
http://poj.org/problem?id=3278 bfs,用到了stl的queue 1 2 3 /* *********************************************** 4 Author :111qqz 5 Created Time :2016年02月19日 星期五 15时45分05秒 6 File Name :3278.cpp 7 ************************************************ */ 8 9 #include <algorithm> 10 #include <cstdio> 11 #include <iostream> 12 #include <cstring> 13 #include <string> 14 #include <cmath> 15 #include <map> 16 #include <stack> 17 #include <queue> 18 19 using namespace std; 20 typedef long long LL; 21 const int inf = 8E8; 22 const int N=2E5+7; 23 int d[N]; 24 int n,k; 25 void bfs() 26 { 27 queue<int> q; 28 memset(d,-1,sizeof(d)); 29 q.push(n); 30 d[n]=0; 31 while (!q.empty()) 32 { 33 int x = q.front(); 34 q.pop(); 35 if ( x==k ) 36 { 37 break; 38 } 39 int next[10]; 40 next[1]=x-1; 41 next[2]=x+1; 42 next[3]=2*x; 43 for ( int i = 1; i <= 3 ; i++ ) 44 { 45 if (next[i]>=0&&next[i]<=100000&&d[next[i]]==-1) 46 { 47 d[next[i]]=d[x]+1; 48 q.push(next[i]); 49 } 50 } 51 } 52 53 54 } 55 int main() 56 { 57 while (scanf("%d %d",&n,&k)!=EOF) 58 { 59 bfs(); 60 cout<<d[k]<<endl; 61 } 62 return 0; 63 }