Beautiful IP Addresses

Time Limit: 2000ms
Memory Limit: 262144KB

This problem will be judged on CodeForces. Original ID: 292C
64-bit integer IO format: %I64d      Java class name: (Any)

 
The problem uses a simplified TCP/IP address model, please read the statement carefully.

An IP address is a 32-bit integer, represented as a group of four decimal 8-bit integers (without leading zeroes), separated by commas. For example, record 0.255.1.123 shows a correct IP address and records 0.256.1.123 and 0.255.1.01 do not. In the given problem an arbitrary group of four 8-bit integers is a correct IP address.

Our hero Polycarpus still works as a system administrator in some large corporation. He likes beautiful IP addresses. To check if some IP address is beautiful, he should do the following:

  1. write out in a line four 8-bit numbers of the IP address, without the commas;
  2. check if the resulting string is a palindrome.

Let us remind you that a palindrome is a string that reads the same from right to left and from left to right.

For example, IP addresses 12.102.20.121 and 0.3.14.130 are beautiful (as strings "1210220121" and "0314130" are palindromes), and IP addresses 1.20.20.1 and 100.4.4.1 are not.

Polycarpus wants to find all beautiful IP addresses that have the given set of digits. Each digit from the set must occur in the IP address at least once. IP address must not contain any other digits. Help him to cope with this difficult task.

Input

The first line contains a single integer n (1 ≤ n ≤ 10) — the number of digits in the set. The second line contains the set of integers a1, a2, ..., an(0 ≤ ai ≤ 9). It is guaranteed that all digits in the set are distinct.

 

Output

In the first line print a single integer k — the number of beautiful IP addresses that contain the given set of digits. In the following k lines print the IP addresses, one per line in the arbitrary order.

 

Sample Input

Input
6
0 1 2 9 8 7
Output
6
78.190.209.187
79.180.208.197
87.190.209.178
89.170.207.198
97.180.208.179
98.170.207.189
Input
1
4
Output
16
4.4.4.4
4.4.4.44
4.4.44.4
4.4.44.44
4.44.4.4
4.44.4.44
4.44.44.4
4.44.44.44
44.4.4.4
44.4.4.44
44.4.44.4
44.4.44.44
44.44.4.4
44.44.4.44
44.44.44.4
44.44.44.44

Source

 
解题:此题不仅繁琐,而且蛋疼!过滤规则约束难搞。。。。
 
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#define LL long long
#define INF 0x3f3f3f
using namespace std;
int bit[],n,tot,cnt;
bool vis[];
char temp[][],s[];
char ans[][],ss[];
void dfs(int cur,int deep,int kind) {
if(cur >= deep) {
if(kind == n) {
s[cur] = '\0';
strcpy(temp[cnt],s);
cnt++;
}
return;
}
for(int i = ; i < n; i++) {
s[cur] = bit[i]+'';
if(vis[i]) {
dfs(cur+,deep,kind);
} else {
vis[i] = true;
dfs(cur+,deep,kind+);
vis[i] = false;
}
}
}
void dfs2(char *s,int cur,int p,int len) {
int i,j,k,sum = ,slen = strlen(s);
if(cur == ) {
if(p < slen) {
for(i = p; i < slen; i++)
sum = sum*+s[i]-'';
if(sum > ) return;
if(s[p] == '' && slen-p > ) return;
ss[len] = '.';
for(i = p; i < slen; i++)
ss[len++i-p] = s[i];
ss[len++i-p] = '\0';
strcpy(ans[tot++],ss+);
}
return;
}
for(i = p; i < slen; i++) {
sum = sum* + s[i]-'';
if(sum > ) break;
ss[len] = '.';
if(s[p] == '' && i-p > ) break;
for(j = p; j <= i; j++)
ss[len++j-p] = s[j];
dfs2(s,cur+,i+,len++j-p);
}
}
void go(int index) {
char s[];
int i,j,len;
strcpy(s,temp[index]);
len = strlen(temp[index]);
for(i = len-,j = len; i >= ; i--,j++)
s[j] = s[i];
s[j] = '\0';
dfs2(s,,,);
for(i = len-,j = len; i >= ; i--,j++)
s[j] = s[i];
s[j] = '\0';
dfs2(s,,,);
}
int main() {
int i;
while(~scanf("%d",&n)) {
for(i = ; i < n; i++)
scanf("%d",bit+i);
tot = cnt = ;
memset(vis,false,sizeof(vis));
for(i = ; i <= ; i++) dfs(,i,);
for(i = ; i < cnt; i++) go(i);
printf("%d\n",tot);
for(i = ; i < tot; i++)
printf("%s\n",ans[i]);
}
return ;
}

xtu summer individual-4 A - Beautiful IP Addresses的更多相关文章

  1. 292C Beautiful IP Addresses

    传送门 题目 The problem uses a simplified TCP/IP address model, please read the statement carefully. An I ...

  2. 【leetcode】Restore IP Addresses

    Restore IP Addresses Given a string containing only digits, restore it by returning all possible val ...

  3. 保留ip: Reserved IP addresses

    Reserved IP addresses From Wikipedia, the free encyclopedia     In the Internet addressing architect ...

  4. 93. Restore IP Addresses

    题目: Given a string containing only digits, restore it by returning all possible valid IP address com ...

  5. 93.Restore IP Addresses(M)

    93.Restore IP Addresses Medium 617237FavoriteShare Given a string containing only digits, restore it ...

  6. 亚马逊 AWS ip反向解析:Configurable Reverse DNS for Amazon EC2’s Elastic IP Addresses

    I’d like to call your attention to a new feature that we rolled out earlier this month. You can now ...

  7. "cni0" already has an IP address different from 10.244.2.1/24。 Error while adding to cni network: failed to allocate for range 0: no IP addresses available in range set: 10.244.2.1-10.244.2.254

    "cni0" already has an IP address different from 10.244.2.1/24. Error while adding to cni n ...

  8. IP addresses in C#

    在.Net网络库里面最大的优点就是IP地址和端口被成对处理,相比于UNIX中用的方法真是一个巨大的令人欢迎的进步..NET定义了两个类来处理关于IP地址的问题. One of the biggest ...

  9. 【LeetCode】93. Restore IP Addresses

    Restore IP Addresses Given a string containing only digits, restore it by returning all possible val ...

随机推荐

  1. 题解报告:Luogu P3368 【模板】树状数组 2(区间修改,单点查询)

    题目描述 如题,已知一个数列,你需要进行下面两种操作: 1.将某区间每一个数数加上x 2.求出某一个数的和 输入输出格式 输入格式: 第一行包含两个整数N.M,分别表示该数列数字的个数和操作的总个数. ...

  2. how-to-fix-fs-re-evaluating-native-module-sources-is-not-supported-graceful

    http://stackoverflow.com/questions/37346512/how-to-fix-fs-re-evaluating-native-module-sources-is-not ...

  3. iOS 集成银联支付(绕过文档的坑,快速集成)-转

    本文是投稿文章,作者:南栀倾寒当初集成支付宝的时候,觉得见了这么丑的代码,加上这么难找的下载地址,在配上几乎为零的文档,寒哥就要吐血了. 下午去集成银联,才知道血吐的早了. 下载地址:https:// ...

  4. SpringMVC的简单传值

    之前学习SpringMVC时感觉他的传值很神奇:简便,快捷,高效. 今天写几个简单的传值与大家分享,希望能对大家有帮助. 一. 从后往前传: (1) @Controller @RequestMappi ...

  5. Android BitmapFactory.decodeFile(filePath, options) 返回 Null 6.0权限

    今天在做拍照上传的时候遇到个问题,根据路径获取Bitmap 失败,一直返回空,以为这个路径获取Bitmap代码久经考验,不怀疑它,找参数传入是否正确,初步怀疑是 filePath 没传进去,打印 fi ...

  6. Thinkphp3.23 连接MSSQL方法

    Thinkphp 3.23要连接MSSQL,必须配置下,以下是主要的步骤. 1.要安装Microsoft Drivers for PHP for SQL Server驱动 下载驱动以前,要查看一下ph ...

  7. php中 mysql 插入特殊字符(手机端的emoji表情)出现异常

    今天在用mysql存储从微信服务器拉来的数据,出现插入数据异常,报 Incorrect string value: '\xF0\x9F\x98\x97\xF0\x9F 的错误. 最终在网上查了一下,有 ...

  8. 用pycharm+django开发web项目

    pycharm是python的一个商业的集成开发工具,本人感觉做python开发还是很好用的,django是一个很流行的python web开源框架,本文就是使用pycharm+django来开发py ...

  9. Android Studio中找出不再使用的资源

    顶部Analyze菜单中选择Run Inspection by Name 在弹出的输入框中输入unused resources

  10. idea 部署struts所遇到的问题\

    1.org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter 加载失败 解决方法:下载struts2 的源码包,然后将D:\ ...