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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

牛客 - 云(扫描线)

發布時間:2024/4/11 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 牛客 - 云(扫描线) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目鏈接:點擊查看

題目大意:在第一個象限內有數個矩形,在第三象限內也有數個矩形,現在第一象限內的矩形向下移動,第三象限內的矩形向右移動,所有矩形的移動速度相同,現在問有多少對矩形可以在第四象限內相交

題目分析:如果直接去求解會比較困難,因為所有的矩形都在移動,但我們可以將模型抽取出來,每次移動的相對運動都比較直接,所有的矩形都沿著 y = x 這條直線相對運動,這樣一來我們就可以將所有的矩形投影到 y = - x 這條直線上去,然后用掃描線O(n)計算出貢獻了

代碼:

#include<iostream> #include<cstdio> #include<string> #include<ctime> #include<cmath> #include<cstring> #include<algorithm> #include<stack> #include<climits> #include<queue> #include<map> #include<set> #include<sstream> #include<unordered_map> using namespace std;typedef long long LL;typedef unsigned long long ull;const int inf=0x3f3f3f3f;const int N=1e5+100;struct Node {int x,type,state;Node(int x,int state,int type):x(x),state(state),type(type){}bool operator<(const Node& a)const{if(x!=a.x)return x<a.x;if(state!=a.state)return state>a.state;} };vector<Node>node;int cnt[2];int main() { //#ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); //#endif // ios::sync_with_stdio(false);int n,m;scanf("%d%d",&n,&m);for(int i=1;i<=n;i++){int a,b,c,d;scanf("%d%d%d%d",&a,&b,&c,&d);node.push_back(Node(a-b,1,0));node.push_back(Node(c-d,-1,0));}for(int i=1;i<=m;i++){int a,b,c,d;scanf("%d%d%d%d",&a,&b,&c,&d);node.push_back(Node(a-b,1,1));node.push_back(Node(c-d,-1,1));}sort(node.begin(),node.end());LL ans=0;for(auto it:node){cnt[it.type]+=it.state;if(it.state==1)ans+=cnt[it.type^1];}printf("%lld\n",ans);return 0; }

?

總結

以上是生活随笔為你收集整理的牛客 - 云(扫描线)的全部內容,希望文章能夠幫你解決所遇到的問題。

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