[Bzoj 1034] [ZJOI2008] Bubble Hall BNB (class Tian bogey horse racing greedy)

Source: Internet
Author: User

http://www.lydsy.com:808/JudgeOnline/problem.php?id=1034

I would say that this is the revision of the POJ Tianji the horse racing ...

But the game rules of this topic slightly different, won 2 points, flat 1 points, lose no points, so greedy process and poj the problem slightly different, specific look at the code bar.

#include <iostream> #include <stdio.h> #include <stdlib.h> #include <string.h> #include < Algorithm> #define MAXN 100050using namespace Std;int a[maxn],b[maxn],n;int cal ()//Note: The value of the CAL function is a-party score, The result is the highest case of a-side {    int minpa=1,minpb=1,maxpa=n,maxpb=n,ans=0;//a minimum pointer, B's minimum pointer, A's maximum pointer, B's maximum pointer while    (minpa< =MAXPA)    {        if (A[MINPA]>B[MINPB]) ans+=2,minpa++,minpb++,//a minimum is greater than B, with the smallest else if of A and B        (a[maxpa]>b [MAXPB]) Ans+=2,maxpa--, maxpb--; A maximum greater than B max        else ans+= (A[MINPA]==B[MAXPB]), minpa++,maxpb--;//otherwise a min and B max ratio    }    return ans; int main () {    scanf ("%d", &n);    for (int i=1;i<=n;i++)        scanf ("%d", &a[i]);    for (int i=1;i<=n;i++)        scanf ("%d", &b[i]);    Sort (a+1,a+n+1);    Sort (b+1,b+n+1);    printf ("%d", Cal ());    Swap (A, b);    printf ("%d\n", 2*n-cal ());    return 0;}




[Bzoj 1034][zjoi2008] Bubble Hall BNB (class Tian bogey horse racing greed)

Related Article

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.