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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

Lines(HDU-5124)

發布時間:2025/3/17 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Lines(HDU-5124) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Problem Description

John has several lines. The lines are covered on the X axis. Let A is a point which is covered by the most lines. John wants to know how many lines cover A.

Input

The first line contains a single integer T(1≤T≤100)(the data for N>100 less than 1 cases),indicating the number of test cases.?
Each test case begins with an integer N(1≤N≤105),indicating the number of lines.?
Next N lines contains two integers Xi and Yi(1≤Xi≤Yi≤109),describing a line.

Output

For each case, output an integer means how many lines cover A.

Sample Input

2
5
1 2?
2 2
2 4
3 4
5 1000
5
1 1
2 2
3 3
4 4
5 5

Sample Output

3
1

題意:t 組數據,每組給出 n 個區間?[xi,yi],求這些區間段所覆蓋的最多的點

思路:?對于一個區間 [xi,yi],將其分為兩個端點 xi、yi,在 xi 端點時該點會新加入一條新的線段,而對于 yi+1 的點,在該點時會減少一條線段,因此可以將給出的 2n 個端點進行排序,同時,令 xi 價值為 1,yi 價值為 -1,這樣一來,問題就由區間覆蓋轉換你為了最大區間和,由于 1 一定在 -1 之前,因此問題又轉換為了最大前綴和,尋找最大值即可

Source Program

#include<iostream> #include<cstdio> #include<cstdlib> #include<string> #include<cstring> #include<cmath> #include<ctime> #include<algorithm> #include<utility> #include<stack> #include<queue> #include<vector> #include<set> #include<map> #define PI acos(-1.0) #define E 1e-6 #define MOD 1000000007 #define INF 0x3f3f3f3f #define N 100001 #define LL long long using namespace std; int n; pair<int,int> a[N*2];//由于將區間轉為點,需要進行擴容 int main(){int t;scanf("%d",&t);while(t--){scanf("%d%",&n);n*=2;for(int i=1;i<=n;i++){scanf("%d",&a[i].first);//左端點xia[i].second=1;//左端點賦值i++;scanf("%d",&a[i].first);//右端點yia[i].first++;//右端點后移一位a[i].second=-1;//右端點賦值}sort(a+1,a+1+n);//默認對第一個元素升序排序int maxx=-INF;int sum=0;for(int i=1;i<=n;i++){sum+=a[i].second;//求前綴和maxx=max(maxx,sum);///記錄最大值}printf("%d\n",maxx);}return 0; }

?

總結

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

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