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

宁夏交通建设质监局官方网站/广告关键词有哪些

宁夏交通建设质监局官方网站,广告关键词有哪些,衡水做外贸网站建设,网店代运营公司方案目录一、题目二、解析三、代码四、感想一、题目 二、解析 主要用到map的构造和find方法。其中&#xff0c;map的构造如下&#xff1a; #include <iostream> #include <map>using namespace std;int n, a, b;map<int, int> u; map<int, int> v;int ma…

目录

    • 一、题目
    • 二、解析
    • 三、代码
    • 四、感想

一、题目

在这里插入图片描述

二、解析

主要用到map的构造和find方法。其中,map的构造如下:

#include <iostream>
#include <map>using namespace std;int n, a, b;map<int, int> u;
map<int, int> v;int main()
{cin >> n >> a >> b;for (int i = 0; i < a; i++) {int ind, val;cin >> ind >> val;u[ind] = val;}for (int i = 0; i < b; i++) {int ind, val;cin >> ind >> val;v[ind] = val;}cout << "Vector u:" << endl;for (map<int, int>::iterator it = u.begin(); it != u.end(); it++)cout << (*it).first << " " << (*it).second << endl;cout << "Vector v:" << endl;for (map<int, int>::iterator it = v.begin(); it != v.end(); it++)cout << (*it).first << " " << (*it).second << endl;return 0;
}

输入:

10 3 4
4 5
7 -3
10 1
1 10
4 20
5 30
7 40

输出:

Vector u:
4 5
7 -3
10 1
Vector v:
1 10
4 20
5 30
7 40

三、代码

#include <iostream>
#include <map>using namespace std;int n, a, b;map<int, int> u;
map<int, int> v;long long product = 0;int main()
{cin >> n >> a >> b;for (int i = 0; i < a; i++) {int ind, val;cin >> ind >> val;u[ind] = val;}for (int i = 0; i < b; i++) {int ind, val;cin >> ind >> val;v[ind] = val;}//	cout<<"Vector u:"<<endl;//	for(map<int, int>::iterator it=u.begin(); it!=u.end(); it++)//		cout<<(*it).first<<" "<<(*it).second<<endl;////	cout<<"Vector v:"<<endl;//	for(map<int, int>::iterator it=v.begin(); it!=v.end(); it++)//		cout<<(*it).first<<" "<<(*it).second<<endl;for (map<int, int>::iterator itU = u.begin(); itU != u.end(); itU++) {int ind = (*itU).first;map<int, int>::iterator itV = v.find(ind);if (itV != v.end())product += (*itU).second * (*itV).second;}cout << product << endl;return 0;
}

输入:

10 3 4
4 5
7 -3
10 1
1 10
4 20
5 30
7 40

输出:

-20

四、感想

  1. 第一次使用vector,但只获得30分,后面的超时了。因为vector的查找的时间复杂度为O(n),所以程序的时间复杂度为O(a*b)。

  2. 第二次使用map,但只获得60分,后面的错误了;第三次将累加用的变量product由int类型换为long long类型,就通过了。因为map的查找的时间复杂度为O(log n),所以程序的时间复杂度为O(a*log b);且|ui|、|vi|<=106,故product的类型应该为long long。

http://www.jmfq.cn/news/5151997.html

相关文章:

  • 企业网站建设有名 乐云seo/南京seo
  • PR做视频需要放网站上/哪个行业最需要推广
  • 阿里云做电影网站/在线crm
  • 国内做网站制作比较/爱站seo工具包
  • 杭州装饰网站建设/百度推广代理商名单
  • 企业建网站的费用/网站模板套用教程
  • wordpress修改站点名/无锡网络优化推广公司
  • 建设银行企业网站银行/nba西部排名
  • 淘客网站难做吗/起名最好的网站排名
  • 有没有专门做教育培训的网站/推广获客
  • 易讯网络网站建设/太原网络推广公司哪家好
  • 计算机编程与网站建设/国内重大新闻
  • 日本做任务赚钱的网站/优化大师使用心得
  • 上海网站开发建设服务/seo优化技术教程
  • 网站建设需要哪些素材/seo关键词智能排名
  • 网站开发模板/百度平台推广该怎么做
  • 微网站开发软件/找人帮忙注册app推广
  • 网站入口你明白我的意思吧/免费顶级域名注册
  • 学做美食交流网站有哪些/灰色词排名推广
  • 在哪做网站建设/关键词优化的技巧
  • 学前端有必要找培训机构吗/百度seo网络营销书
  • 乐清网站建设honmau/如何制作网页游戏
  • 贵州省城乡与建设厅网站/sem搜索引擎营销是什么
  • 中关村在线手机频道/seo优化工作内容
  • 湘潭市 网站建设/seo兼职论坛
  • 怎么给网站开发后台/专业网站优化培训
  • 龙岗建网站公司/沧州网络推广公司
  • 东莞建设网站的公司/中视频自媒体平台注册官网
  • 创意网站界面/推广app下载
  • 有没有一些帮做名片的网站/网络推广公司十大排名