Securing the Barn poj
来源:互联网 发布:大数据性能 编辑:程序博客网 时间:2024/04/30 10:20
Securing the Barn
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 1860 Accepted: 1191
Description
Farmer John has installed a new security system on the barn and now must issue a valid password to the cows in the herd. A valid password consists of L (3 <= L <= 15) different lower-case characters (from the traditional latin character set 'a'...'z'), has at least one vowel ('a', 'e', 'i', 'o', or 'u'), at least two consonants (non-vowels), and has characters that appear in alphabetical order (i.e., 'abc' is valid; 'bac' is not).
Given a desired length L along with C lower-case characters, write a program to print all the valid passwords of length L that can be formed from those letters. The passwords must be printed in alphabetical order, one per line.
Given a desired length L along with C lower-case characters, write a program to print all the valid passwords of length L that can be formed from those letters. The passwords must be printed in alphabetical order, one per line.
Input
* Line 1: Two space-separated integers, L and C
* Line 2: C space-separated lower-case characters that are the set of characters from which to build the passwords
* Line 2: C space-separated lower-case characters that are the set of characters from which to build the passwords
Output
* Lines 1..?: Each output line contains a word of length L characters (and no spaces). The output lines must appear in alphabetical order.
Sample Input
4 6a t c i s w
Sample Output
acisacitaciwacstacswactwaistaiswaitwastwcistciswcitwistw
Hint
INPUT DETAILS:
Passwords of length 4 chosen from the given six characters
Passwords of length 4 chosen from the given six characters
Source
USACO 2005 November Bronze
从六个里选四个字母 需至少1个元音字母,两个辅音字母
这道题没什么好解释的~
code:
#include<iostream>#include<algorithm>using namespace std;int num,l,yz,fz,index,len;char a[27];int vis[27];void dfs(int index,int len,int yz,int fz){ if (len==num&&yz>=1&&fz>=2) { for (int i=0; i<l; i++) if (vis[i]) cout<<a[i]; cout<<endl; return ; } for (int i=index; i<l; i++) { if (a[i]=='a'||a[i]=='e'||a[i]=='i'||a[i]=='o'||a[i]=='u') { vis[i]=1; dfs(i+1,len+1,yz+1,fz); vis[i]=0; } else { vis[i]=1; dfs(i+1,len+1,yz,fz+1); vis[i]=0; } }}int main(){ cin>>num>>l; for (int i=0; i<l; i++) { cin>>a[i]; vis[i]=0; } sort(a,a+l); dfs(0,0,0,0); return 0;}
- Securing the Barn poj
- POJ 3049 Securing the Barn 笔记
- Securing the Barn(dfs)
- 3049-Securing the Barn ====dfs
- Securing the Information Infrastructure
- Securing the Deep Learning Stack
- poj 3168 Barn Expansion 排序
- SSL & TLS Essentials: Securing the Web
- Administering and Securing the Apache Server
- 7 Managing Users and Securing the Database
- barn
- poj 3269 Building A New Barn
- poj 3168 Barn Expansion 几何yy
- POJ 3168 Barn Expansion(几何啊 )
- POJ 3168 Barn Expansion (几何+排序)
- POJ 3168 Barn Expansion (平面扫描)
- POJ 3168 Barn Expansion (平面扫描)
- POJ 3168 Barn Expansion 已翻译
- 深入理解ANDROID消息处理系统——LOOPER、HANDLER、THREAD
- HDU 1754 线段树
- oracle保存小数点前为"0"的问题
- jquery正则表达式验证
- 黑马程序员:Java中的修饰符
- Securing the Barn poj
- NGUI控件如何接受消息
- linux下常用FTP命令
- Centos 6.4的Minimal下配置网络,设置IP(食用菌百科网站长提供)
- 倒计时自动跳转页面
- poj1704(变形Nim博弈)
- 这样解决浏览器不兼容问题
- hdu 2795 Billboard
- Android Binder设计与实现 – 设计篇