首页 > 其他分享 >UESTC 482 Charitable Exchange(优先队列+bfs)

UESTC 482 Charitable Exchange(优先队列+bfs)

时间:2022-10-18 15:00:42浏览次数:70  
标签:term2 Exchange int long UESTC bfs value time include

Charitable Exchange

Time Limit: 4000/2000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others)

Submit  Status

Have you ever heard a star charity show called Charitable Exchange? In this show, a famous star starts with a small item which values 11

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

Now, you task is help the star to exchange for an item which values more than or equal to MM

Input

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

For each case, two integers NN, MM (1≤N≤1051≤N≤105, 1≤M≤1091≤M≤109) in the first line indicates the number of available exchanges and the expected value of final item. Then NN lines follow, each line describes an exchange with 33 integers ViVi, RiRi, TiTi (1≤Ri≤Vi≤1091≤Ri≤Vi≤109, 1≤Ti≤1091≤Ti≤109).

Output

For every test case, you should output ​​Case #k:​​ first, where kk indicates

the case number and counts from 11. Then output the minimum time. Output −1−1

Sample input and output

Sample Input

Sample Output

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
优先队列 贪心+bfs
#include <iostream>


#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <queue>

using namespace std;
#define MAX 100000
struct Node
{
long long int v;
long long int r;
long long int t;
}a[MAX+5];
struct node
{
long long int value;
long long int time;
bool friend operator <(node a,node b)
{
return a.time>b.time;
}

};
priority_queue<node> q;
int n,m;
int right1;
int cmp(Node a,Node b)
{
return a.r<b.r;
}
long long int bfs()
{
node term1;
term1.value=1;term1.time=0;
q.push(term1);
int left=1,i;
while(!q.empty())
{
node term2=q.top();
q.pop();
if(term2.value>=m)
{
return term2.time;
}
for(i=left;i<=right1;i++)
{
if(term2.value>=a[i].r&&term2.value<a[i].v)
{
node temp;
temp.value=a[i].v;
temp.time=term2.time+a[i].t;
q.push(temp);
}
if(term2.value<a[i].r)
break;

}
left=i;

}
return -1;
}
int main()
{
int t;
int cas=0;
scanf("%d",&t);
long long int vv,rr,tt;
while(t--)
{
scanf("%d%d",&n,&m);
right1=0;
for(int i=1;i<=n;i++)
{
scanf("%lld%lld%lld",&vv,&rr,&tt);
if(vv==rr)
continue;
a[++right1].v=vv;a[right1].r=rr;a[right1].t=tt;
}
while(!q.empty())
q.pop();
sort(a+1,a+1+right1,cmp);
printf("Case #%d: %lld\n",++cas,bfs());
}
return 0;
}
Case #1: -1
Case #2: 4
Case #3: 10



标签:term2,Exchange,int,long,UESTC,bfs,value,time,include
From: https://blog.51cto.com/u_15834522/5766703

相关文章

  • HDU 1885 Key Task(BFS)
    KeyTaskTimeLimit:3000/1000MS(Java/Others)    MemoryLimit:32768/32768K(Java/Others)TotalSubmission(s):1809    AcceptedSubmission(s):770Pr......
  • Exchange Online 发送邮件
    项目背景2022年10月4日微软更改了Exchange的验证方式,原来exchangelib的库没法继续实现邮件的发送。实现方式利用MicrosoftGraphAPI里  发送邮件-MicrosoftGrap......
  • Leetcode 117 -- 树&&bfs
    题目描述填充每个节点的下一个节点题目要求我们填充每个节点的\(next\)指针,让它指向它的(同一层)右侧的节点,如果没有,指向$NULL,(初始时全部指向\(NULL\))。思路看到......
  • Exchange零日漏洞缓解措施
    点开参考文档注:此文章只是记录,使用前要根据自己的生产环境是否可用该方式。下面的处理方法会影响autodiscover自动发现配置邮箱。如图打开IIS双击打开URL重写模块......
  • 横向移动-Exchange
    1、端口扫描exchange会对外暴露接口如OWA,ECP等,会暴露在80端口,而且25/587/2525等端口上会有SMTP服务,所以可以通过一些端口特征来定位exchange。2、SPN扫描powershell......
  • POJ 2227 The Wedding Juicer(三维接雨水 BFS 贪心
    POJ2227TheWeddingJuicer(三维接雨水BFS贪心)题意:​ 给出一个二维地图,其各点上权值为其高度。如果向其中填水,请问在这张地图中可以积得多少水。​ 地图长宽为300,高......
  • POJ 3697 USTC campus network(BFS 删边)
    POJ3697USTCcampusnetwork(BFS删边)题意:​ 有一张图,每个点\(n\le10000\)之间都有一条边。现在删去若干条边\(m\le1000000\),请问还有多少点是联通的。思路:​ 我......
  • exchange邮件爬虫
    #!/usr/bin/python3#coding=utf8from__future__importprint_functionimportshutilfromexchangelibimportCredentials,Account,Configuration,DELEGATE,Fi......
  • 07-RabbitMQ核心API-Direct Exchange
    DirectExchange简介所有发送到directexchange的消息被转发到Routekey中指定的Queue注意:Direct模式可以使用RabbitMQ自带的Exchange(defaultexchange),所以不需......
  • 08-RabbitMQ核心API-Topic Exchange
    TopicExchange简介所有发送到TopicExchange的消息被转发到所有关心RouteKey中指定Topic的Queue上Exchange将RouteKey和某Topic进行模糊匹配,此时队列需要绑定一个T......