Codeforces 388B Fox and Minimal path(构造)
来源:互联网 发布:邳州网络直通车 编辑:程序博客网 时间:2024/05/18 15:04
题意:
给出一个数字k,要求你构造一张无向图使得点1到点2的最短路径恰好有k条
首先将k二进制化,然后看图就明白怎么构造了:
拿k=7来说
首先构造出最大的2的指数级部分,然后接下来在此链上继续并联一些点
#include<cstring>#include<cstdio>#include<algorithm>#include<iostream>#include<map>using namespace std;map<int,int>mp;int pw[30];char g[2005][2005];int n;int len;int cnt;void F(int k){ ++cnt; g[1][cnt]=g[cnt][1]='Y'; mp[0]=3; for(int i=1; i<=k; i++) { g[cnt+1][cnt]=g[cnt][cnt+1]='Y'; g[cnt+2][cnt]=g[cnt][cnt+2]='Y'; g[cnt+3][cnt+1]=g[cnt+1][cnt+3]='Y'; g[cnt+3][cnt+2]=g[cnt+2][cnt+3]='Y'; cnt+=3; mp[i]=cnt; } g[cnt][2]=g[2][cnt]='Y';}void F2(int k){ int st=mp[k]; k<<=1; while(k<len*2) { g[cnt+1][st]=g[st][cnt+1]='Y'; st=++cnt; k++; } g[st][2]=g[2][st]='Y';}int main(){ pw[0]=1; for(int i=1; i<=30; i++) pw[i]=pw[i-1]*2; memset(g,'N',sizeof g); scanf("%d",&n); cnt=2; for(int i=30; i>=0; i--) { if(n>=pw[i]) { len=i; F(i); n-=pw[i]; break; } } for(int i=30; i>=0; i--) { if(n>=pw[i]) { F2(i); n-=pw[i]; } } printf("%d\n",cnt); for(int i=1; i<=cnt; i++) { for(int j=1; j<=cnt; j++) { printf("%c",g[i][j]); } puts(""); } return 0;}
0 0
- Codeforces 388B Fox and Minimal path(构造)
- Codeforces 388B Fox and Minimal path(构造)
- codeforces 388B Fox and Minimal path
- CodeForces 388B Fox and Minimal path
- Codeforces B. Fox and Minimal path
- Codeforces 388B Fox and Minimal path(构造最短路条数为N的图)
- Codeforces 388B Fox and Minimal path(构造最短路条数为N的图)
- Codeforces 388B Fox and Minimal path 构图
- Codeforces Round #228 (Div. 1)-B-Fox and Minimal path
- Codeforces Round #228 Div1 B Fox and Minimal path
- Codeforces Round #228 (Div. 1) B. Fox and Minimal path
- Codeforces 389D Fox and Minimal path【构造+二进制思维】好题!
- Codeforces 389D Fox and Minimal path【构造+二进制思维】好题!
- cf 389D Fox and Minimal path 【构造】
- Codeforces Round #228 (Div. 2) D - Fox and Minimal path
- Codeforces #228 D2D / D1B:Fox and Minimal path
- CF 好题集锦 PART 0 & #388 B Fox and Minimal path 题解
- CodeForces 510 B. Fox And Two Dots(DFS)
- WWDC之优化App启动速度
- 待转移
- Android通用的EmptyLayout-展示不用状态的界面
- jquery ajax 同步异步的执行
- 曲线平滑-B样条曲线
- Codeforces 388B Fox and Minimal path(构造)
- 数据库理论(2)之数据库事务
- 界面对应字段,绑定数据到gridview 显示 及删除功能 窗体事件 分页及键
- 子类,父类默认构造函数及带参构造函数的调用
- VI操作--跳到最后一行和跳到最后一行的最后一个字符
- 总结下最近Android混合开发的种种
- Java 4种数组复制方式的性能比较
- Extjs4 封装echarts组件 2016.8.31
- Matlab计算机视觉/图像处理工具箱推荐