POJ 2287 Tian Ji--The Horse Racing

Source: Internet
Author: User

POJ 2287 Tian Ji--The Horse Racing

Test instructions
Tian Bogey horse racing
If 3 horses become 1000, King still let his horse in the order of favorably to inferior, Tian bogey can choose his horse racing in any order. Win a game, Tian Bogey can get 2002 silver, lose a game, Tian Bogey will lose 2002 silver, draw words do not lose not win.
How much can Tian bogey win?

Ideas:
Greedy
If the best horse of the present can win King the best horse, then let the two horses compare to one;
If the current worst horse wins King's worst horse, let the two horses be one;
If none of the above two conditions are met, then let the worst horse and King be the best.

/*POJ 2287  Test instructions:  Tian bogey horse race   if 3 horses become 1000, King still let his horse in the order of favorably to inferior, Tian bogey can choose his horse racing in any order. Win a game, Tian Bogey can get 2002 silver, lose a game, Tian Bogey will lose 2002 silver, draw words do not lose not win.   How much can Tian bogey win?  Idea:  greedy;  if the best horse can win King the best horse, then let the two horses than one,  if the current worst horse can win king the worst horse, then let the two horses than  one, if the above two conditions are not satisfied, Then make the worst horse and king the best horse ever. */#include <iostream> #include <cstdio> #include <algorithm>using namespace Std;const int N=1005;int a [N],b[n];void Gao (int N) {int p1=0,p2=0;int q1=n-1,q2=n-1;int ans=0;while (p1<=q1) {if (A[p1]>b[p2]) {++p1;++p2;++ Ans;} else if (A[q1]>b[q2]) {--q1;--q2;++ans;} Else{if (A[P1]!=B[Q2])--ans;++p1;--q2;} printf ("%d\n", ans*200);} int main () {int n;while (scanf ("%d", &n) && N) {for (Int. i=0;i<n;++i) scanf ("%d", &a[i]); for (int i=0;i <n;++i) scanf ("%d", &b[i]); sort (a,a+n); sort (b,b+n); Gao (n);} return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

POJ 2287 Tian Ji--The Horse Racing

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.