NOIP2015普及组 —— 推销员(salesman)

#include 
#include 
using namespace std;
ifstream fin("salesman.in");
ofstream fout("salesman.out");

const int MAX_N = 100000, INT_MIN = 1<<31;

struct Tnode
{
    int a, id;
} a[MAX_N];
int S[MAX_N], A[MAX_N], rmax[MAX_N];
int Head_a = 0;

bool cmp(const Tnode &, const Tnode &);

void Build_a(int);
void Build_rmax(int);
int LMax();
int RMax();
void Update_a(int);
void Update_rmax(int);

int main()
{
    int N;
    fin>>N;
    for (int i=0; i>S[i];
    for (int i=0; i>A[i];

    Build_a(N);
    Build_rmax(N);

    int Last_Max = rmax[0];
    int Ans = S[Last_Max]<<1+A[Last_Max];
    fout<0]] = INT_MIN;
    a[0].a = INT_MIN;
    Update_rmax(rmax[0]);

    int Left_Max_id, Right_Max_id, Left_Max, Right_Max;
    for (int i=1; iwhile (visit[a[Left_Max_id].id] && Left_Max_id1 + A[Right_Max_id];

        if (Left_Max > Right_Max)
        {
            Ans += Left_Max;
            Last_Max = Left_Max_id;
            Update_a(Left_Max_id);
        }
        else
        {
            Ans += Right_Max;
            Last_Max = Right_Max_id;
        //  Update_rmax(Right_Max_id);
        }
        fout<return 0;
}

bool cmp(const Tnode &A, const Tnode &B)
{
    return A.a < B.a ? true : false;
}

void Build_a(int n)
{
    for (int i=0; ivoid Build_rmax(int n)
{
    rmax[n-1] = n-1; 
    int Right_Max = S[n-1]<<1 + A[n-1];
    int Now_Max;
    for (int i=n-2; i>=0; i--)
    {
        Now_Max = S[i]<<1 + A[i];
        if (Now_Max > Right_Max)
        {
            rmax[i] = i;
            Right_Max = Now_Max;
        }
        else
            rmax[i] = rmax[i-1];
    }
}

int LMax()
{
    return Head_a;
}
void Update_a()
{
    Head_a++;
}

你可能感兴趣的:(NOIP2015)