当前位置:网站首页>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;
}
边栏推荐
- typeScript - Partially apply a function
- 2022 Niu Ke Summer Multi-School Training Camp 5 (BCDFGHK)
- 论文解读( AF-GCL)《Augmentation-Free Graph Contrastive Learning with Performance Guarantee》
- 软件测试面试题:做好测试计划的关键是什么?
- 僵尸进程和孤儿进程
- 软件测试面试题:负载测试、容量测试、强度测试的区别?
- 软件测试面试题:软件测试类型都有哪些?
- Mysql based
- 软件测试面试题:测试用例通常包括那些内容?
- 测试经理要不要做测试执行?
猜你喜欢

TinyMCE disable escape

matlab中rcosdesign函数升余弦滚降成型滤波器

Will domestic websites use Hong Kong servers be blocked?

2022牛客暑期多校训练营5(BCDFGHK)

gorm联表查询-实战

2022 Niu Ke Summer Multi-School Training Camp 5 (BCDFGHK)

3. Actual combat---crawl the result page corresponding to Baidu's specified entry (a simple page collector)

Three tips for you to successfully get started with 3D modeling

How to automatically push my new articles to my fans (very simple, can't learn to hit me)

Mysql_13 事务
随机推荐
性能测试如何准备测试数据
2022杭电多校第一场 1004 Ball
gorm的Raw与scan
Flask框架 根据源码分析可扩展点
电赛必备技能___定时ADC+DMA+串口通信
【idea】idea配置sql格式化
仿网易云音乐小程序-uniapp
tiup status
国内网站用香港服务器会被封吗?
软件测试面试题:软件验收测试的合格通过准则?
The master teaches you the 3D real-time character production process, the game modeling process sharing
软件测试面试题:您如何看待软件过程改进?在您曾经工作过的企业中,是否有一些需要改进的东西呢?您期望的理想的测试人员的工作环境是怎样的?
E - Many Operations (按位考虑 + dp思想记录操作后的结果
《MySQL入门很轻松》第2章:MySQL管理工具介绍
软件测试面试题:网络七层协仪具体?
ansible学习笔记分享-含剧本示例
动态上传jar包热部署
网站最终产品页使用单一入口还是多入口?
2022杭电多校第三场 L题 Two Permutations
【论文笔记】—低照度图像增强—Unsupervised—EnlightenGAN—2019-TIP