ZCMU-1229-Two bags

Description

Xiaoming has 2*n cubes,each cube contains an integer from 10 to 99.He arbitrarily chooses n cubes and puts them in the first bag.The remaining cubes form the second bag.

Xiaoming decided to play with cubes.During the game he takes a cube from the first bag and writes down the number it has.Then he takes a cube from the second bag and write out its two digits near two digits he had written(to the right of them).In the end he obtained a single fourdigit integer --the first two digits of it is written on the cube from the first bag,and the second two digits of it is written on the second cube from the second bag.

Xiaoming is not good at arithmetic.So,he can not easily count the largest number of distinct fourdigit numbers he can get in the game.Can you help him?

Input

The first line contains integer n(0<n<101).The second line contains 2*n space-separated integers Ai(10<=Ai<=99),denoting the numbers on the cubes.

Output

In the first line print a single number–the maximum possible number of distinct four-digit numbers Xiaoming can obtain.

Sample Input

1
10 99
2
13 24 13 45

Sample Output

1
4

题意就是把2n个数分成两组,然后从第一组中选一个数ab(两位数a是十位b是个位),从第二组中选一个数cd,组成abcd,求最多能组合出几个不同abcd。我的思路是先找相同的如果相同的个数多于2个就保留2个,其他的多的就去掉,总数也相应的减掉,最后如果个数cnt是奇数,就是 (cnt+1)/2*(cnt/2),是偶数的话就是cnt*cnt/4。

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mem(a) memset(a,0,sizeof(a))
#define N 1000000007
 
int s[300];
 
int main()
{
    int n;
    while(~scanf("%d", &n)){
        for(int i = 0; i < 2*n; i++) scanf("%d", &s[i]);
        sort(s,s+2*n);
        int num = n*2;
        int cnt = 0;
        int x = 1;
        for(int i = 0; i < 2*n-1; i++){
            if(s[i]==s[i+1]){
                x = 1;
                while(s[i]==s[i+1]&&i<2*n-1){
                    i++;
                    x++;
                }
                if(x>2){
                    num -= (x-2);
                }
                cnt++;
            }
        }
        int sum = 0;
        if(num%2==1){
            sum = ((num+1)/2)*(num/2);
        }else{
            sum = num*num/4;
        }
        printf("%d\n", sum);
    }
    return 0;
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值