Hackerrank && Network
来源:互联网 发布:老铁seo 编辑:程序博客网 时间:2024/05/12 02:02
1.Hackerrank
一个在N个数字里,选K个数字,从N个数字里选出K个数字的子集,使得此子集中的数字之间差的最大值比其他任何子集中的相差值小。
先输入N,然后输入K,接着输入N个数字
如input:9,3,1,2,3,100,101,5,6,7,8
表面输入9个数字,子集大小为3个数字:
请找出{1,2,3,100,101,5,6,7,8}子集数为3,且“贫富差距”最小的一组。
............................
............................
开始拿到这题让我想到了Leetcode上的一道十分相似的题目,半天没什么思绪,变去Github上找到一个牛写的答案,看了之后茅塞顿开,并且见识到了工业级代码的风格,人家走来调用STL中的strol、getline,齐刷刷的函数我还得去问度娘,而且他走来是一个输入的范围判断,如果超出则抛出异常,学习咯。
思路很简单,先利用sort()对输入数组进行排序,再依次遍历。
code:
#include <cmath>#include <cstdio>#include <vector>#include <iostream>#include <algorithm>using namespace std;// It is NOT mandatory to use the provided template. You can handle the IO section differently.int main() {/* The code required to enter n,k, candies is provided*/int N, K, unfairness,temp;vector<int> candies;cin >> N >> K;for (int i = 0; i < N; i++){cin >> temp;candies.push_back(temp);}sort(candies.begin(),candies.end());unfairness = candies[K - 1] - candies[0];for (int i = 0; i <= N-K ; i++){if (unfairness>(candies[i + K - 1] - candies[i]))unfairness = candies[i + K - 1] - candies[i];}cout << unfairness << endl;return 0;system("pause");}
2.Network
Today, I studied ICMP and IP protocols. I learned that Ethernet is a kind of protocol in Data Link Layer. And there are some protocols in this layer link like Token Ring、FDDI、ARCNET. The formation of IP protocal must have at least 20 Bytes in its header, including VER(version,usually like 4 or 6) and HLEN(header length, range:5~15) and Toal Length、Identification、Flags(which determine whether it can or can't be separate into fragment and status if it's the last fragmentation of a sequence)、Fragmentation offset、Time to live(this was originally designed to hold a timestamp, a number which means at most we could transfer from a router to other router,and it was decremented by each visited router)、Protocol(the higher level protocol that uses the services of the IP layer)、Header checksum、the Source and destination IP address.
ICMP is another protocol used in the Network layer. It's mainly help the IP protocol to solve some error that happened in this layer.
3.Leetcode
刷了道30的题,秒刷啊。。然后被一道20的题搞到现在,妈蛋,睡觉去。。fuck...
- Hackerrank && Network
- hackerRank
- HackerRank
- HackerRank
- HackerRank
- HackerRank
- HackerRank
- HackerRank
- HackerRank Palindromes
- Hackerrank Pangrams
- Hackerrank IsFibo
- 【hackerrank】数据结构
- HackerRank String
- Hackerrank :Candies
- HackerRank: Equal
- [hackerrank Random]
- [hackerrank random]
- HackerRank-Arrays
- shell第7周
- 修改dedecms 后台【模板管理】中模板的文件描述
- Java反射机制原理及使用(二)
- 数据结构实验二 线性表实验
- 1、cocos2d-x环境安装
- Hackerrank && Network
- 简单修复DHCP Client服务
- 【MongoDB】The description of index(一)
- 112家互联网与IT公司薪水一览表
- 逻辑提高
- 疾烈婪俗赘列屡嫌访泛愿的人铣餐
- 开源:我的Android新闻客户端,速度快、体积小、支持离线阅读、操作简便、内容展现形式丰富多样、信息量大、功能全面 等(要代码的留下邮箱)
- 1 游戏逻辑架构,Cocos2d-x游戏项目创建,HelloWorld项目创建,HelloWorld程序分析,(CCApplicationProtocol,CCApplication,AppDeleg
- 程序设计:从圆的半径求得圆的面积