zoukankan      html  css  js  c++  java
  • 【bzoj1034】 ZJOI2008—泡泡堂BNB

    http://www.lydsy.com/JudgeOnline/problem.php?id=1034 (题目链接)

    题意

      田忌赛马。。

    Solution

      贪心。

      1.若A队最弱的比B队最弱的强,先赢一场。

      2.若A队最强的比B队最强的强,先赢一场。

      3.用A队最弱的去顶B队最强的。

      其中第一步与第二步可以替换。

    细节

      考试自信不拍,结果又写Wa了。。

    代码

    // bzoj1034
    #include<algorithm>
    #include<iostream>
    #include<cstdlib>
    #include<cstring>
    #include<cstdio>
    #include<cmath>
    #define LL long long
    #define inf 2147483640
    #define Pi acos(-1.0)
    #define free(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
    using namespace std;
    
    const int maxn=100010;
    int a[maxn],b[maxn],n;
    
    int solve(int *a,int *b) {
    	int al=1,bl=1,ar=n,br=n,ans=0;
    	while (al<=ar && bl<=br) {
    		if (a[al]>b[bl]) ans+=2,al++,bl++;
    		else if (a[ar]>b[br]) ans+=2,ar--,br--;
    		else ans+=(a[al]==b[br]),al++,br--;
    	}
    	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+1+n);sort(b+1,b+1+n);
    	printf("%d %d",solve(a,b),2*n-solve(b,a));
    	return 0;
    }
    

      

  • 相关阅读:
    向 DataGridView 的行集合中添加行
    添加form窗口最大化最小化事件
    转义字符表
    键盘输入变简单了
    数字9X9的表格
    统计你输入的任意字符
    一个九九表
    用冒泡法排序
    学生会
    任意排序几个数
  • 原文地址:https://www.cnblogs.com/MashiroSky/p/6004292.html
Copyright © 2011-2022 走看看