Posted by Dusign on
2019-11-12
Words 363 and
Reading Time 1 Minutes
Viewed Times
Algorithms change the world. The importance of algorithms is self-evident to a programmer, so the practice of some algorithms is indispensable. Next, I will share some algorithmic problems.
intmax(int a, int b){ int tmp = a; if(b > a) tmp = b; return tmp; }
intmin(int a, int b){ int tmp = a; if(b < a) tmp = b; return tmp; }
voidsolve(int L, int n, int *x){ int minT = 0, maxT = 0; for(int i = 0; i < n; i++){ minT = max(minT, min(x[i], (L - x[i]))); maxT = max(maxT, max(x[i], (L - x[i]))); } cout << minT <<endl; cout << maxT <<endl; }
intmain(){ int L, n, x[MAP_SIZE]; cin >> L >> n; for(int i = 0; i < n; i ++){ cin >> x[i]; } solve(L, n, x); }
If you like this blog or find it useful for you, you are welcome to comment on it. You are also welcome to share this blog, so that more people can participate in it. If the images used in the blog infringe your copyright, please contact the author to delete them. Thank you !
If you like this blog or find it useful for you, you are welcome to comment on it. You are also welcome to share this blog, so that more people can participate in it. If the images used in the blog infringe your copyright, please contact the author to delete them. Thank you !