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

网站种类有哪些wordpress 在线pdf

网站种类有哪些,wordpress 在线pdf,页面锚wordpress,会宁网站建设公司原题链接:https://codeforces.com/contest/1742/problem/D 题目背景: 给定一个有 n 个元素的数组a ,定义 s 为如果 ai 和 aj 互质,s i j。求最大的 s。 思路: 直接暴力枚举每个 i 的话时间复杂度为 n^2 的&#xf…
原题链接:https://codeforces.com/contest/1742/problem/D
题目背景:

       给定一个有 n 个元素的数组a ,定义 s 为如果 ai 和 aj 互质,s = i + j。求最大的 s。

思路:

       直接暴力枚举每个 i 的话时间复杂度为 n^2 的,肯定会超时。

       可以看到 ai 最大为 1000,我们可以只遍历1到1000而不是遍历数组,先预处理出来1到1000中与每个数互质的数,再存储数组a中每个元素最后出现的位置,遍历1到1000及其互质的数,如果两个元素都在数组中出现了,s就是两个元素的下标,最后遍历全部取最大s即可。

数据范围:

        1 <= ai <= 1000,n 总和不超过 2e5。

时间复杂度:

        O(1000^2)

ac代码: 
#include <bits/stdc++.h>#define ioscc ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define endl '\n'
#define me(a, x) memset(a, x, sizeof a)
#define all(a) a.begin(), a.end()
#define sz(a) ((int)(a).size())
#define pb(a) push_back(a)
using namespace std;typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<bool> vb;const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
const int MAX = (1ll << 31) - 1;
const int MIN = 1 << 31;
const int MOD = 1e9 + 7;
const int N = 1e5 + 10;template <class T>
ostream &operator<<(ostream &os, const vector<T> &a) noexcept
{for (int i = 0; i < sz(a) - 10; i++)std::cout << a[i] << ' ';return os;
}template <class T>
istream &operator>>(istream &in, vector<T> &a) noexcept
{for (int i = 0; i < sz(a) - 10; i++)std::cin >> a[i];return in;
}/* ----------------- 有乘就强转,前缀和开ll ----------------- */ll gcd(ll a, ll b)
{
#define tz __builtin_ctzllif (!a || !b)return a | b;int t = tz(a | b);a >>= tz(a);while (b){b >>= tz(b);if (a > b)swap(a, b);b -= a;}return a << t;
#undef tz
}vvi v(1010, vi(1010));void init()
{for (int i = 1; i <= 1001; ++i){for (int j = 1; j <= 1001; ++j){if (gcd(i, j) == 1){v[i].pb(j);}}}
}void solve()
{int n;cin >> n;vi a(n + 10);vi p(1010, 0);for (int i = 1; i <= n; ++i){cin >> a[i];p[a[i]] = i;}ll ans = -1;for (int i = 1; i <= 1001; ++i){for (auto x : v[i]){if (p[x] && p[i])ans = max(ans, 1ll * p[i] + p[x]);}}cout << ans << endl;
}int main()
{ioscc;init();int T;cin >> T;while (T--)solve();return 0;
}


文章转载自:

http://00000000.mcpdn.cn
http://00000000.mcpdn.cn
http://00000000.mcpdn.cn
http://00000000.mcpdn.cn
http://00000000.mcpdn.cn
http://00000000.mcpdn.cn
http://00000000.mcpdn.cn
http://00000000.mcpdn.cn
http://00000000.mcpdn.cn
http://00000000.mcpdn.cn
http://00000000.mcpdn.cn
http://00000000.mcpdn.cn
http://00000000.mcpdn.cn
http://00000000.mcpdn.cn
http://00000000.mcpdn.cn
http://00000000.mcpdn.cn
http://00000000.mcpdn.cn
http://00000000.mcpdn.cn
http://00000000.mcpdn.cn
http://00000000.mcpdn.cn
http://00000000.mcpdn.cn
http://00000000.mcpdn.cn
http://00000000.mcpdn.cn
http://00000000.mcpdn.cn
http://00000000.mcpdn.cn
http://00000000.mcpdn.cn
http://00000000.mcpdn.cn
http://00000000.mcpdn.cn
http://00000000.mcpdn.cn
http://00000000.mcpdn.cn
http://www.dtcms.com/wzjs/613391.html

相关文章:

  • 阿里云网站建设教学视频教程湖州网站设计
  • 1m的带宽做网站可以吗佛山宽屏网站建设
  • 有自建服务器做网站的吗贸易公司 网站 扶持
  • 怎么用ip访问vps网站手机网站cms有哪些
  • 中山市城乡和住房建设局网站网页设计说明书1000字
  • 做3d ppt模板下载网站优化游戏卡顿的软件
  • 网站为什么要更新成都网络营销策划公司
  • 网站用户角色树品营销拓客平台系统
  • 个人网站如何建中国门户网站有哪些
  • 做一个企业网站价格北京专业做网站的公司
  • 网页设计与网站建设大作业做字体网站
  • 网站馆店精准引流怎么推广江苏专业网站推广公司
  • 深圳最专业的高端网站建设百度公司可以做网站么
  • 普通网站和门户网站的区别赤峰微网站建设
  • 网站开发 企业 定制系统网站建设报告书
  • 网站建设如何入账网站地图是怎么做的
  • 开发网站需求设计网站集约化建设优势
  • 常州网站制作市场江苏网站建设推广
  • 网站后台使用培训什么是seo什么是sem
  • 苏宁易购网站建设的目的中国网站开发排名
  • 做视频的背景音乐哪里下载网站微信公众号开发需要多少钱
  • 江阴做网站公司html5网站开发趋势
  • 发布企业信息的网站做网站的客户需求
  • 网站三网合一案例做网站图片切图是什么
  • 做一网站要什么wordpress app提示
  • 做的网站怎么让百度收录广东东莞天气
  • 建一个电商网站多少钱栾城网站制作
  • 已有网站开发app终端wordpress ftp连接不上
  • 手机网站设计推荐网页版传奇排行
  • 盐城网站建设0515icp口碑最好的旅游网站