B. Fox and Minimal path

题目连接:

http://codeforces.com/contest/388/problem/B

Description

Fox Ciel wants to write a task for a programming contest. The task is: "You are given a simple undirected graph with n vertexes. Each its edge has unit length. You should calculate the number of shortest paths between vertex 1 and vertex 2."

Same with some writers, she wants to make an example with some certain output: for example, her birthday or the number of her boyfriend. Can you help her to make a test case with answer equal exactly to k?

Input

The first line contains a single integer k (1 ≤ k ≤ 109).

Output

You should output a graph G with n vertexes (2 ≤ n ≤ 1000). There must be exactly k shortest paths between vertex 1 and vertex 2 of the graph.

The first line must contain an integer n. Then adjacency matrix G with n rows and n columns must follow. Each element of the matrix must be 'N' or 'Y'. If Gij is 'Y', then graph G has a edge connecting vertex i and vertex j. Consider the graph vertexes are numbered from 1 to n.

The graph must be undirected and simple: Gii = 'N' and Gij = Gji must hold. And there must be at least one path between vertex 1 and vertex 2. It's guaranteed that the answer exists. If there multiple correct answers, you can output any of them.

Sample Input

2

Sample Output

4

NNYY

NNYY

YYNN

YYNN

Hint

题意

你需要构造一个图,使得1到2的最短路恰好有k条

题解:

拆成二进制,比如9 = 20+23

二进制的最短路就非常好构造,就2*2*2这样去构造就好了

然而这样裸的构造的话,点数可能会超过1000个点

所以你再压缩一下点的个数,复用一下就好了

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 3200;
int mp[maxn][maxn];
int k,bit[32],tot=3,max_len;
int getid()
{
return tot++;
}
int main()
{
scanf("%d",&k);
int id1=1,id2=1,id3=getid();
while(k)
{
if(k%2)mp[id1][id3]=1,mp[id2][id3]=1;
k/=2;if(k==0)break;
int id4=getid(),id5=getid(),id6=getid();
mp[id1][id4]=1,mp[id1][id5]=1;
mp[id2][id4]=1,mp[id2][id5]=1;
mp[id3][id6]=1;
id1=id4,id2=id5,id3=id6;
}
mp[id3][2]=1;
int Max = getid()-1;
printf("%d\n",Max);
for(int i=1;i<=Max;i++,cout<<endl)for(int j=1;j<=Max;j++)
if(mp[i][j]||mp[j][i])printf("Y");else printf("N");
}

Codeforces Round #228 (Div. 1) B. Fox and Minimal path 构造的更多相关文章

  1. Codeforces Round #228 (Div. 1) 388B Fox and Minimal path

    链接:http://codeforces.com/problemset/problem/388/B [题意] 给出一个整数K,构造出刚好含有K条从1到2的最短路的图. [分析] 由于是要自己构造图,当 ...

  2. Codeforces Round #228 (Div. 1) C. Fox and Card Game 博弈

    C. Fox and Card Game 题目连接: http://codeforces.com/contest/388/problem/C Description Fox Ciel is playi ...

  3. Codeforces Round #228 (Div. 1) A. Fox and Box Accumulation 贪心

    A. Fox and Box Accumulation 题目连接: http://codeforces.com/contest/388/problem/A Description Fox Ciel h ...

  4. Codeforces Round #228 (Div. 2) C. Fox and Box Accumulation(贪心)

    题目:http://codeforces.com/contest/389/problem/C 题意:给n个箱子,给n个箱子所能承受的重量,每个箱子的重量为1: 很简单的贪心,比赛的时候没想出来.... ...

  5. Codeforces Round #228 (Div. 2) C. Fox and Box Accumulation

    C. Fox and Box Accumulation time limit per test 1 second memory limit per test 256 megabytes input s ...

  6. Codeforces Round #228 (Div. 2) B. Fox and Cross

    #include <iostream> #include <string> #include <vector> #include <algorithm> ...

  7. Codeforces Round #228 (Div. 2) A. Fox and Number Game

    #include <iostream> #include <algorithm> #include <vector> #include <numeric> ...

  8. Codeforces Round #228 (Div. 2)

    做codeforces以来题目最水的一次 A题: Fox and Number Game 题意:就是用一堆数字来回减,直到减到最小值为止,再把所有最小值加,求这个值 sol: 简单数论题目,直接求所有 ...

  9. Codeforces Round #228 (Div. 1) B

    B. Fox and Minimal path time limit per test 1 second memory limit per test 256 megabytes input stand ...

随机推荐

  1. WindowsServer2003双网卡配置

    今天突然被问起,找资料10+分钟才找到记录,因此再次记录下: route -p delete 0.0.0.0 route -p add 0.0.0.0 mask 0.0.0.0 58.240.115. ...

  2. git checkout 命令详解【转】

    转自:http://www.cnblogs.com/hutaoer/archive/2013/05/07/git_checkout.html 在日常的git操作中,git checkout——检出,是 ...

  3. aarch64_l2

    libfreehand-devel-0.1.1-5.fc26.aarch64.rpm 2017-05-23 07:16 26K fedora Mirroring Project libfreehand ...

  4. MySQL分页存储过程

    CREATE PROCEDURE ProcPage(in tableName varchar(20),#表名  in showField varchar(100),#要显示的列名  in whereT ...

  5. 在VirtualBox上安装Ubuntu

    Windows 10家庭中文版,VirtualBox 5.2.12 r122591,Ubuntu ubuntu-18.04-desktop, 前言 很久没用过Linux类的操作系统了,上一次是好多年前 ...

  6. Web Api - HttpMessageHandler 学习

    参考: 1.http://www.cnblogs.com/chenboyi081/p/4995252.html 2.http://www.cnblogs.com/r01cn/archive/2012/ ...

  7. 【笔记】jQuery插件开发指南

    原文链接:http://www.cnblogs.com/Wayou/p/jquery_plugin_tutorial.html (有部分增删和修改) jQuery插件开发模式 软件开发过程中是需要一定 ...

  8. jquery 绑定,mvc和webform的三种方式

    asp.net里的绑定方式,on的绑定方式无效 $('#SelCommandType').bind('click', function () { }); mvc里的绑定方式 $('#DownList' ...

  9. CVE-2010-2553 Microsoft Windows Cinepak 编码解码器解压缩漏洞 分析

      Microsoft Windows是微软发布的非常流行的操作系统.         Microsoft Windows XP SP2和SP3,Windows Vista SP1和SP2,以及Win ...

  10. CCF CSP 201503-3 节日

    CCF计算机职业资格认证考试题解系列文章为meelo原创,请务必以链接形式注明本文地址 CCF CSP 201503-3 节日 问题描述 有一类节日的日期并不是固定的,而是以“a月的第b个星期c”的形 ...