Describe
Small A and little B decide to take vacation trips, they will want to go to the city from 1 to n numbered, and the smaller number of cities in the west of the numbered cities, the cities are known to be different altitude, the city I of the altitude of Hi, city I and the distance between the city J D[i,j] is exactly the absolute value of the difference in altitude of these two cities, i.e. d[i,j] = | hi-hj|.
During the trip, small A and small b take turns driving, the first day small a drive, after the rotation once a day. They plan to choose a city s as a starting point, always going east, and traveling at a maximum of x kilometres. Small A and little B have different driving styles, little b always chooses a nearest city as its destination along the way, while little a always chooses the second-closest city as the destination (note: If the current city is the same distance from the two cities, it is considered to be closer to the lower elevation). If any of them cannot choose the destination city according to their own principles, or if they arrive at a destination that will drive the total distance beyond x km, they will end the trip.
Before departing, little a wants to know two questions:
1. For a given x=x0, from which city to start, the total number of small a driving distance and the total number of small B travel distance is the smallest (if the small B driving distance is 0, at this time the ratio can be regarded as infinity, and two infinity as equal). If you start from more than one city, the total number of small a driving distance and the total number of small B travel distance is the smallest, then output the highest altitude of the city.
2. For any given x=xi and departure city Si, the total number of small a driving distance and the total number of small B travel. Format input Format
The first row contains an integer n that represents the number of cities.
The second row has n integers, separated by a space between each two integers, which in turn indicates the elevation of the city 1 to the city N, i.e. H1,h2,......,hn, and each hi is different.
The third row contains an integer X0.
The Forth act an integer m, which represents the given M-group Si and XI.
The next line of M, each containing 2 integers, Si and Xi, represents a maximum of Xi kilometres from the city Si. Output format
Outputs a total of m+1 rows.
The first line contains an integer S0, indicating that for the given X0, from the city numbered S0, little a drives
The total number of miles travelled is the smallest of the total distance travelled by small B.
The next line of M, each containing 2 integers, is separated by a single space, which in turn represents the total mileage of the small A and the total number of miles travelled under the given Si and XI. Example 1 Sample input
4
2 3 1, 4 3 4 1 3 2 3 3 3 4 3
Sample output
1
1 1
2 0
0 0
0 0
Example 2 Sample Input
4 5 6 1 2 3 7 8 9 ten 7 1 7 2 7 3 7 4 7 5 7 6 7 7 7 8 7 9
7
10 7
Sample output
2
3 2
2 4
2
1
2 4 5 1 5 1 2 1 2 0 0 0
Limit
1s tips per test point
For 30% of the data, there are 1≤n≤20,1≤m≤20;
For 40% of the data, there are 1≤n≤100,1≤m≤100;
For 50% of the data, there are 1≤n≤100,1≤m≤1,000;
For 70% of the data, there are 1≤n≤1,000,1≤m≤10,000;
For 100% of the data, there are 1≤n≤100,000,1≤m≤10,000,-1,000,000,000≤hi≤1,000,000,000,0≤x0≤1,000,000,000,1≤si≤n,0≤xi≤1, 000,000,000, the data guarantee that hi is different. Source
Noip2012 to improve the group-rematch DAY1T3
The problem comes to the simulation ....
T3 is incredibly analog ...
In fact, 70 points feel very simple
First, preprocessing the shortest short time of destination and distance for each point backwards
And then simulate it.
。。。。。。。。
The other ratio, it's going to be 1.9 billion to 70.
At first, 900,000,999 out of 65 is good.
Without long long can also be 70 = =
Stick Code.
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace
Std
const int lim=1011;
const int inf=1999999999; struct Side{int x,y,h,w;}
S[lim*lim]; struct Self{int first,nxt,fw,nw;}
G[lim];
int M,casenum,n,a,b,c,h[lim];
int X,y,l,r,ans,ansh;
Double bizhi=0; inline int Abs (int i) {return i<0?-i:i.} int cmp (side a1,side A2) {return a1.w==a2.w?a1.h<a2.h:a1.w<a2.w;} void Yu
Chuli () {int a,b,c;
for (a=1;a<=m;a++) for (b=a+1;b<=m;b++) {n++;
S[n].x=a;
S[n].y=b;
S[N].H=H[B];
S[n].w=abs (H[a]-h[b]);
Sort (s+1,s+n+1,cmp);
for (a=1;a<=n;a++) {int u=s[a].x;
if (g[u].fw==0) {G[U].FIRST=S[A].Y;G[U].FW=S[A].W;}
else if (g[u].nw==0) {G[U].NXT=S[A].Y;G[U].NW=S[A].W} else if (G[U].FW>S[A].W)}} void work (int from,int dis,int now) {//cout<< "work" ("<<from<<") , "<<dis<< "," <<now<< ")" <<endl;
if (now==1) {if (DIS<G[FROM].NW) return;
if (g[from].nxt==0) return;
L+=G[FROM].NW;
Work (g[from].nxt,dis-g[from].nw,2);
else {if (DIS<G[FROM].FW) return;
if (g[from].first==0) return;
R+=G[FROM].FW;
Work (g[from].first,dis-g[from].fw,1);
int main () {scanf ("%d", &m);
for (a=1;a<=m;a++) scanf ("%d", &h[a]);
Yuchuli (); for (a=1;a<=n;a++) cout<<s[a].x<< "<<s[a].y<<" "<<s[a].h<<" "<<s[a]
.w<<endl; for (a=1;a<=m;a++) cout<< "g[" <<a<< "]=" <<g[a].first<< "" <<g[a].fw<<
"" <<g[a].nxt<< "" <<g[a].nw<<endl;
scanf ("%d", &y);
Bizhi=inf;
for (a=1;a<=m;a++) {l=r=0; Work (a,y,1);
From a person 1 Length Y if (r==0&&h[a]>ansh&&bizhi>inf-1) {Ansh=h[a];
Ans=a;
} if (r!=0&& (double) L/r<bizhi) {Ansh=h[a];
Ans=a;
Bizhi= (double) L/R; }//cout<< "A=" <<a<< "ans=" <<ans<< "bizhi=" <<bizhi<< "l=" <<l<<
; "R=" <<r<<endl;
printf ("%d\n", ans);
scanf ("%d", &casenum);
while (Casenum) {casenum--;
scanf ("%d%d", &x,&y);
l=r=0;
Work (x,y,1);
printf ("%d%d\n", l,r);
return 0;
}
AC procedure
If you have time, then look at it.
Noip rp++