P2587 [ZJOI2008] BNB greedy gods

Ideas: greedy

Submissions: 1 (read explanations $ QwQ $)

answer:

If you can get rid of the weakest weakest each other, then dry;

Otherwise, if we can kill each other the most strongest, then dry;

Otherwise, if our weakest strongest tie with each other, the flat;

In fact, seemingly twelve are interchangeable, mainly explain the last one: the equivalent of the most garbage to replace the other side of the strongest.

#include<cstdio>
#include<iostream>
#include<algorithm>
#define ull unsigned long long
#define ll long long
#define R register int
using namespace std;
#define pause (for(R i=1;i<=10000000000;++i))
#define In freopen("NOIPAK++.in","r",stdin)
#define Out freopen("out.out","w",stdout)
namespace Fread {
static char B[1<<15],*S=B,*D=B;
#ifndef JACK
#define getchar() (S==D&&(D=(S=B)+fread(B,1,1<<15,stdin),S==D)?EOF:*S++)
#endif
inline int g() {
    R ret=0,fix=1; register char ch; while(!isdigit(ch=getchar())) fix=ch=='-'?-1:fix;
    if(ch==EOF) return EOF; do ret=ret*10+(ch^48); while(isdigit(ch=getchar())); return ret*fix;
} inline bool isempty(const char& ch) {return (ch<=36||ch>=127);}
inline void gs(char* s) {
    register char ch; while(isempty(ch=getchar()));
    do *s++=ch; while(!isempty(ch=getchar()));
}
} using Fread::g; using Fread::gs;

namespace Luitaryi {
const int N=100010;
int n,a[N],b[N];
inline int solve(int* a,int* b) {
    R h=1,t=n,l=1,r=n,ret=0;
    while(h<=t&&l<=r) {
        if(a[h]>b[l]) ret+=2,++h,++l;
        else if(a[t]>b[r]) ret+=2,--t,--r;
        else ret+=a[h]==b[r],++h,--r;
    } return ret;
}
inline void main() {
    n=g(); 
    for(R i=1;i<=n;++i) a[i]=g();
    for(R i=1;i<=n;++i) b[i]=g();
    sort(a+1,a+n+1); sort(b+1,b+n+1);
    printf("%d ",solve(a,b));
    printf("%d\n",2*n-solve(b,a));
}
}
signed main() {
    Luitaryi::main();
}

2019.07.21

Guess you like

Origin www.cnblogs.com/Jackpei/p/11223223.html