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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

CDOJ 482 Charitable Exchange bfs

發布時間:2023/12/15 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 CDOJ 482 Charitable Exchange bfs 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Charitable Exchange

Time Limit: 20 Sec

Memory Limit: 256 MB

題目連接

http://acm.uestc.edu.cn/#/problem/show/482

Description

Have you ever heard a star charity show called Charitable Exchange? In this show, a famous star starts with a small item which values $1$ yuan. Then, through the efforts of repeatedly exchanges which continuously increase the value of item in hand, he (she) finally brings back a valuable item and donates it to the needy.

In each exchange, one can exchange for an item of Vi yuan if he (she) has an item values more than or equal to $R_i$ yuan, with a time cost of $T_i$ minutes.

Now, you task is help the star to exchange for an item which values more than or equal to $M$ yuan with the minimum time.

Input

The first line of the input is $T$ (no more than $20$), which stands for the number of test cases you need to solve.

For each case, two integers $N$, $M$ ($1 \leq N \leq 10^5$, $1 \leq M \leq 109$) in the first line indicates the number of available exchanges and the expected value of final item. Then $N$ lines follow, each line describes an exchange with $3$ integers $V_i$, $R_i$, $T_i$ ($1 \leq R_i \leq V_i \leq 10^9$, $1 \leq T_i \leq 109$).

Output

For every test case, you should output?Case #k:?first, where $k$ indicates the case number and counts from $1$. Then output the minimum time. Output $-1$ if no solution can be found.

Sample Input

3
3 10
5 1 3
8 2 5
10 9 2
4 5
2 1 1
3 2 1
4 3 1
8 4 1
5 9
5 1 1
10 4 10
8 1 10
11 6 1
7 3 8

Sample Output

Case #1: -1
Case #2: 4
Case #3: 10

HINT

?

題意

每一個物品價值為x,可以由價值為r的物品來換,需要花費t秒

然后問你最小花費多少秒能夠得到價值至少為m的物品

一開始你有價值為1的物品

題解:

為毛我的dp+線段樹優化t了,迷的不行

正解用優先隊列,然后直接bfs就好了

代碼

#include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <set> #include <vector> #include <sstream> #include <queue> #include <typeinfo> #include <fstream> #include <map> #include <stack> typedef long long ll; using namespace std; //freopen("D.in","r",stdin); //freopen("D.out","w",stdout); #define sspeed ios_base::sync_with_stdio(0);cin.tie(0) #define test freopen("test.txt","r",stdin) const int maxn=202501; #define mod 1000000007 #define eps 1e-9 const int inf=0x3f3f3f3f; const ll infll = 0x3f3f3f3f3f3f3f3fLL; inline ll read() {ll x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f; } //**************************************************************************************struct node {ll r,v,t; }a[maxn]; bool cmp(node aa,node bb) {if(aa.r==bb.r&&aa.v==bb.v)return aa.t<bb.t;if(aa.r==bb.r)return aa.v<bb.v;return aa.r<bb.r; } struct node2 {ll x,t;bool operator<(const node2 &p1)const{return t>p1.t||t==p1.t&&x>p1.x;} }; ll ans=0; int n,m; ll bfs() {priority_queue<node2>q;node2 xx;xx.x=1;xx.t=0;q.push(xx);int B=0;int i;ll anss=-1;while(!q.empty()){xx=q.top();q.pop();if(xx.x>=m){anss=xx.t;break;}for(i=B;i<=n;i++){if(a[i].r>xx.x)break;if(a[i].r<=xx.x&&a[i].v>xx.x){node2 kk;kk.x=a[i].v;kk.t=xx.t+a[i].t;q.push(kk);}}B=i;}return anss; } int main() {int t=read();for(int cas=1;cas<=t;cas++){n=read(),m=read();for(int i=0;i<n;i++)a[i].v=read(),a[i].r=read(),a[i].t=read();sort(a,a+n,cmp);ans=0;ans=bfs();printf("Case #%d: %lld\n",cas,ans);} }

?

?

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的CDOJ 482 Charitable Exchange bfs的全部內容,希望文章能夠幫你解決所遇到的問題。

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