JZOJ5415. NOIP2017 to improve Group A training 10.22 public transport Dp__jzoj

Source: Internet
Author: User

I won't say it.

A little ghost animals, the game will only 50 points, spent 30 minutes thinking nothing, even by the mode of grouping did not expect to retire sooner or later.
Then spent 10 minutes playing 50 points to throw the problem. Big loss.
In fact, the game has one hours left to find the slope optimization, but no time to play so let's put it.
In fact, this is not a simple slope optimization, because if the direct does not guarantee that his slope is monotonically increasing.
First, the dots are grouped, and only the same points in%c can be reached.
Then you can directly slope optimization, each time first enumerated C, for the stack point, we put the stack top and the previous one out, if the stack top to i the answer is not as good as the first to I answer, that must be kicked out of the stack top. It is said that only doing this optimization can take 80.
Then you can directly monotonically increase the maintenance slope.
Pay attention to the implementation of the best linked list will be more convenient.

#include <cstdio> #include <algorithm> #include <cstring> #include <iostream> #include <
cstring> #include <queue> #define FO (i,a,b) for (int i=a;i<=b;i++) #define FD (I,A,B) for (int i=a;i>=b;i--)
using namespace Std;
const int n=1e6+5;
typedef double DB;
int c[n],v[n],n,maxc,cnt,q[n];
typedef long Long LL;
int f[n],sta[n],h[15][15],t[15][15],last[n],next[n];
int top,inf=1e9;
DB K[n]; inline int get (int j,int i) {return (I-J)/c[j]*v[j]+f[j]; double getk (int j,int k) {return (double) 1.0* (k/c[k)
*V[K]-J/C[J]*V[J]+F[J]-F[K])/(V[k]-v[j]);
    int main () {freopen ("bus.in", "R", stdin);
    Freopen ("Bus.out", "w", stdout);
    scanf ("%d%d", &AMP;N,&AMP;MAXC);
        Fo (i,1,n) {scanf ("%d%d", &c[i],&v[i]);
    F[i+1]=inf;
    } h[c[1]][1%c[1]]=t[c[1]][1%c[1]]=1;
            Fo (i,2,n+1) {fo (j,1,maxc) {int x=i%j;
            if (!h[j][x]) continue; while (h[j][x]!=t[j][x]&&t[j][x]&&get (t[j][x],i) >get (last[t[j][x]],i)) t[j][x]=last[t[j][x]],next[t[j][x]]=0;
        F[i]=min (F[i],get (t[j][x],i)); } if (i==n+1| |
        F[i]==inf) continue;
        int x=c[i],y=i%x;
            while (T[x][y]&&v[t[x][y]]>=v[i]) t[x][y]=last[t[x][y]],next[t[x][y]]=0;
        if (!t[x][y]) h[x][y]=0; while (H[X][Y]!=T[X][Y]&AMP;&AMP;T[X][Y]&AMP;&AMP;GETK (Last[t[x][y]],t[x][y]) &LT;GETK (t[x][y],i)) t[x][y]=last[t [x]
        [Y]],next[t[x][y]]=0;
        if (T[x][y]) next[t[x][y]]=i,last[i]=t[x][y];
        if (!h[x][y]) h[x][y]=i;
    T[x][y]=i;
    } fo (i,2,n+1) if (f[i]<inf) printf ("%d", f[i]);
    else printf ("%d",-1);
return 0; }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.