这道题大意呢就是给一串数,然后你要做出查询一个数,求出除了这个数以外的和,或,异或。

求出前缀和后缀,再对结尾和开头比较就行了。

Little A has come to college and majored in Computer and Science. 

Today he has learned bit-operations in Algorithm Lessons, and he got a problem as homework. 

Here is the problem: 

You are giving n non-negative integers a1,a2,,ana1,a2,⋯,an, and some queries. 

A query only contains a positive integer p, which means you 
are asked to answer the result of bit-operations (and, or, xor) of all the integers except apap. 

InputThere are no more than 15 test cases. 

Each test case begins with two positive integers n and p 
in a line, indicate the number of positive integers and the number of queries. 

2n,q1052≤n,q≤105 

Then n non-negative integers a1,a2,,ana1,a2,⋯,an follows in a line, 0ai1090≤ai≤109 for each i in range[1,n]. 

After that there are q positive integers p1,p2,,pqp1,p2,⋯,pqin q lines, 1pin1≤pi≤n for each i in range[1,q].
OutputFor each query p, output three non-negative integers indicates the result of bit-operations(and, or, xor) of all non-negative integers except apap in a line. 
Sample Input

3 3
1 1 1
1
2
3

Sample Output

1 1 0
1 1 0
1 1 0
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <stack>
#define INF 1e9
using namespace std;
    int sw[100005];
    long long a[100005],b[100005],c=0;
    long long a1[100005],b1[100005];
int main()
{
    int n,m;
    int t;
    while(~scanf("%d %d",&n,&m)){
        scanf("%d",&sw[1]);
        a[1]=sw[1];
        b[1]=sw[1];
        c=a[1];
        for(int i=2;i<=n;i++){
            scanf("%d",&sw[i]);
            a[i]=a[i-1]&sw[i];
            b[i]=b[i-1]|sw[i];
            c^=sw[i];
        }
        a1[n]=sw[n];
        b1[n]=sw[n];
        for(int i=n-1;i>=1;i--){
            a1[i]=a1[i+1]&sw[i];
            b1[i]=b1[i+1]|sw[i];
        }
        for(int i=0;i<m;i++){
            scanf("%d",&t);
            if(t==1) printf("%lld %lld %lld\n",a1[2],b1[2],c^sw[t]);
            else if(t==n) printf("%lld %lld %lld\n",a[n-1],b[n-1],c^sw[t]);
            else {
                long long q,w;
                q=a[t-1]&a1[t+1];
                w=b[t-1]|b1[t+1];
                printf("%lld %lld %lld\n",q,w,c^sw[t]);
            }
        }
    }
    return 0;
}

这道题挺适合我们这种赌博做的,找了几个例子比较情况,就是先打掉对子,然后如果打掉之后有剩余的话,再看后面的数是不是奇数,如果是,看再后面还有没有数,有的话那就可以组成一个顺子。

Nike likes playing cards and makes a problem of it. 

Now give you n integers, ai(1in)ai(1≤i≤n) 

We define two identical numbers (eg: 2,22,2) a Duizi, 
and three consecutive positive integers (eg: 2,3,42,3,4) a Shunzi. 

Now you want to use these integers to form Shunzi and Duizi as many as possible. 

Let s be the total number of the Shunzi and the Duizi you formed. 

Try to calculate max(s)max(s). 

Each number can be used only once. 

InputThe input contains several test cases. 

For each test case, the first line contains one integer n(1n1061≤n≤106). 
Then the next line contains n space-separated integers aiai (1ain1≤ai≤n) 
OutputFor each test case, output the answer in a line. 
Sample Input

7
1 2 3 4 5 6 7
9
1 1 1 2 2 2 3 3 3
6
2 2 3 3 3 3 
6
1 2 3 3 4 5

Sample Output

2
4
3
2
#include <iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<map>
using namespace std;
int a[1000001];
int main()
{
    int n,i,x;
    while(~scanf("%d",&n))
    {
        memset(a,0,sizeof(a));
        for(i=1;i<=n;i++)
        {
           scanf("%d",&x);
            a[x]++;
        }
        int ans=0;
        for(i=1;i<=n;i++)
        {
            ans+=a[i]/2;
            a[i]=a[i]%2;
            if(a[i]&&a[i+1]%2&&a[i+2])
            {
                ans++;
                a[i]--;
                a[i+1]--;
                a[i+2]--;
            }
        }
  printf("%d\n",ans);
    }
    return 0;
}

想回家啊想回家,在学校好热呜呜呜呜

posted on 2018-08-16 16:45  可怕hiahia  阅读(113)  评论(0编辑  收藏  举报