当前位置:网站首页>2022 Hangzhou Electric Multi-School 1004 Ball
2022 Hangzhou Electric Multi-School 1004 Ball
2022-08-05 00:22:00 【Rain Sure】
题目链接
题目大意
Topic given our two-dimensional plane n n n个点,Horizontal ordinate are no more than 100000 100000 100000,Ask we choose three points,Three points constitute three sides of the perimeter of the median is the number of primes scheme is how much?
题解
Direct enumeration three points,势必会TLE;So we consider all edge build up,时间复杂度 O ( n 2 ) O(n^2) O(n2),And then according to the edge of the smallest size,Then, in turn, enumerated each edge,If the current edge is prime,Assuming that the current edge two endpoints for a a a 和 b b b,We need to know the connection a a aThe number of the edge is smaller than the current edge weights in the,连接 b b bThe number of edge is bigger than the current edge weights;Similarly, in turn, requires a.Direct enumeration not goozyet,我们考虑使用 b i t s e t bitset bitset进行优化, p [ i ] p[i] p[i]What are said to i i iPoint distance less than or equal to the current edge,In the process of enumeration and maintenance can be.最终时间复杂度 O ( n 2 l o g ( n 2 ) ) O(n^2 log(n^2)) O(n2log(n2)).
代码
#include<iostream>
#include<cstring>
#include<bitset>
#include<algorithm>
using namespace std;
#define int long long
const int maxn = 2010, M = 200010;
#define x first
#define y second
typedef pair<int,int> PII;
PII a[maxn];
bool st[M];
int primes[M], cnt;
typedef struct node
{
int a, b, c;
bool operator < (const struct node &w) const {
return c < w.c;
}
}Node;
Node edges[maxn * maxn];
bitset<maxn> p[maxn];
int n, m;
void init(int n)
{
for(int i = 2; i <= n; i ++){
if(!st[i]) primes[cnt ++] = i;
for(int j = 0; primes[j] <= n / i; j ++){
st[primes[j] * i] = true;
if(i % primes[j] == 0) break;
}
}
}
int get_dist(PII a, PII b)
{
return abs(a.x - b.x) + abs(a.y - b.y);
}
signed main()
{
init(200000);
st[1] = true;
int t; cin >> t;
while(t --){
for(int i = 0; i < maxn; i ++) p[i].reset();
cin >> n >> m;
for(int i = 1; i <= n; i ++) cin >> a[i].x >> a[i].y;
int k = 0;
for(int i = 1; i <= n; i ++){
for(int j = i + 1; j <= n; j ++){
edges[k ++] = {
i, j, get_dist(a[i], a[j])};
}
}
int res = 0;
sort(edges, edges + k);
for(int i = 0; i < k; i ++){
int a = edges[i].a, b = edges[i].b, c = edges[i].c;
if(!st[c]) res += (p[a] ^ p[b]).count();
p[a][b] = 1, p[b][a] = 1;
}
cout << res << endl;
}
return 0;
}
边栏推荐
猜你喜欢

软件质量评估的通用模型
![[230]连接Redis后执行命令错误 MISCONF Redis is configured to save RDB snapshots](/img/fa/5bdc81b1ebfc22d31f42da34427f3e.png)
[230]连接Redis后执行命令错误 MISCONF Redis is configured to save RDB snapshots

QSunSync Qiniu cloud file synchronization tool, batch upload

英特尔WiFi 7产品将于2024年亮相 最高速度可达5.8Gbps

图解 Canvas 入门

典型相关分析CCA计算过程

元宇宙:未来我们的每一个日常行为是否都能成为赚钱工具?

进程间通信和线程间通信
![[CVA Valuation Training Camp] Financial Modeling Guide - Lecture 1](/img/8b/360df9a9094037dc358cb21c60cdc8.png)
[CVA Valuation Training Camp] Financial Modeling Guide - Lecture 1

【LeetCode】滑动窗口题解汇总
随机推荐
How to burn the KT148A voice chip into the chip through the serial port and the tools on the computer
软件测试面试题:软件测试类型都有哪些?
2022多校第二场 K题 Link with Bracket Sequence I
matlab中rcosdesign函数升余弦滚降成型滤波器
Handwritten Distributed Configuration Center (1)
"No title"
【LeetCode】矩阵模拟相关题目汇总
软件测试面试题:手工测试与自动测试有哪些区别?
2022牛客多校训练第二场 J题 Link with Arithmetic Progression
ARC129E Yet Another Minimization 题解 【网络流笔记】
软件质量评估的通用模型
canvas 高斯模糊效果
软件测试面试题:一套完整的测试应该由哪些阶段组成?
【unity编译器扩展之模型动画拷贝】
2022杭电多校训练第三场 1009 Package Delivery
工业物联网 —— 新型数据库的召唤
导入JankStats检测卡帧库遇到问题记录
看图识字,DELL SC4020 / SCv2000 控制器更换过程
简单的顺序结构程序(C语言)
软件测试面试题:LoadRunner 分为哪三个模块?