当前位置: 首页 > news >正文

搭建网站案例英文seo实战派

搭建网站案例,英文seo实战派,做彩票网站代理犯法吗,男女做羞羞的视频网站文章目录 1. 题目要求2.解题思路 注意3.ACM模式代码 1. 题目要求 2.解题思路 首先,按照每个人的身高属性(即people[i][0])来排队,顺序是从大到小降序排列,如果遇到同身高的,按照另一个属性(即p…

文章目录

    • 1. 题目要求
    • 2.解题思路
  • 注意
    • 3.ACM模式代码

1. 题目要求

在这里插入图片描述

2.解题思路

首先,按照每个人的身高属性(即people[i][0])来排队,顺序是从大到小降序排列,如果遇到同身高的,按照另一个属性(即people[i][1])来从小到大升序排列。
使用到C++的sort()函数,第三个参数cmp函数自己定义:

static bool cmp(const vector<int>& a, const vector<int>& b)
{
// 使用const关键字来确保在函数内部不会修改a和bif(a[0] == b[0]) return a[1] < b[1]; // 象形的记,升序return a[0] > b[0];
}

接下来再次遍历people数组,从前到后将每个元素放入到一个二维数组里。
为什么从前到后?
先排身高更高的,后面身高矮的即使因为第二个属性需要插入到前面人的中间去也没关系,反正身高更高的第二个属性不受影响。但是从后到前先排身高矮的可就不行了。

vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {sort (people.begin(), people.end(), cmp);vector<vector<int>> que;for (int i = 0; i < people.size(); i++) {int position = people[i][1];que.insert(que.begin() + position, people[i]);}return que;}

时间复杂度要大于O(nlogn + n ^ 2),首先C++里的sort函数的时间复杂度就是O(nlogn),这个排序函数内部并不是单一的快速排序或者是其他的,而是动态改变的,可能一开始数据量较大时先快速排序对半分,等分到后面则使用插入排序;C++的vector是一个动态数组,插入操作是先考虑原来的数组大小够不够,如果不够那就二倍扩容,然后把原数组拷贝到新数组再插入新的元素,所以时间复杂度要大于O(n^2)。
将数组改成链表

vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {sort (people.begin(), people.end(), cmp);list<vector<int>> que; // list底层是链表实现,插入效率比vector高的多for (int i = 0; i < people.size(); i++) {int position = people[i][1]; // 插入到下标为position的位置std::list<vector<int>>::iterator it = que.begin();while (position--) { // 寻找在插入位置it++;}que.insert(it, people[i]);}return vector<vector<int>>(que.begin(), que.end());

注意

sort函数的第三个参数是cmp,cmp是一个比较函数,想这样使用 sort (people.begin(), people.end(), cmp);那必须得将cmp声明为静态成员函数,这样就不需要将函数实例化了。

3.ACM模式代码

#include <vector>
#include <algorithm>
#include <list>
#include <iostream> // 用于输出调试using namespace std;class Solution {
public:static bool cmp(const vector<int>& a, const vector<int>& b) {// Sort by height descending, and if heights are same, by k ascendingif (a[0] == b[0]) {return a[1] < b[1]; // Sort by k in ascending order} else {return a[0] > b[0]; // Sort by height in descending order}}vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {// Sort people array using custom comparatorsort(people.begin(), people.end(), cmp);// Use list for efficient insertionlist<vector<int>> que;// Insert into list at the specified index (k value)for (int i = 0; i < people.size(); i++) {int position = people[i][1]; // k value tells us the exact index to insertauto it = que.begin();advance(it, position); // Move iterator to the correct positionque.insert(it, people[i]); // Insert person into the list}// Convert list back to vector for returning the resultreturn vector<vector<int>>(que.begin(), que.end());}
};int main() {Solution sol;// Example usage:vector<vector<int>> people = {{7,0}, {4,4}, {7,1}, {5,0}, {6,1}, {5,2}};vector<vector<int>> result = sol.reconstructQueue(people);// Print the resultcout << "[";for (const auto& person : result) {cout << "[" << person[0] << ", " << person[1] << "],";}cout << "]";cout << endl;return 0;
}
http://www.hkea.cn/news/268218/

相关文章:

  • 网站建设性价比高优化设计官网
  • 电脑手机网站相互跳转西安seo关键词排名优化
  • 一般做网站用什么字体比较合适搜索引擎营销是什么
  • 去什么网站发贴做推广seo及网络推广招聘
  • 如何批量建站什么是互联网营销
  • 哈尔滨网站建设如何搭建一个网站平台
  • 哪些网站可以做任务网络营销推广的基本手段
  • 互联网舆情报告什么是seo营销
  • 餐饮商家做网站的好处沈阳关键词优化费用
  • 如何把网站的文字编辑网站页面优化内容包括哪些
  • 安徽做公司网站哪家好销售策略和营销策略
  • 做游戏都需要什么网站吗域名注册腾讯云
  • 北京建设厅网站谷歌关键词搜索
  • 如何识别一个网站是否做的好谷歌关键词挖掘工具
  • 网站建设专家网店营销推广
  • 做试玩网站搜索引擎优化答案
  • 外贸家具网站百度引擎搜索网址
  • 公司网站的栏目设置肇庆seo优化
  • 如何制作一个论坛网站网络服务器配置与管理
  • 北京中国建设部网站有什么平台可以推广
  • flash网站优缺点厦门百度seo
  • 贵阳利于优化的网站百度搜索引擎推广步骤
  • 金色 网站 模板外链是什么
  • 网站有多难做如何做推广引流赚钱
  • 建设企业网站怎么样百度首页 百度
  • 热烈祝贺网站上线泉州seo代理计费
  • 网站平台建设意见长沙有实力seo优化
  • 深圳网站如何制作西安seo网站推广优化
  • 网站建设业务文案网站seo检测工具
  • 石家庄做外贸网站建设现在最好的营销方式