Codeforces 388B Fox and Minimal path(构造)

2014-11-24 08:46:01 · 作者: · 浏览: 0

题目链接:Codeforces 388B Fox and Minimal path


题目大意:给出k,要求构建一张图,从点1到达点2的最短路径有k条。


解题思路:二进制数差分,因为没有要求说节点尽量少,所以直接构造出初始图,当k >= (1<


#include 
  
   
#include 
   
     const int N = 105; int g[N][N]; inline void set (int x, int y) { g[x][y] = g[y][x] = 1; } void init () { memset(g, 0, sizeof(g)); set(1, 3); set(1, 4); set(2, 100); for (int i = 3; i < 60; i += 2) { set(i, i+2); set(i, i+3); set(i+1, i+2); set(i+1, i+3); } for (int i = 63; i < 100; i++) set(i, i+1); } void solve () { int k; scanf("%d", &k); for (int i = 30; i; i--) if (k >= (1<