cf 389D Fox and Minimal path 【构造】
来源:互联网 发布:网络规划设计师有用吗 编辑:程序博客网 时间:2024/05/23 01:15
点击打开链接
题意:
给你一个整数n,让你构造一个地图,该地图包含n个顶点,要求你构造的地图顶点1->顶点2 的最短路条数为n。
题解:
已知n可以拆成二进制形式。
那么我们可以很容易先构造一个2^31条最短路的地图,接下来再构造一条长度为31的最短路。
接下来按n的二进制位数在个地图和路上连边即可,
#include<bits/stdc++.h>using namespace std;const int maxn=1005;int ma[maxn][maxn];int n;int bit[50];int fac(int x){ int cnt=0; while(x){ bit[++cnt]=x%2; x/=2; } return cnt;}void unicom(int u,int v){ ma[u][v]=ma[v][u]=1;}int main(){ scanf("%d",&n); int len=fac(n); int pos=3; unicom(1,3); unicom(1,4); for(int i=1;i<=32;++i){ unicom(pos,pos+2); unicom(pos,pos+3); unicom(pos+1,pos+2); unicom(pos+1,pos+3); pos+=2; } int beg=pos+2; pos+=2; for(int i=1;i<=31;++i){ unicom(pos,pos+1); pos++; } unicom(2,pos); if(bit[1]) unicom(1,beg); beg+=2; int t=5; for(int i=2;i<=len;++i){ if(bit[i]){ unicom(beg,t); } beg++; t+=2; } puts("100"); for(int i=1;i<=100;++i){ for(int j=1;j<=100;++j){ if(ma[i][j])printf("%c",'Y'); else printf("%c",'N'); }puts(""); } return 0;}
阅读全文
0 0
- cf 389D Fox and Minimal path 【构造】
- Codeforces 389D Fox and Minimal path【构造+二进制思维】好题!
- Codeforces 389D Fox and Minimal path【构造+二进制思维】好题!
- Codeforces 388B Fox and Minimal path(构造)
- Codeforces 388B Fox and Minimal path(构造)
- Codeforces Round #228 (Div. 2) D - Fox and Minimal path
- CF 好题集锦 PART 0 & #388 B Fox and Minimal path 题解
- codeforces 388B Fox and Minimal path
- Codeforces B. Fox and Minimal path
- CodeForces 388B Fox and Minimal path
- CF D. Fox And Jumping
- Codeforces 388B Fox and Minimal path(构造最短路条数为N的图)
- Codeforces 388B Fox and Minimal path(构造最短路条数为N的图)
- Codeforces Round #228 (Div. 1)-B-Fox and Minimal path
- Codeforces #228 D2D / D1B:Fox and Minimal path
- Codeforces Round #228 Div1 B Fox and Minimal path
- Codeforces 388B Fox and Minimal path 构图
- Codeforces Round #228 (Div. 1) B. Fox and Minimal path
- 简明YAML教程
- C++个人编程标准(字符、指针、字符串)
- 用JS实现系统登录页的登录和验证
- Connection: close(http协议短链接)和Connection: keep-alive(http协议长链接)有什么区别?
- JSP九大内置对象的作用和用法总结
- cf 389D Fox and Minimal path 【构造】
- 数据结构(c语言)线性表-顺序表
- GPIO Product Guide笔记(Xilinx)
- 1006.换个格式输出整数(字符串处理)
- 使用一个数组实现两个栈
- 13 java里的tcp网络编程
- 技术积累 — 加权平均值滤波算法
- ReentrantReadWriteLock
- javascript 对象的理解