EDITORIAL
Still autistic game
T1 goods collection
Idea
Use a priority queue
For example, a sample
4 7
5 5 2
1 3 2
1 2 7
1 4 5
(Please add their own point right (funny
The right side can traverse points thrown into the queue.
So first went to 3, 5 to collect the goods, we need to force the value of 2
Goods is not enough to have gone to 4, 2 to collect the goods, the total cargo 7, we need to force the value 5. Cargo enough, the answer is 5.
Code
namespace Sol{
struct node{
int v,to,net;
}e[maxn<<1];
int n,M,tot,ans,cnt;
int head[maxn],a[maxn];
bool vis[maxn];
priority_queue<pair<int,int> >q;
inline void add(int x,int y,int z){
e[++tot].v=y; e[tot].to=z;
e[tot].net=head[x]; head[x]=tot;
}
inline int Main(){
n=read(); M=read();
for(int i=2;i<=n;i++) a[i]=read();
for(int i=1;i<n;i++){
int x=read(),y=read(),z=read();
add(x,y,z); add(y,x,z);
}
vis[1]=1;
for(int i=head[1];i;i=e[i].net){
int y=e[i].v;
vis[y]=1;
q.push(make_pair(-e[i].to,y));
}
while(ans<M){
int x=-q.top().first;//武力值
int y=q.top().second;//走到的节点
q.pop();
ans+=a[y];//收集到的总货物
cnt=max(cnt,x);//比较武力值
for(int i=head[y];i;i=e[i].net){
int yy=e[i].v;
if(vis[yy]) continue;
vis[yy]=1;
q.push(make_pair(-e[i].to,yy));
}
}
printf("%d",cnt);
return 0;
}
}
T2 goods group
Idea
Here there are articles blog and I'm thinking about, but nonetheless my constant relatively good?
Why posts blog? Because I'm lazy
Code
namespace Sol{
int n,M;
int f[maxn],s[maxn],a[maxn];
int maxx,minn;
inline int Main(){
n=read(); M=read();
for(int i=1;i<=n;i++){
a[i]=read();
s[i]=s[i-1]+a[i];
}
for(int i=1;i<=n;i++){
f[i]=f[i-1]-s[i-1];
maxx=a[i]; minn=a[i];
for(int j=i-2;j>=0&&s[j]>=s[i]-M;j--){
maxx=max(maxx,a[j+1]);
minn=min(minn,a[j+1]);
if(f[i]>f[j]-s[j]+maxx-minn)
f[i]=f[j]-s[j]+maxx-minn;
}
f[i]+=s[n];
}
printf("%lld",f[n]);
return 0;
}
}
Calculating terrain T3
Not write, waiting for an update
\ [\ mathcal The \ quad End \]
\ [May you out of half, yet still a teenager \]