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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

poj3190 Stall Reservations(贪心+STL)

發(fā)布時(shí)間:2023/12/20 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 poj3190 Stall Reservations(贪心+STL) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

https://vjudge.net/problem/POJ-3190

cin和scanf差這么多么。。tle和300ms

思路:先對結(jié)構(gòu)體x升序y升序,再對優(yōu)先隊(duì)列重載<,按y升序。

  然后依次入隊(duì),如果node[i].x<=q.top().y ans++, 否則出隊(duì),入隊(duì),使用出隊(duì)的那個(gè)攤位。

1 #include<iostream> 2 #include<cstdio> 3 #include<queue> 4 #include<cstring> 5 #include<algorithm> 6 #include<cmath> 7 #include<set> 8 #define INF 0x3f3f3f3f 9 typedef long long ll; 10 using namespace std; 11 struct Node{ 12 int x, y; 13 int id; 14 bool operator<(const Node &a)const{ 15 return y > a.y; 16 } 17 }node[50010]; 18 int n, maxm = -INF, b[50010]; 19 bool cmp(const Node a, const Node b) 20 { 21 if(a.x != b.x) 22 return a.x<b.x; 23 return a.y<b.y; 24 } 25 int main() 26 { 27 scanf("%d", &n); 28 int ans = 1; 29 for(int i = 0; i < n; i++){ 30 scanf("%d%d", &node[i].x, &node[i].y); 31 node[i].id=i+1; 32 } 33 sort(node, node+n, cmp); 34 priority_queue<Node> q; 35 q.push(node[0]); 36 b[node[0].id] = ans; 37 for(int i = 1; i < n; i++){ 38 Node t = q.top(); 39 if(node[i].x <= t.y){ 40 q.push(node[i]); 41 ans++; 42 b[node[i].id] = ans; 43 //maxm = max(maxm, ans); 44 } 45 else if(node[i].x > t.y){ 46 q.pop(); 47 q.push(node[i]); 48 b[node[i].id] = b[t.id]; 49 //cout << b[t.id] << "t"; 50 } 51 } 52 printf("%d\n", ans); 53 for(int i = 1; i <= n; i++){ 54 printf("%d\n", b[i]); 55 } 56 57 return 0; 58 }

?

轉(zhuǎn)載于:https://www.cnblogs.com/Surprisezang/p/9000363.html

總結(jié)

以上是生活随笔為你收集整理的poj3190 Stall Reservations(贪心+STL)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。