博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
codeforces 395 B1. iwiwi(待续)
阅读量:4034 次
发布时间:2019-05-24

本文共 3700 字,大约阅读时间需要 12 分钟。

1、

2、题目:

B1. iwiwi
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

The Codeforces users sometimes have very interesting handles! For example, you can meet a grandmaster from Japan namediwiwi or an international grandmaster from Taiwan by name0O0o00OO0Oo0o0Oo.

To be honest, Polycarpus prefers handle iwiwi to0O0o00OO0Oo0o0Oo.

Polycarpus noticed that in many fonts the width of letter w is exactly twice wider that the width of letter i. Now he wants to write all sorts of strings containing letters i and w on a board exactly as wide asn letters i. He doesn't want the problem to be too easy, so Polycarpus added another limit: each consequence string must be different from the previous one:

  • either by replacing two consecutive letters i by one letterw,
  • or be replacing letter w by two consecutive lettersi.

For example, string iii can follow after stringiw, as the second string results after replacingw by ii in the first one. Stringwi can follow after string iii, as it is obtained by replacing ii byw.

Help Polycarpus, print all strings of width of exactly n letters i in the described manner. For each pair of consecutive strings there must be exactly one replacement by exactly one of the given rules. The written sequence doesn't have to be cycled, that is, the first string isn't considered consequent for the last string.

Input

The single line of the input contains a positive integer n. The limits for n are different for the subproblems:

  • for subproblem B1, the following inequation fulfills 1 ≤ n ≤ 5,
  • for subproblem B2, the following inequation fulfills 1 ≤ n ≤ 20.
Output

Print all strings of letters i and w, such that i + 2w = n, wherei — the number of letters i, and w — the number of letters w. Print the strings in the order that is described in the problem.

If there are many answers, print any of them.

Sample test(s)
Input
3
Output
iwiiiwi

 

3、wrong answer

#include
#include
#include
using namespace std;int main(){ int n; while(scanf("%d",&n)!=EOF) { int i=1; int w=(n-i)/2; int flag=(n-i)%2; printf("i"); for(int j=1; j<=w; j++) printf("w"); if(flag) printf("i"); printf("\n"); // printf("***********\n"); for(int k=1; k<=w; k++) { printf("i"); for(int j=1; j<=k; j++) printf("ii"); for(int j=k+1; j<=w; j++) printf("w"); if(flag) printf("i"); printf("\n"); } for(int k=1; k<=n/2; k++) { for(int j=1; j<=k; j++) printf("w"); for(int p=1; p<=n-k*2; p++) printf("i"); printf("\n"); } for(int k=1; k<=(n-1)/2; k++) { if(n/2-k>0) { for(int j=1; j<=k; j++) printf("ii"); for(int j=1; j<=n/2-k; j++) printf("w"); if(n%2==1) printf("i"); printf("\n"); } } } return 0;}

 4、附AC代码:(参见网上代码)

#include 
#include
#include
#include
#include
#include
using namespace std;vector
vs[30];int main(){ vs[1].push_back("i"); vs[2].push_back("ii"); vs[2].push_back("w"); int n; scanf("%d",&n); if(n==1) puts("i"); else if(n==2) puts("ii\nw"); else { int s; for(int i=3;i<=n;i++) { s=vs[i-1].size(); for(int j=s-1;j>=0;j--) { vs[i].push_back("i"+vs[i-1][j]); } s=vs[i-2].size(); for(int j=s-1;j>=0;j--) { vs[i].push_back("w"+vs[i-2][j]); } } s=vs[n].size(); for(int i=0;i

 

转载地址:http://xwcdi.baihongyu.com/

你可能感兴趣的文章
C语言位扩展
查看>>
linux dump_backtrace
查看>>
linux irqdebug
查看>>
git 常用命令
查看>>
linux位操作API
查看>>
uboot.lds文件分析
查看>>
uboot start.s文件分析
查看>>
没有路由器的情况下,开发板,虚拟机Ubuntu,win10主机,三者也可以ping通
查看>>
本地服务方式搭建etcd集群
查看>>
安装k8s Master高可用集群
查看>>
忽略图片透明区域的事件(Flex)
查看>>
忽略图片透明区域的事件(Flex)
查看>>
AS3 Flex基础知识100条
查看>>
Flex动态获取flash资源库文件
查看>>
flex中设置Label标签文字的自动换行
查看>>
Flex 中的元数据标签
查看>>
flex4 中创建自定义弹出窗口
查看>>
01Java基础语法-11. 数据类型之间的转换
查看>>
01Java基础语法-13. if分支语句的灵活使用
查看>>
01Java基础语法-15.for循环结构
查看>>