Codevs 1139 Sightseeing Bus

Source: Internet
Author: User

/*A glimpse of greed is the key to greed, considering that each passenger's travel time is only counted on the car. Not too much to see is the number of passengers per section of the road the more passengers use the accelerator card and then self-confidence to pay 10 points ....*/#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#defineMAXN 10010using namespacestd;intN,m,k,t[maxn],f[maxn],s[maxn],ans;structnode{intnum,o,t;} P[MAXN];structpeople{intTi,u,v;} PEO[MAXN];intCMP (node X,node y) {returnX.num>Y.num;}intMain () {//freopen ("bus.in", "R", stdin); //freopen ("Bus.out", "w", stdout);scanf"%d%d%d",&n,&m,&k);  for(intI=1; i<=n-1; i++) scanf ("%d",&T[i]); intU,v,ti,pre;  for(intI=1; i<=n;i++) P[I].O=i;  for(intI=1; i<=m;i++) {scanf ("%d%d%d",&ti,&u,&v); Peo[i].ti=ti;peo[i].u=u;peo[i].v=v; S[u]=Max (S[u],ti);  for(intj=u;j<=v;j++) p[j].num++; } sort (P+1, p+1+n,cmp); Pre=s[1];  for(intI=1;; i++)      if(t[p[i].o]>=k) {T[P[I].O]-=K;  Break; }      Elsek-=t[p[i].o],t[p[i].o]=0;  for(intI=2; i<=n;i++) {F[i]=pre+t[i-1]; Pre=max (pre+t[i-1],s[i]); }     for(intI=1; i<=m;i++) ans+=f[peo[i].v]-Peo[i].ti; printf ("%d\n", ans); return 0;}
/*The above idea is not difficult to find the problem obviously did not take into account every departure must wait for the people to come to the full assumption again we carry the most people fly to the next station however, there are not a few people get off immediately then the passengers still have to wait for the whole person to go back to the time not much less obvious greedy error The following is a positive solution (actually see him is a year Noip D2 T3 know so simple greed will hang off) considering the need to wait for people to go all the car to leave so we each use an accelerator card when it will affect the back of several times the arrival time but not all we have to do is the statistics can affect where not using an accelerator card We're going to look for the longest segment of the affected line, and then the first time--update the next arrival time and update each point to see where it's going to affect that. The time to save this acceleration is the number of people who get off the bus. We can pre-count the time without acceleration*/#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#defineMAXN 10010using namespacestd;intN,M,K,T[MAXN],F[MAXN],S[MAXN],ANS,NUM[MAXN],G[MAXN];structpeople{intTi,u,v;} P[MAXN];voidsolve () {intmaxx=0, L,r;  for(intI=1; i<=n;i++)      if(maxx<num[g[i]]-num[i]&&t[i]>0) {L=i;r=G[i]; Maxx=num[g[i]]-Num[i]; } T[l]--;if(r>n-1) r=n-1; ans-=Maxx;  for(inti=l;i<=r;i++) F[i]=max (f[i-1],s[i-1]) +t[i-1];  for(inti=r;i>=l;i--)      if(f[i+1]<=s[i+1]) g[i]=i+1; Elseg[i]=g[i+1];}intMain () {//freopen ("bus.in", "R", stdin); //freopen ("Bus.out", "w", stdout);scanf"%d%d%d",&n,&m,&k);  for(intI=1; i<=n-1; i++) scanf ("%d",&T[i]); intU,v,ti;  for(intI=1; i<=m;i++) {scanf ("%d%d%d",&ti,&u,&v); P[i].ti=ti;p[i].u=u;p[i].v=W; S[u]=max (S[u],ti); num[v]++; }     for(intI=2; i<=n;i++) num[i]+=num[i-1];  for(intI=1; i<=n;i++) F[i]=max (f[i-1],s[i-1]) +t[i-1]; G[n]=g[n-1]=N;  for(inti=n-2; i>=1; i--)      if(f[i+1]<=s[i+1]) g[i]=i+1; Elseg[i]=g[i+1];  for(intI=1; i<=m;i++) ans+=f[p[i].v]-P[i].ti;  for(intI=1; i<=k;i++) solve (); printf ("%d\n", ans); return 0;}

Codevs 1139 Sightseeing Bus

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.