当前位置:网站首页>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;
}
边栏推荐
- redis可视化管理软件Redis Desktop Manager2022
- oracle创建用户以后的权限问题
- 软件测试面试题:您以往所从事的软件测试工作中,是否使用了一些工具来进行软件缺陷(Bug)的管理?如果有,请结合该工具描述软件缺陷(Bug)跟踪管理的流程?
- what?测试/开发程序员要被淘汰了?年龄40被砍到了32?一瞬间,有点缓不过神来......
- About I double-checked and reviewed the About staff page, returning an industry question
- Mysql based
- 情侣牵手[贪心 & 抽象]
- 标识符、关键字、常量 和变量(C语言)
- Mysql_14 存储引擎
- Metasploit-域名上线隐藏IP
猜你喜欢

redis可视化管理软件Redis Desktop Manager2022

性能测试如何准备测试数据

Getting started with 3D modeling for games, what modeling software can I choose?

【idea】idea配置sql格式化

【云原生--Kubernetes】调度约束

leetcode经典例题——单词拆分

oracle创建表空间

Mathematical Principles of Matrix

The master teaches you the 3D real-time character production process, the game modeling process sharing

【LeetCode】矩阵模拟相关题目汇总
随机推荐
10 个关于 Promise 和 setTimeout 知识的面试题,通过图解一次说透彻
【论文笔记】—低照度图像增强—Unsupervised—EnlightenGAN—2019-TIP
LeetCode Hot 100
【云原生--Kubernetes】Pod控制器
网站最终产品页使用单一入口还是多入口?
[CVA Valuation Training Camp] Financial Modeling Guide - Lecture 1
软件测试面试题:请你分别画出 OSI 的七层网络结构图和 TCP/IP 的四层结构图?
看图识字,DELL SC4020 / SCv2000 控制器更换过程
MongoDB permission verification is turned on and mongoose database configuration
IDEA file encoding modification
【LeetCode】滑动窗口题解汇总
Mysql_13 事务
tensor.nozero(), mask, [mask]
进程间通信和线程间通信
leetcode:269. 火星词典
图解 Canvas 入门
ARC129E Yet Another Minimization 题解 【网络流笔记】
What is next-generation modeling (with learning materials)
刘润直播预告 | 顶级高手,如何创造财富
The master teaches you the 3D real-time character production process, the game modeling process sharing