日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

HDU 4631 Sad Love Story 平面内最近点对

發布時間:2023/12/13 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HDU 4631 Sad Love Story 平面内最近点对 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

http://acm.hdu.edu.cn/showproblem.php?pid=4631

題意: 在平面內依次加點,求每次加點后最近點對距離平方的和

因為是找平面最近點對...所以加點以后這個最短距離一定是遞減的...所以最后會形成這樣一個函數圖像

所以我們只要從后往前依次刪點即可...

15秒驚險水過...不過我最小點對的木板肯定寫掛了,卡時限的話估計過不了...

請用G++交...C++會TLE...當然我也無法解釋這個問題...估計是我傻逼

?

/********************* Template ************************/ #include <set> #include <map> #include <list> #include <cmath> #include <ctime> #include <deque> #include <queue> #include <stack> #include <bitset> #include <cstdio> #include <string> #include <vector> #include <cassert> #include <cstdlib> #include <cstring> #include <sstream> #include <fstream> #include <numeric> #include <iomanip> #include <iostream> #include <algorithm> #include <functional> using namespace std;#define EPS 1e-8 #define MAXN (int)5e5+5 #define MOD (int)1e9+7 #define PI acos(-1.0) #define INF ((1LL)<<50) #define max(a,b) ((a) > (b) ? (a) : (b)) #define min(a,b) ((a) < (b) ? (a) : (b)) #define max3(a,b,c) (max(max(a,b),c)) #define min3(a,b,c) (min(min(a,b),c)) #define BUG cout<<"BUG! "<<endl #define LINE cout<<"------------------"<<endl #define L(t) (t << 1) #define R(t) (t << 1 | 1) #define Mid(a,b) ((a + b) >> 1) #define lowbit(a) (a & -a) #define FIN freopen("out.txt","w",stdout) #pragma comment (linker,"/STACK:102400000,102400000")// typedef long long LL; // typedef unsigned long long ULL; typedef __int64 LL; // typedef unisigned __int64 ULL; // int gcd(int a,int b){ return b?gcd(b,a%b):a; } // int lcm(int a,int b){ return a*b/gcd(a,b); }/********************* F ************************/ struct point {LL x,y;int pos;int id;point(double a = 0,double b = 0,int c = 0){x = a ; y = b ; pos = c;} }p[MAXN],t[MAXN],tmp[MAXN];LL n,ax,bx,cx,ay,by,cy;bool cmp(point a,point b){if(a.x == b.x) return a.y < b.y;return a.x < b.x; }bool cmp1(point a,point b){return a.y < b.y; }LL dist(point a ,point b){return (a.x-b.x) * (a.x-b.x) + (a.y-b.y) * (a.y-b.y); }/** 二維空間找最近點對* 返回排序后點位置的pair<int,int>*/ pair<int,int> Closest_Pair(int l ,int r){if(l == r || l+1 == r) return make_pair(l,r); //1個點,2個點 直接return;int m = Mid(l,r); // (l+r)/2pair<int,int> dl = Closest_Pair(l,m);pair<int,int> dr = Closest_Pair(m+1,r);LL ldis,rdis; //左部分的最值 右部分的最值LL ans_dis; //左中右三部分最值if(dl.first == dl.second) ldis = INF; //判重else ldis = dist(p[dl.first],p[dl.second]);if(dr.first == dr.second) rdis = INF;else rdis = dist(p[dr.first],p[dr.second]);pair<int,int> ans = ldis < rdis ? dl : dr ; //左右兩部分的最值點對ans_dis = min(ldis,rdis); //左右兩部分的最值// 從中向左右兩邊找在[p[m].x-d,p[m].x+d]的平面內所有點// 這以后的復雜度就不太好估計了...// 這段模板是用暴力找的...我只做了一點點優化...但為什么加剪枝時間還多了這我不太理解囧int cnt = 0; // for(int i = l; i <= r; i++) // { // if((long long)(p[m].x - p[i].x)*(p[m].x - p[i].x) <= ans_dis) // tmp[cnt++] = p[i]; // }for(int i = m ; i >= l ; i--){LL q = (p[m].x - p[i].x) * (p[m].x - p[i].x);if(p[i].x < p[m].x - q) break;if(q <= ans_dis){tmp[cnt++] = p[i];}}for(int i = m+1 ; i <= r ; i++){LL q = (p[m].x - p[i].x) * (p[m].x - p[i].x);if(p[i].x > p[m].x + q) break;if(q <= ans_dis){tmp[cnt++] = p[i];}}//按y方向進行篩選 ,相隔大于d的點可以直接跳過sort(tmp,tmp+cnt,cmp1);for(int i = 0 ; i < cnt ; i++){for(int j = i+1 ; j < cnt ; j++){if((tmp[i].y - tmp[j].y) * (tmp[i].y - tmp[j].y) >= ans_dis)break;if(dist(tmp[i],tmp[j]) < ans_dis){ans_dis = dist(tmp[i],tmp[j]);ans = make_pair(tmp[i].id,tmp[j].id);}}}return ans; }void pre(){t[0].x = bx % cx;t[0].y = by % cy;t[0].pos = 0;for(int i = 1 ; i <= n ; i++) {t[i].x = (t[i-1].x * ax + bx) % cx;t[i].y = (t[i-1].y * ay + by) % cy;t[i].pos = i;} } int main() {//FIN;int T;scanf("%d",&T);while(T--){scanf("%d%I64d%I64d%I64d%I64d%I64d%I64d",&n,&ax,&bx,&cx,&ay,&by,&cy);pre();LL res = 0 ;while(n){for(int i = 0 ; i < n ; i++)p[i] = t[i];sort(p,p+n,cmp);for(int i = 0 ; i < n ; i++)p[i].id = i;pair<int,int> ans = Closest_Pair(0,n-1);int last = max(p[ans.first].pos,p[ans.second].pos);res += (dist(p[ans.first],p[ans.second]) * (n - last));n = last ;}printf("%I64d\n",res);}return 0; }

?

轉載于:https://www.cnblogs.com/Felix-F/p/3231376.html

總結

以上是生活随笔為你收集整理的HDU 4631 Sad Love Story 平面内最近点对的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 国产三级av片 | 我和公激情中文字幕 | 粉嫩av国产一区二区三区 | 中文字幕免费高清在线 | 欧美中文字幕在线播放 | 欧美精品二区 | 又黄又爽一区二区三区 | 久久黄色免费视频 | 国产精品久久777777换脸 | 午夜影院在线观看18 | 国产精品人八做人人女人a级刘 | 操人视频免费 | 波多野结衣免费在线视频 | 少妇无码一区二区三区免费 | 久久鲁视频 | 国色天香网站 | 永久久久久久 | 无码熟妇αⅴ人妻又粗又大 | 日韩视频国产 | 亚洲成人一区二区三区 | 亚洲综合精品视频 | 爽插| 久久精品视频日本 | 欧美综合影院 | 国产做爰视频免费播放 | a免费看| 日韩六十路 | 免费观看一区二区三区 | 少妇高潮久久久久久潘金莲 | 国产精品视频一区二区三区不卡 | 懂色av蜜臀av粉嫩av喷吹 | 国产亚洲一区二区三区在线观看 | 日韩国产在线一区 | 在线播放亚洲精品 | 国产成人久久精品流白浆 | 91在线免费观看网站 | 亚州色图欧美色图| 香蕉久久a毛片 | 免费看欧美黑人毛片 | 中文字幕一区二区在线播放 | 久国产精品 | 中文字幕乱码中文乱码777 | 亚洲高清在线视频 | 伊人久久综合影院 | 中文字幕色片 | 成人a网| 18成人在线观看 | www.色多多| 国产精品视频 | 欧美成人精品激情在线观看 | 久久精品视频91 | eeuss一区二区三区 | 一区二区三区国产精品 | 欧美日韩免费看 | 国产精品久久久久久久专区 | 88av在线| 国产资源av| 久久精品一二三区 | 日本女v片 | 蜜臀av性久久久久蜜臀aⅴ | 伊伊综合网 | 手机看片日韩欧美 | 亚洲丁香婷婷 | 老司机福利av | 日韩精品免费看 | 色av影院| 狠狠躁日日躁夜夜躁av | 国产一区色 | 久久久久久久无码 | 91视频社区 | 亚洲淫| 欧美成人va| 日韩福利视频 | 国产91九色 | 哪个网站可以看毛片 | 自拍天堂 | 亚洲天堂久 | 草莓视频在线观看入口w | 精品亚洲国产成人av制服丝袜 | 国产精品伦一区二区三区免费看 | 极品美女无套呻吟啪啪 | 男女插孔视频 | 四色成人| 中年夫妇啪啪高潮 | 日韩精品一区二区三区视频在线观看 | 色国产在线| 超碰97国产 | 网站在线免费观看 | 久久福利国产 | 一级黄色录像大片 | sao浪受的饥渴日常 91免费入口 | 天天色av| 成人午夜在线观看 | 亚洲AV无码一区二区三区蜜桃 | 丹丹的呻吟声1一7 | 亚洲一区二区在线电影 | 台湾佬成人中文网222vvv | 日本污视频在线观看 | 国内黄色一级片 |