hdoj39721 M possible【一直MLE到目前仍未ac】

1 M possible

Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 2048/1024 K (Java/Others)
Total Submission(s): 1238    Accepted Submission(s): 354


Problem Description
There are 3*N+2 nonnegative integers. Except two special integers, the rest 3*N integers can form N triple groups: { Vi, Vj, Vk| Vi=Vj=Vk}, each integer are at most in one triple group.

Your task is to find the two special integers.

Now, suneast is so boring. He wants to compete with you. As there is no computer available for him, he has to find the integers use his eyes! Unbelievable! So just for fairness, your program can access ONLY 1MB memory!

Tips: Impossible itself says 1 M possible ------ Tourist’s quote (a topcoder target member)
 

Input
The first line of the input contains an integer T(T<=3), indicating the number of test cases.

Each case begin with a line containing an integers N(2<=N<=300000, N=2(mod3) ).

The second lines contains N nonnegative integers Vi (1<=Vi<=2147483647).
 

Output
For each test case, print a line containing two integers a, b (a<=b) separate by a blank. a, b is the desire two special integers.
 

Sample Input
  
  
2 2 1 2 23 1 3 1 4 5 2 1 1 3 1 4 5 2 1 1 3 1 4 5 2 1 2 1
 

Sample Output
  
  
1 2 1 2
 

Author
isuneast
 

Source

3*n+2个数找出两个数他们的个数不是3的倍数此题一直MLE把能搜到的代码ac代码交了还是MLE看了一下hdoj的提交数据从14年12月之后此题就没有ac过可能是数据加强了吧现在此题依旧没过贴下代码希望有过此题的大神给下思路

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#define maxn 31
using namespace std;
int cnt[maxn][maxn];
void slove(){
    int i,j,k,pos;
    bool flag=false;
    for(i=0;i<maxn;++i){
        for(j=0;j<maxn;++j){
            cnt[i][j]%=3;
        }
        if(cnt[i][i]==1){
            flag=true;
            pos=i;
        }
    }
    int a=0,b=0;
    if(flag){
        for(i=0;i<maxn;++i){
            if(cnt[pos][i]){
                a|=(1<<i);
            }
            if(cnt[i][i]==2){
                b|=(1<<i);
            }
            else if(cnt[i][i]==1){
                if(!cnt[pos][i]){
                    b|=(1<<i);
                }
            }
        }
        if(a>b)swap(a,b);
    }
    else {
        for(i=0;i<maxn;++i){
            if(cnt[pos][i]){
                a|=(1<<i);
                b|=(1<<i);
            }
        }
    }
    printf("%d %d\n",a,b);
}
int main()
{
    int t,i,j,k,n,num;
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        memset(cnt,0,sizeof(cnt));
        for(k=0;k<n;++k){
            scanf("%d",&num);
            for(i=0;i<maxn;++i){
                if(num&(1<<i)){
                    for(j=0;j<maxn;++j){
                        if(num&(1<<j)){
                            cnt[i][j]++;
                        }
                    }
                }
            }
        }
        slove();
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值