数位统计

Problem B: Changlong

Time Limit: 10 Sec  Memory Limit: 1 MB
Submit: 98  Solved: 10
[ Submit][ Status][ Web Board]

Description

Changlong is a handsome and clever boy and he is admired by many beautiful girls. Every day he received tens of thousands of letters form girls which express their intense desire to be his life companion. You see, Changlong is very tired of this and one day he get an idea to avoid this bother. He declares:

Only those clever girls who can solve the problem below have the qualification to be his wife.

Changlong's problem can be formulated like this:

There is one interesting sequence of numbers a1,a2,...an, this sequence has a very attractive property that every number appears exactly p times except a particular number t, which occurs q times. How to extract this particular number t from this sequence? In order to let this problem more mysterious, Changlong assumes that the involved number p, q in his problem are prime to each other, i.e., gcd(p, q)=1.

Changlong's method works very well. After his declaration, the number of received letter has decrease sufficiently. The girls are beginning to think over the problem with continuous strenuous effort, no sooner later they find this problem is beyond their ability. So most of them give up, but there is still a beautiful girl who is persistent in this problem. One day this girl comes across you and she invites you to help her.

Input

At the first line of the input is a integer k(0<k<=100), the number of test cases.

For each test case, there will be a line containing three integers: n(0<n<=10^7), p, q(1<p, q<200, gcd(p,q)=1) and a line containing n elements ai(0<ai<10^7) of the sequence.

Output

.   For each test case, you should first output a line with“Case #:”,where # is the id of the test case, then you should output the particular number t, i.e., the number which occurs q times in the sequence.

Sample Input

28 3 21 2 1 2 1 2 3 37 4 31 1 1 1 2 2 2

Sample Output

Case 1:3Case 2:2

思路:数位统计
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
int cnt[30];
int k,p,q;
int main()
{
    //freopen("in.txt","r",stdin);
    int t,x,i,j;
    scanf("%d",&t);
    for(int cas=1;cas<=t;cas++)
    {
        memset(cnt,0,sizeof(cnt));
        scanf("%d%d%d",&k,&p,&q);
        for(i=1;i<=k;i++)
        {
            scanf("%d",&x);
            for(j=0;(1<<j)<=x;j++)
            {
                if(x&(1<<j))cnt[j]++;
            }
        }
        int ans=0;

        for(i=0;i<=25;i++)
            if(cnt[i]%p!=0)
            ans+=(1<<i);
        printf("Case %d:\n%d\n",cas,ans);
    }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值