11.7 CSP training camp before the game summary

11.7 CSP training camp before the game summary

Today is the one-day game

1. Revised morning: nothing to say

Yesterday T1, wrote a little thought, the height difference and maintain direct points of the discussion will be autistic people, plus sign + - different and the amount of change, will explode, then it may change between the first minus, the answer can then count back together, is the anti difficult truth.

#include<stdio.h>
#include<bits/stdc++.h>
#define maxn 200005
using namespace std;
long long Ht[maxn];
long long n,q,s,t;
long long Getdel(long long x)
{
   return x > 0 ? x * s : x * t; 
}
long long T=0;
int main()
{
    scanf("%lld%lld%lld%lld",&n,&q,&s,&t);
    s=-s;
    t=-t; 
    for(long long i=0;i<=n;i++)
    scanf("%lld",&Ht[i]);
    
    for(long long i=n;i;i--)
    Ht[i]-=Ht[i-1];
    
    for(long long i=1;i<=n;i++)
    
    T+=Getdel(Ht[i]);
    long long x,y;
    long long temp;
    while(q--)
    {
        scanf("%lld%lld%lld",&x,&y,&temp);
        T-=Getdel(Ht[x]);
        T-=Getdel(Ht[y+1]);
        Ht[x]+=temp;
        if(y+1<=n)
        Ht[y+1]-=temp;
        T+=Getdel(Ht[x]);
        if(y+1<=n)
        T+=Getdel(Ht[y+1]);
        printf("%lld\n",T);
    }
}

Dong then God is speaking of two questions, one about the DP is the shortest time and then seek another road is a pile of broken mouth Hu mathematical formulas. . Then identify problems wrong 233,333,333

A first channel code (I did not transfer, which is LCFjulao code)

#include<stdio.h>
#include<queue>
using namespace std;

#define INF 1000000000

int End[100005],Next[100005],Len[100005],Last[10004],tot;
int n,k,Dis[10004][12];
bool Inqueue[10005][12];
struct node{int p,t;};
bool operator<(node a,node b){return Dis[a.p][a.t]>Dis[b.p][b.t];}
priority_queue<node>q;

void Link(int x,int y,int l)
{
    tot++;
    End[tot]=y;
    Len[tot]=l;
    Next[tot]=Last[x];
    Last[x]=tot;
}

void DJ(int x)
{
    int i,j,t,y;
    node a;
    for(i=0;i<=n;i++)for(j=0;j<=k;j++)Dis[i][j]=INF;
    Dis[x][0]=0;
    a.p=x,a.t=0;
    q.push(a);
    Inqueue[x][0]=true;
    while(q.size())
    {
        x=q.top().p,t=q.top().t;
        q.pop();
        Inqueue[x][t]=false;
        for(i=Last[x];i;i=Next[i])
        {
            y=End[i];
            if(Dis[x][t]+Len[i]<=Dis[y][t])
            {
                Dis[y][t]=Dis[x][t]+Len[i];
                if(!Inqueue[y][t])
                {
                    a.p=y,a.t=t;
                    q.push(a);
                    Inqueue[y][t]=true;
                }
            }
            if(t<k&&Dis[x][t]<Dis[y][t+1])
            {
                Dis[y][t+1]=Dis[x][t];
                if(!Inqueue[y][t+1])
                {
                    a.p=y,a.t=t+1;
                    q.push(a);
                    Inqueue[y][t+1]=true;
                }
            }
        }
    }
}

int main()
{
    int m,s,t,a,b,c,i,ans=INF;
    scanf("%d %d %d",&n,&m,&k);
    scanf("%d %d",&s,&t);
    for(i=1;i<=m;i++)
    {
        scanf("%d %d %d",&a,&b,&c);
        Link(a,b,c);
        Link(b,a,c);
    }
    DJ(s);
    for(i=0;i<=k;i ++) years =min(ans,Dis[t][i]);
    printf("%d",ans);
}

 Then nothing to do, then the water channel tree title DP (DP would have to do with this)

 

#include <bits / STDC ++ H.>
 #define MAXN 10005
 #define INF 999999999
 the using  namespace STD;
 / * 
Conclusion: any point of the tree must be the longest distance to the diameter of the end of a distance 
so this problem can be by the first conclusions tree determined diameter 
seeking: find any point of the most distant point of the determined point T 
by the conclusion must be understood T tree diameter end, and then seek the point farthest from T S, and the conclusion is clear terminal S 
so ST is the diameter of the tree, and then again the conclusion of each point in this problem is the farthest distance max (dis [S], dis [T]); 
use to do this question two conclusions bit mean 
* /  
struct Node 
{ 
    int the To, Len; 
}; 
Vector <Node> the Map [MAXN];
 int Max_Dis = - INF;
 int S = 0 ;
 int the Type = 0 ;
 int Dis_S[maxn];
int Dis_T[maxn];
void Dfs1(int pos,int fa,int Dis)
{
//    cout<<Dis<<endl;
    if(Type==1)
    {
        Dis_S[pos]=Dis;
    }
    if(Type==2)
    {
        Dis_T[pos]=Dis;
    }
    if(Dis>=Max_Dis)
    {
        S=pos;
        Max_Dis=Dis;
    }
    for(int i=0;i<Map[pos].size();i++)
    {
        if(Map[pos][i].To!=fa)
        Dfs1(Map[pos][i].To,pos,Dis+Map[pos][i].Len);
    }
}
int main()
{
    int n;
    scanf("%d",&n);
    node temp;
    int x,y;
    for(int i=1;i<n;i++)
    {
        scanf("%d%d",&x,&y);
        temp.To=x;
        temp.Len=y;
        Map[i+1].push_back(temp);
        temp.To=i+1;
        Map[x].push_back(temp);
    }
    Type=0;
    Dfs1(1,1,0);
    int SS=S;
    Max_Dis=-inf;
    S=0;
    Type=1;
    Dfs1(SS,SS,0);
    int TT=S;
    Type=2;
    Max_Dis=-inf;
    Dfs1(TT,TT,0);
    for(int i=1;i<=n;i++)
    {
        printf("%d\n",max(Dis_T[i],Dis_S[i]));
    }
}

 

 

 

Guess you like

Origin www.cnblogs.com/pveds/p/11811306.html