思路:贪心
提交:1次(看了题解$QwQ$)
题解:
若我方最弱可以干掉对方最弱,则干;
否则若我方最强可以干掉对方最强,则干;
否则若我方最弱与对方最强平手,则平;
其实貌似一二条是可以互换的,主要说明最后一条:相当于用最垃圾的去换掉对方最强的。
#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 ",2*n-solve(b,a)); } } signed main() { Luitaryi::main(); }
2019.07.21