[BZOJ 1034]泡泡堂

danihao123 posted @ 2016年8月24日 20:38 in 题解 with tags BZOJ ZJOI 省选 贪心 , 778 阅读
转载请注明出处:http://danihao123.is-programmer.com/

这题其实就是一个田忌赛马类问题。贪心即可。

如果你不知道田忌赛马怎么贪,可以看《骗分导论》相关介绍(然而那个贪心不是骗分算法哦)。

代码:

/**************************************************************
    Problem: 1034
    User: danihao123
    Language: C++
    Result: Accepted
    Time:256 ms
    Memory:1604 kb
****************************************************************/
 
#include <cstdio>
#include <cctype>
#include <algorithm>
using namespace std;
const int maxn=100001;
int a[maxn],b[maxn];
int n;
inline int solve(int *A,int *B){
    register int L1=1,R1=n,L2=1,R2=n,ans=0;
    while(L1<=R1 && L2<=R2){
        if(A[L1]>B[L2]){
            ans+=2;
            L1++;
            L2++;
        }else{
            if(A[R1]>B[R2]){
                ans+=2;
                R1--;
                R2--;
            }else{
                if(A[L1]==B[R2])
                    ans++;
                L1++;
                R2--;
            }
        }
    }
    return ans;
}
int main(){
    register int i,ans;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(i=1;i<=n;i++)
        scanf("%d",&b[i]);
    sort(a+1,a+1+n);
    sort(b+1,b+1+n);
    printf("%d %d\n",solve(a,b),2*n-solve(b,a));
    return 0;
}
ip-192-168-0-1.com 说:
Jul 05, 2023 08:27:33 PM

To enable you to setup WiFi routers by typing the default IP address 192.168.1.1 (192.168.o.1) on your web browser, the top router makers of D-Link or Netgear brands created the IP 192.168.0.1 adjacent to IP 192.168.1.1 and IP 192.168.2.1.Wi-Fi routers with IPv4 private network IP addresses or default gateways include those made by Tenda, Cisco ip-192-168-0-1.com Linksys Netgear,TP-Link, D-Link Asus,and Apple AirPort Extreme.You can change your router's default Admin ID and Password on the control panel configuration page after successfully logging in using the above simple process. Simply select the option to change your password, modify it, and then save.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter