Describe
Eagles are most proud of soaring, but the Eagles are jealous of each other eagles fly faster than themselves, more jealous of other eagles than their own flying skills. So they decided to hold a game where the game would be in a maze.
The starting point of these eagles is located in the lower left corner of the lower left corner of a n*m matrix map[1,1]. The end point is set in the upper right corner of the map[n,m] in the upper right corner of the matrix, and some map[i,j] can be traversed from it. Every square of the side length is 100 meters. :
There are no obstacles, no dead ends. This design is mainly for high-speed flying hawks do not find the dead end too late to adjust the accident. The Pampas Eagle risked reducing the RP's risk of stealing the construction map from the heavily guarded base of the tournament organizers. But the problem followed, and he had to figure out every road in the map before the start of the game and find a way to get to the finish line. (Haha, stupid birds do not fly first to take the championship) but this eagle is no Furutaka, and then no eagle to eat vegetables grow up eagle-Rookie. He has no way to get the shortest path, so urgent to find the learning Oi you, hope to find your help.
Input
There are multiple sets of data. A flag that ends with EOF as input.
The first behavior of each group of test data is n,m (0<n,m<=1000000), and the 2nd behavior, K (0<k<=1000), indicates how many special edges there are. The following K acts two numbers, i,j means that map[i,j] can be traversed directly.
Output
Only one row, the length of the shortest path of the 1,1-->n,m, rounded and preserved to an integer
Sample input
3 2
3
1 1
3 2
1 2
Sample output
383
This problem in fact seriously look should be found to be the longest ascending sequence, the problem is similar to the rectangle nested that problem, understand that this is really very simple to do, so this algorithm really does not speak, the key you have to see is called you to find the longest ascending sequence, time complexity O (k*k); Finally, a little attention to processing rounding
AC Code:
# include <cstdio># include <cstdlib># include <cstring># include <cmath># include <algorithm >using namespace std;struct seg{int x;int y;}; SEG s[1010];int dp[1010];int Compare (seg A, seg b) {if (a.x!=b.x) {return a.x<b.x;} return A.Y<B.Y;} int main () {int n, m, K, I, J, Max;double Ans;while (scanf ("%d%d%d", &n, &m, &k)!=eof) {for (i=1; i<=k; i++) {DP [I]=1;} Max=-1;dp[1]=1;for (i=1; i<=k; i++) {scanf ("%d%d", &s[i].x, &S[I].Y);} Sort (s+1, s+k+1, Compare); for (i=2; i<=k; i++) {for (j=1; j<i; J + +) {if (s[i].x>s[j].x&&s[i].y>s[j].y {Dp[i]=max (dp[j]+1, Dp[i]);}} Max=max (Max, dp[i]);} Ans= (m+n-max*2) *100+100.0*sqrt (2.0) *max;int c= (int) (ANS*10)-(int) ans*10;if (c<=4) {printf ("%d\n", (int) ans);} else{printf ("%d\n", (int) ans+1);}} return 0;}
Nyoj 195 Flight (Dynamic planning)