Shorten IPv6 Address
题意:转换一个128位的二进制串,变成16进制,并且格式为x:x:x:x:x:x:x:x然后多个相邻的0变成::,且只有一个::,求变成的字典序最小且最短的字符串。
思路:大水题,但是就是一直wa,思路都一样的还是wa。先将二进制转化为十进制,然后用%x输出,因为连续的0可变短,但有优先级,首先选0长的,然后如果长度相等,先选中间,中间里面先选中间偏后,然后是最后,最后是前面。差不多就这意思吧。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#define ll long long
using namespace std;
const int N = + ;
char s[N];int a[], r[];
int main() {
int T;
scanf("%d", &T);
for (int tii = ; tii <= T; tii++) {
scanf("%s", s + );
for (int i = ; i <= ; i++) {
a[i] = ;
for (int j = ; j <= ; j++) {
a[i] = a[i] * + s[(i - ) * + j] - '';
}
}
memset(r, , sizeof(r));
printf("Case #%d: ", tii);
int id = ;
for (int i = ; i > ; i--) {
if (a[i] == ) r[i] = r[i + ] + ;
if (r[id] < r[i]) id = i;
if (r[id] == r[i] && r[id] + id - == && i != ) id = i;
} for (int i = ; i <= ; i++) {
if (id == i && r[i] >= ) {
if (id == )
printf(":");
printf(":");
i += r[id] - ;
}
else {
printf("%x", a[i]);
if (i != )
printf(":");
}
}
printf("\n");
}
return ;
}
Shorten IPv6 Address的更多相关文章
- 2019牛客多校第六场 B - Shorten IPv6 Address 模拟
B - Shorten IPv6 Address 题意 给你\(128\)位的二进制,转换为十六进制. 每\(4\)位十六进制分为\(1\)组,每两组用一个\(":"\)分开. 每 ...
- 牛客多校第六场 B Shorten IPv6 Address 模拟
题意: 给你一个二进制表示的IPv6地址,让你把它转换成8组4位的16进制,用冒号分组的表示法.单组的前导0可以省略,连续多组为0的可以用两个冒号替换,但是只允许替换一次.把这个地址通过这几种省略方式 ...
- 2019 牛客多校第六场 B Shorten IPv6 Address
题目链接:https://ac.nowcoder.com/acm/contest/886/B 题目大意 给定一个 128 位的二进制 ip 地址,让你以 16 位一组,每组转成 16 进制,用冒号连接 ...
- Convert IPv6 Address to IP numbers (C#)
URL: http://lite.ip2location.com/ Use the code below to convert the IP address of your web visitors ...
- IPv6 tutorial 4 IPv6 address syntax
https://4sysops.com/archives/ipv6-tutorial-part-4-ipv6-address-syntax/ Now that you know about the n ...
- How to support both ipv4 and ipv6 address for JAVA code.
IPv6 have colon character, for example FF:00::EEIf concatenate URL String, IPv6 URL will like: http: ...
- [题解]Shorten IPv6 Address-模拟(2019牛客多校第六场B题)
题目链接:https://ac.nowcoder.com/acm/contest/886/B 题意: 您将获得一个IPv6地址,该地址是128位二进制字符串.请根据以下规则确定其最短的表示: 以十六进 ...
- golang 判断IPv4 or IPv6 address
import strings func IsIPv4(address string) bool { return strings.Count(address, ":") < ...
- 2019nc#6
https://ac.nowcoder.com/acm/contest/886#question 题号 标题 已通过代码 题解/讨论 通过率 团队的状态 A Garbage Classificatio ...
随机推荐
- Naive Bayes Algorithm And Laplace Smoothing
朴素贝叶斯算法(Naive Bayes)适用于在Training Set中,输入X和输出Y都是离散型的情况.如果输入X为连续,输出Y为离散,我们考虑使用逻辑回归(Logistic Regression ...
- Ubuntu安装byzanz截取动态效果图
byzanz-record主要参数选项 用法: byzanz-record [选项...] 录制您的当前桌面会话 帮助选项: -?, --help 显示帮助选项 --help-all 显示全部帮助选项 ...
- PowerShell - Invoke VBA function
$xl = new-object -comobject Excel.Application $source_wb = $xl.workbooks.open($source) $xl.visible=$ ...
- 利用多态,简易实现电脑usb连接设备案例
package cn.learn.Practice03; public interface UsbInterface { void open(); //打开usb void close(); //关闭 ...
- 基于Annotation的IOC 初始化
从Spring2.0 以后的版本中,Spring 也引入了基于注解(Annotation)方式的配置,注解(Annotation)是JDK1.5 中引入的一个新特性,用于简化Bean 的配置,可以取代 ...
- 最小生成树基础算法(Prim + Krustal)
最小生成树问题的引入: 对于一个无向图G(V, E),需要用图中的n - 1条边连接图中的n个顶点并且不产生回路所产生的树就叫做生成树,其中权值总和最小的就是最小生成树. 如何求解最小生成树问题: 譬 ...
- [CF960G]Bandit Blues(第一类斯特林数+分治卷积)
Solution: 先考虑前缀,设 \(f(i, j)\) 为长度为 \(i\) 的排列中满足前缀最大值为自己的数有 \(j\) 个的排列数. 假设新加一个数 \(i+1\) 那么会有: \[ f ...
- [CF580C]Shortest Cycle(图论,最小环)
Description: 给 \(n\) 个点的图,点有点权 \(a_i\) ,两点之间有边当且仅当 \(a_i\ \text{and}\ a_j \not= 0\),边权为1,求最小环. Solut ...
- mysql高级知识
2 数据约束 2.1什么数据约束 对用户操作表的数据进行约束 2.2 默认值 作用: 当用户对使用默认值的字段不插入值的时候,就使用默认值. 注意: 1)对默认值字段插入null是可以的. 2)对 ...
- 2018-8-10-C#-TextBlock-上标
title author date CreateTime categories C# TextBlock 上标 lindexi 2018-08-10 19:16:52 +0800 2018-2-13 ...