C++如何实现DNS域名解析<转>
C++如何实现DNS域名解析
一、概述
现在来搞定DNS域名解析,其实这是前面一篇文章C++实现Ping里面的遗留问题,要干的活是ping的过程中画红线的部分:
cmd下域名解析的命令是nslookup,比如“nslookup www.baidu.com”的结果如下:
其中,Address返回的就是www.baidu.com对应的IP地址,这个可能有多个
Alias指别名,也就是说www.baidu.com是www.a.shifen.com的别名,而www.a.shifen.com则是www.baidu.com的规范名(Canonical Name,CName),具体参考RFC1035 3.2.2 & wikipedia
二、实现结果预览
先看一下最终搞成了什么样子
输入:域名字符串
输出:IP列表、CName列表、DNS查询所用时间
三、相关技术
3.1、UDP or TCP ? (RFC1035 4.2)
UDP:DNS查询和回复采用低开销高性能的UDP,端口号为53。
TCP:辅助DNS服务器从主DNS服务器拉取最新数据时,采用可靠的TCP传输,端口号也为53。
我们这里做DNS查询采用UDP,53端口。
3.2、DNS查询/回复包头部解析 (RFC1035 4.1.1)
重点介绍一下我们关心的部分:
ID(16bits):标识符,一般填入本进程的标识符
QR(1bits):标志位,查询包为0,回复包为1
Opcode(4bits):查询的种类,标准查询为0
QDCOUNT(16bits):DNS查询/回复包数据部分Question字段的个数
ANCOUNT(16bits):DNS查询/回复包数据部分Answer字段的个数
3.2、DNS查询/回复包数据部分解析 (RFC1035 4.1.2 & 4.1.3)
查询/回复包的数据部分依次为QDCOUNT个Question字段、ANCOUNT个Answer字段....
对于任意字段,其格式如下:
Name(不定长):域名,这部分的格式比较复杂,后面单独说。
TYPE(16bits):查询类型/回复包RDATA类型,比如TYPE=1表示主机IP地址、TYPE=5表示CNAME,详见RFC1035 3.2.2
CLASS(16bits):类,一般情况下CLASS=1表示Internet,详见RFC1035 3.2.4
TTL(32bits,仅回复包):生存时间
RDLENGTH(16bits,仅回复包):RDATA部分的字节数
RDATA(不定长,仅回复包):资源数据,具体格式取决于TYPE和CLASS,比如TYPE=1、CLASS=1时,RDATA为四个字节的IP地址
3.3、Name解析&消息压缩
3.3.1、一般格式 (RFC1035 4.1.2)
标签内容长度(1个字节) + 标签内容,以标签内容长度0作为Name的结束符,例如:
3.3.2、消息压缩格式 (RFC1035 4.1.4)
如果标签内容长度的二进制前两位是11,则表示消息压缩。
此时,标签内容长度1个字节+后面的1个字节一共16位,后14位表示相对DNS包起始地址的偏移(Byte),例如:
上述例子中,DNS包起始地址为0x0000,c0 13的二进制为11000000 00010003,即跳转偏移为0x13个字节,对应的数据为03 63 6f 6d 00。
RFC1035中规定,支持的消息压缩规则为:
①以内容长度0结尾的标签序列
②偏移指针
③标签序列+偏移指针
也就是说,Name的消息压缩要求偏移指针必须在Name的尾部,且不支持同一级存在多个偏移指针(偏移指针序列),
但Name的消息压缩支持嵌套的偏移指针,即指针指向的偏移位置仍然是以偏移指针结尾的数据
四、代码实现
#pragma once //这里需要导入库 Ws2_32.lib,在不同的IDE下可能不太一样
//#pragma comment(lib, "Ws2_32.lib") #include <windows.h>
#include <string>
#include <vector> #define MAX_DOMAINNAME_LEN 255
#define DNS_PORT 53
#define DNS_TYPE_SIZE 2
#define DNS_CLASS_SIZE 2
#define DNS_TTL_SIZE 4
#define DNS_DATALEN_SIZE 2
#define DNS_TYPE_A 0x0001 //1 a host address
#define DNS_TYPE_CNAME 0x0005 //5 the canonical name for an alias
#define DNS_PACKET_MAX_SIZE (sizeof(DNSHeader) + MAX_DOMAINNAME_LEN + DNS_TYPE_SIZE + DNS_CLASS_SIZE) struct DNSHeader
{
USHORT usTransID; //标识符
USHORT usFlags; //各种标志位
USHORT usQuestionCount; //Question字段个数
USHORT usAnswerCount; //Answer字段个数
USHORT usAuthorityCount; //Authority字段个数
USHORT usAdditionalCount; //Additional字段个数
}; class CDNSLookup
{
public:
CDNSLookup();
~CDNSLookup(); BOOL DNSLookup(ULONG ulDNSServerIP, char *szDomainName, std::vector<ULONG> *pveculIPList = NULL, std::vector<std::string> *pvecstrCNameList = NULL, ULONG ulTimeout = , ULONG *pulTimeSpent = NULL);
BOOL DNSLookup(ULONG ulDNSServerIP, char *szDomainName, std::vector<std::string> *pvecstrIPList = NULL, std::vector<std::string> *pvecstrCNameList = NULL, ULONG ulTimeout = , ULONG *pulTimeSpent = NULL); private:
BOOL Init();
BOOL UnInit();
BOOL DNSLookupCore(ULONG ulDNSServerIP, char *szDomainName, std::vector<ULONG> *pveculIPList, std::vector<std::string> *pvecstrCNameList, ULONG ulTimeout, ULONG *pulTimeSpent);
BOOL SendDNSRequest(sockaddr_in sockAddrDNSServer, char *szDomainName);
BOOL RecvDNSResponse(sockaddr_in sockAddrDNSServer, ULONG ulTimeout, std::vector<ULONG> *pveculIPList, std::vector<std::string> *pvecstrCNameList, ULONG *pulTimeSpent);
BOOL EncodeDotStr(char *szDotStr, char *szEncodedStr, USHORT nEncodedStrSize);
BOOL DecodeDotStr(char *szEncodedStr, USHORT *pusEncodedStrLen, char *szDotStr, USHORT nDotStrSize, char *szPacketStartPos = NULL);
ULONG GetTickCountCalibrate(); private:
BOOL m_bIsInitOK;
SOCKET m_sock;
WSAEVENT m_event;
USHORT m_usCurrentProcID;
char *m_szDNSPacket;
};
[DNSLookup.h] #include "DNSLookup.h"
#include <stdio.h>
#include <string.h> CDNSLookup::CDNSLookup() :
m_bIsInitOK(FALSE),
m_sock(INVALID_SOCKET),
m_szDNSPacket(NULL)
{
m_bIsInitOK = Init();
} CDNSLookup::~CDNSLookup()
{
UnInit();
} BOOL CDNSLookup::DNSLookup(ULONG ulDNSServerIP, char *szDomainName, std::vector<ULONG> *pveculIPList, std::vector<std::string> *pvecstrCNameList, ULONG ulTimeout, ULONG *pulTimeSpent)
{
return DNSLookupCore(ulDNSServerIP, szDomainName, pveculIPList, pvecstrCNameList, ulTimeout, pulTimeSpent);
} BOOL CDNSLookup::DNSLookup(ULONG ulDNSServerIP, char *szDomainName, std::vector<std::string> *pvecstrIPList, std::vector<std::string> *pvecstrCNameList, ULONG ulTimeout, ULONG *pulTimeSpent)
{
std::vector<ULONG> *pveculIPList = NULL;
if (!pvecstrIPList)
{
return FALSE;
}
std::vector<ULONG> veculIPList;
pveculIPList = &veculIPList;
BOOL bRet = DNSLookupCore(ulDNSServerIP, szDomainName, pveculIPList, pvecstrCNameList, ulTimeout, pulTimeSpent); if (bRet)
{
pvecstrIPList->clear();
char szIP[] = {'\0'};
for (std::vector<ULONG>::iterator iter = pveculIPList->begin(); iter != pveculIPList->end(); ++iter)
{
BYTE *pbyIPSegment = (BYTE*)(&(*iter));
//sprintf_s(szIP, 16, "%d.%d.%d.%d", pbyIPSegment[0], pbyIPSegment[1], pbyIPSegment[2], pbyIPSegment[3]);
sprintf(szIP, "%d.%d.%d.%d", pbyIPSegment[], pbyIPSegment[], pbyIPSegment[], pbyIPSegment[]);
pvecstrIPList->push_back(szIP);
}
} return bRet;
} BOOL CDNSLookup::Init()
{
WSADATA wsaData;
if (WSAStartup(MAKEWORD(, ), &wsaData) == SOCKET_ERROR)
{
return FALSE;
} if ((m_sock = socket(AF_INET, SOCK_DGRAM, )) == INVALID_SOCKET)
{
return FALSE;
} m_event = WSACreateEvent();
WSAEventSelect(m_sock, m_event, FD_READ); m_szDNSPacket = new (std::nothrow) char[DNS_PACKET_MAX_SIZE];
if (m_szDNSPacket == NULL)
{
return FALSE;
} m_usCurrentProcID = (USHORT)GetCurrentProcessId(); return TRUE;
} BOOL CDNSLookup::UnInit()
{
WSACleanup(); if (m_szDNSPacket != NULL)
{
delete [] m_szDNSPacket;
} return TRUE;
} BOOL CDNSLookup::DNSLookupCore(ULONG ulDNSServerIP, char *szDomainName, std::vector<ULONG> *pveculIPList, std::vector<std::string> *pvecstrCNameList, ULONG ulTimeout, ULONG *pulTimeSpent)
{
if (m_bIsInitOK == FALSE || szDomainName == NULL)
{
return FALSE;
} //配置SOCKET
sockaddr_in sockAddrDNSServer;
sockAddrDNSServer.sin_family = AF_INET;
sockAddrDNSServer.sin_addr.s_addr = ulDNSServerIP;
sockAddrDNSServer.sin_port = htons( DNS_PORT ); //DNS查询与解析
if (!SendDNSRequest(sockAddrDNSServer, szDomainName)
|| !RecvDNSResponse(sockAddrDNSServer, ulTimeout, pveculIPList, pvecstrCNameList, pulTimeSpent))
{
return FALSE;
} return TRUE;
} BOOL CDNSLookup::SendDNSRequest(sockaddr_in sockAddrDNSServer, char *szDomainName)
{
char *pWriteDNSPacket = m_szDNSPacket;
memset(pWriteDNSPacket, , DNS_PACKET_MAX_SIZE); //填充DNS查询报文头部
DNSHeader *pDNSHeader = (DNSHeader*)pWriteDNSPacket;
pDNSHeader->usTransID = m_usCurrentProcID;
pDNSHeader->usFlags = htons(0x0100);
pDNSHeader->usQuestionCount = htons(0x0001);
pDNSHeader->usAnswerCount = 0x0000;
pDNSHeader->usAuthorityCount = 0x0000;
pDNSHeader->usAdditionalCount = 0x0000; //设置DNS查询报文内容
USHORT usQType = htons(0x0001);
USHORT usQClass = htons(0x0001);
USHORT nDomainNameLen = strlen(szDomainName);
char *szEncodedDomainName = (char *)malloc(nDomainNameLen + );
if (szEncodedDomainName == NULL)
{
return FALSE;
}
if (!EncodeDotStr(szDomainName, szEncodedDomainName, nDomainNameLen + ))
{
return FALSE;
} //填充DNS查询报文内容
USHORT nEncodedDomainNameLen = strlen(szEncodedDomainName) + ;
memcpy(pWriteDNSPacket += sizeof(DNSHeader), szEncodedDomainName, nEncodedDomainNameLen);
memcpy(pWriteDNSPacket += nEncodedDomainNameLen, (char*)(&usQType), DNS_TYPE_SIZE);
memcpy(pWriteDNSPacket += DNS_TYPE_SIZE, (char*)(&usQClass), DNS_CLASS_SIZE);
free (szEncodedDomainName); //发送DNS查询报文
USHORT nDNSPacketSize = sizeof(DNSHeader) + nEncodedDomainNameLen + DNS_TYPE_SIZE + DNS_CLASS_SIZE;
if (sendto(m_sock, m_szDNSPacket, nDNSPacketSize, , (sockaddr*)&sockAddrDNSServer, sizeof(sockAddrDNSServer)) == SOCKET_ERROR)
{
return FALSE;
} return TRUE;
} BOOL CDNSLookup::RecvDNSResponse(sockaddr_in sockAddrDNSServer, ULONG ulTimeout, std::vector<ULONG> *pveculIPList, std::vector<std::string> *pvecstrCNameList, ULONG *pulTimeSpent)
{
ULONG ulSendTimestamp = GetTickCountCalibrate(); if (pveculIPList != NULL)
{
pveculIPList->clear();
}
if (pvecstrCNameList != NULL)
{
pvecstrCNameList->clear();
} char recvbuf[] = {'\0'};
char szDotName[] = {'\0'};
USHORT nEncodedNameLen = ; while (TRUE)
{
if (WSAWaitForMultipleEvents(, &m_event, FALSE, , FALSE) != WSA_WAIT_TIMEOUT)
{
WSANETWORKEVENTS netEvent;
WSAEnumNetworkEvents(m_sock, m_event, &netEvent); if (netEvent.lNetworkEvents & FD_READ)
{
ULONG ulRecvTimestamp = GetTickCountCalibrate();
int nSockaddrDestSize = sizeof(sockAddrDNSServer); //接收响应报文
if (recvfrom(m_sock, recvbuf, , , (struct sockaddr*)&sockAddrDNSServer, &nSockaddrDestSize) != SOCKET_ERROR)
{
DNSHeader *pDNSHeader = (DNSHeader*)recvbuf;
USHORT usQuestionCount = ;
USHORT usAnswerCount = ; if (pDNSHeader->usTransID == m_usCurrentProcID
&& (ntohs(pDNSHeader->usFlags) & 0xfb7f) == 0x8100 //RFC1035 4.1.1(Header section format)
&& (usQuestionCount = ntohs(pDNSHeader->usQuestionCount)) >=
&& (usAnswerCount = ntohs(pDNSHeader->usAnswerCount)) > )
{
char *pDNSData = recvbuf + sizeof(DNSHeader); //解析Question字段
for (int q = ; q != usQuestionCount; ++q)
{
if (!DecodeDotStr(pDNSData, &nEncodedNameLen, szDotName, sizeof(szDotName)))
{
return FALSE;
}
pDNSData += (nEncodedNameLen + DNS_TYPE_SIZE + DNS_CLASS_SIZE);
} //解析Answer字段
for (int a = ; a != usAnswerCount; ++a)
{
if (!DecodeDotStr(pDNSData, &nEncodedNameLen, szDotName, sizeof(szDotName), recvbuf))
{
return FALSE;
}
pDNSData += nEncodedNameLen; USHORT usAnswerType = ntohs(*(USHORT*)(pDNSData));
USHORT usAnswerClass = ntohs(*(USHORT*)(pDNSData + DNS_TYPE_SIZE));
ULONG usAnswerTTL = ntohl(*(ULONG*)(pDNSData + DNS_TYPE_SIZE + DNS_CLASS_SIZE));
USHORT usAnswerDataLen = ntohs(*(USHORT*)(pDNSData + DNS_TYPE_SIZE + DNS_CLASS_SIZE + DNS_TTL_SIZE));
pDNSData += (DNS_TYPE_SIZE + DNS_CLASS_SIZE + DNS_TTL_SIZE + DNS_DATALEN_SIZE); if (usAnswerType == DNS_TYPE_A && pveculIPList != NULL)
{
ULONG ulIP = *(ULONG*)(pDNSData);
pveculIPList->push_back(ulIP);
}
else if (usAnswerType == DNS_TYPE_CNAME && pvecstrCNameList != NULL)
{
if (!DecodeDotStr(pDNSData, &nEncodedNameLen, szDotName, sizeof(szDotName), recvbuf))
{
return FALSE;
}
pvecstrCNameList->push_back(szDotName);
} pDNSData += (usAnswerDataLen);
} //计算DNS查询所用时间
if (pulTimeSpent != NULL)
{
*pulTimeSpent = ulRecvTimestamp - ulSendTimestamp;
} break;
}
}
}
} //超时退出
if (GetTickCountCalibrate() - ulSendTimestamp > ulTimeout)
{
*pulTimeSpent = ulTimeout + ;
return FALSE;
}
} return TRUE;
} /*
* convert "www.baidu.com" to "\x03www\x05baidu\x03com"
* 0x0000 03 77 77 77 05 62 61 69 64 75 03 63 6f 6d 00 ff
*/
BOOL CDNSLookup::EncodeDotStr(char *szDotStr, char *szEncodedStr, USHORT nEncodedStrSize)
{
USHORT nDotStrLen = strlen(szDotStr); if (szDotStr == NULL || szEncodedStr == NULL || nEncodedStrSize < nDotStrLen + )
{
return FALSE;
} char *szDotStrCopy = new char[nDotStrLen + ];
//strcpy_s(szDotStrCopy, nDotStrLen + 1, szDotStr);
strcpy(szDotStrCopy, szDotStr); char *pNextToken = NULL;
//char *pLabel = strtok_s(szDotStrCopy, ".", &pNextToken);
char *pLabel = strtok(szDotStrCopy, ".");
USHORT nLabelLen = ;
USHORT nEncodedStrLen = ;
while (pLabel != NULL)
{
if ((nLabelLen = strlen(pLabel)) != )
{
//sprintf_s(szEncodedStr + nEncodedStrLen, nEncodedStrSize - nEncodedStrLen, "%c%s", nLabelLen, pLabel);
sprintf(szEncodedStr + nEncodedStrLen, "%c%s", nLabelLen, pLabel);
nEncodedStrLen += (nLabelLen + );
}
//pLabel = strtok_s(NULL, ".", &pNextToken);
pLabel = strtok(NULL, ".");
} delete [] szDotStrCopy; return TRUE;
} /*
* convert "\x03www\x05baidu\x03com\x00" to "www.baidu.com"
* 0x0000 03 77 77 77 05 62 61 69 64 75 03 63 6f 6d 00 ff
* convert "\x03www\x05baidu\xc0\x13" to "www.baidu.com"
* 0x0000 03 77 77 77 05 62 61 69 64 75 c0 13 ff ff ff ff
* 0x0010 ff ff ff 03 63 6f 6d 00 ff ff ff ff ff ff ff ff
*/
BOOL CDNSLookup::DecodeDotStr(char *szEncodedStr, USHORT *pusEncodedStrLen, char *szDotStr, USHORT nDotStrSize, char *szPacketStartPos)
{
if (szEncodedStr == NULL || pusEncodedStrLen == NULL || szDotStr == NULL)
{
return FALSE;
} char *pDecodePos = szEncodedStr;
USHORT usPlainStrLen = ;
BYTE nLabelDataLen = ;
*pusEncodedStrLen = ; while ((nLabelDataLen = *pDecodePos) != 0x00)
{
if ((nLabelDataLen & 0xc0) == ) //普通格式,LabelDataLen + Label
{
if (usPlainStrLen + nLabelDataLen + > nDotStrSize)
{
return FALSE;
}
memcpy(szDotStr + usPlainStrLen, pDecodePos + , nLabelDataLen);
memcpy(szDotStr + usPlainStrLen + nLabelDataLen, ".", );
pDecodePos += (nLabelDataLen + );
usPlainStrLen += (nLabelDataLen + );
*pusEncodedStrLen += (nLabelDataLen + );
}
else //消息压缩格式,11000000 00000000,两个字节,前2位为跳转标志,后14位为跳转的偏移
{
if (szPacketStartPos == NULL)
{
return FALSE;
}
USHORT usJumpPos = ntohs(*(USHORT*)(pDecodePos)) & 0x3fff;
USHORT nEncodeStrLen = ;
if (!DecodeDotStr(szPacketStartPos + usJumpPos, &nEncodeStrLen, szDotStr + usPlainStrLen, nDotStrSize - usPlainStrLen, szPacketStartPos))
{
return FALSE;
}
else
{
*pusEncodedStrLen += ;
return TRUE;
}
}
} szDotStr[usPlainStrLen - ] = '\0';
*pusEncodedStrLen += ; return TRUE;
} ULONG CDNSLookup::GetTickCountCalibrate()
{
static ULONG s_ulFirstCallTick = ;
static LONGLONG s_ullFirstCallTickMS = ; SYSTEMTIME systemtime;
FILETIME filetime;
GetLocalTime(&systemtime);
SystemTimeToFileTime(&systemtime, &filetime);
LARGE_INTEGER liCurrentTime;
liCurrentTime.HighPart = filetime.dwHighDateTime;
liCurrentTime.LowPart = filetime.dwLowDateTime;
LONGLONG llCurrentTimeMS = liCurrentTime.QuadPart / ; if (s_ulFirstCallTick == )
{
s_ulFirstCallTick = GetTickCount();
}
if (s_ullFirstCallTickMS == )
{
s_ullFirstCallTickMS = llCurrentTimeMS;
} return s_ulFirstCallTick + (ULONG)(llCurrentTimeMS - s_ullFirstCallTickMS);
}
[DNSLookup.cpp] #include <stdio.h>
#include <windows.h>
#include "DNSLookup.h" int main(void)
{
char szDomainName[] = "www.baidu.com";
std::vector<ULONG> veculIPList;
std::vector<std::string> vecstrIPList;
std::vector<std::string> vecCNameList;
ULONG ulTimeSpent = ;
CDNSLookup dnslookup;
BOOL bRet = dnslookup.DNSLookup(inet_addr("114.114.114.114"), szDomainName, &vecstrIPList, &vecCNameList, , &ulTimeSpent); printf("DNSLookup result (%s):\n", szDomainName);
if (!bRet)
{
printf("timeout!\n");
return -;
} for (int i = ; i != veculIPList.size(); ++i)
{
printf("IP%d(ULONG) = %u\n", i + , veculIPList[i]);
}
for (int i = ; i != vecstrIPList.size(); ++i)
{
printf("IP%d(string) = %s\n", i + , vecstrIPList[i].c_str());
}
for (int i = ; i != vecCNameList.size(); ++i)
{
printf("CName%d = %s\n", i + , vecCNameList[i].c_str());
}
printf("time spent = %ums\n", ulTimeSpent); return ;
}
http://www.jb51.net/article/70359.htm
C++如何实现DNS域名解析<转>的更多相关文章
- C++实现DNS域名解析
一.概述 现在来搞定DNS域名解析,其实这是前面一篇文章C++实现Ping里面的遗留问题,要干的活是ping的过程中画红线的部分: cmd下域名解析的命令是nslookup,比如“nslookup w ...
- DNS域名解析过程
图1-10是DNS域名解析的主要请求过程实例图. 如图1-10所示,当一个用户在浏览器中输入www.abc.com时,DNS解析将会有将近10个步骤,这个过程大体描述如下.当用户在浏览器中输入域名并按 ...
- 配置DNS域名解析服务器
bind这个DNS域名解析服务器解析好后,执行下面的语句实现开启服务 named -c named.conf & -c指配置脚本named.conf的文件地址 named.conf主要有下面几 ...
- 域名下Web项目重定向出现DNS域名解析错误问题
问题: 项目使用的是阿里云的ESC,前几天为IP地址添加了域名 发现发送正常请求时跳转没问题,但发送重定向请求时,页面就会出现DNS域名解析错误的情况 1.我在Tomcat的server.xml中配置 ...
- 每天进步一点点——负载均衡之DNS域名解析
转载请说明出处:http://blog.csdn.net/cywosp/article/details/38017027 在上一篇文章(http://blog.csdn.net/cywosp/ ...
- 一张图看懂DNS域名解析全过程
DNS域名解析是互联网上非常重要的一项服务,上网冲浪(还有人在用这个词吗?)伴随着大量DNS服务来支撑,而对于网站运营来说,DNS域名解析的稳定可靠,意味着更多用户的喜欢,更好的SEO效果和更大的访问 ...
- DNS域名解析过程,域名的认识
DNS域名解析过程 参考知乎:https://www.zhihu.com/question/23042131 当你通过浏览器输入url访问资源时,会请求DNS解析域名成对应的IP地址,由IP地址在去与 ...
- 《linux就该这么学》第十四节课:第13章,部署DNS域名解析服务(bind服务)
(借鉴请改动) 第十二章收尾 12.2.nfs网络文件系统 RHEL7默认安装了nfs,配置文件在 /etc/export 写入格式:共享目录 允许的客户端(参数) ro ...
- DNS域名解析之搭建公司内部域--技术流ken
什么是DNS DNS( Domain Name System)是“域名系统”的英文缩写,是一种组织成域层次结构的计算机和网络服务命名系统,它用于TCP/IP网络,它所提供的服务是用来将主机名和域名转换 ...
- Cloudflare DNS 域名解析
参考文章:Cloudflare DNS 域名解析 小白一枚,等我这几天搞定后就写.....
随机推荐
- UVALive-3887 Slim Span (kruskal)
题目大意:定义无向图生成树的最大边与最小边的差为苗条度,找出苗条度最小的生成树的苗条度. 题目分析:先将所有边按权值从小到大排序,在连续区间[L,R]中的边如果能构成一棵生成树,那么这棵树一定有最小的 ...
- C#皮肤之IrisSkin4.dll
1. 将IrisSkin4.dll动态文件导入当前项目引用中.具体操作为:解决方案资源管理器->当前项目->引用->右键->添加引用,找到IrisSkin4.dll文件,然后加 ...
- iOS UI-自动布局(Autoresizing)
// // ViewController.m // IOS_0115_buzhi // // Created by ma c on 16/1/15. // Copyright (c) 2016年 博文 ...
- prototype原型模式
/** * 原型模式 Prototype * 用原型实例指定创建对象的种类,并通过拷贝这些原型创建新的对象 */ 需求: public class Resume { /** * 要求:一个简历类,必须 ...
- New Concept English Two 33 91
$课文89 口误 981. People will do anything to see a free show -- even if it is a bad one. 人们总要想尽办法看不花钱的演出 ...
- IE 问题集合
1.zIndex在ie需要 先对比父级的层级
- ASP.NET FORM认证配置排错记录
搞了2小时都不能实现自动跳转到登录页面,后删除了配置文件中的name,就解决问题了. <authorization> <deny users="?" / ...
- Linux:安装Ubuntu时出现“客户机操作新系统已禁用CPU,请关闭或重置虚拟机”
安装Ubuntu时出现“客户机操作新系统已禁用CPU,请关闭或重置虚拟机“ 解决 在vmware的虚拟机的配置文件中找到xxxx.vmx的文件 用记事本打开 加入 cpuid..eax = " ...
- Python数据类型-02.字符串
本文主要记录字符串的相关知识,包括字符串的定义特点,常用方法和 请知悉: 计算机中,一切皆为对象世界万物,皆为对象,一切对象皆可分类 1.什么是字符串? 类似"hello world&quo ...
- lmdb数据格式
http://deepdish.io/2015/04/28/creating-lmdb-in-python/ https://lmdb.readthedocs.org/en/release/ http ...