广西2017邀请赛 Problem E CS Course

本文介绍了一种基于位运算的算法题解决方案,该问题要求计算一组整数中除指定数外其余数的按位与、或、异或结果。通过统计每位上0的数量并结合查询数,快速得出答案。

问题 E: CS Course

时间限制: 2 Sec  内存限制: 512 MB

题目描述

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,...,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 ap.

输入

There are no more than 15 test cases.
Each test case begins with two positive integers n(2 ≤ n ≤ 105) and p(2 ≤ p ≤ 105) in a line, indicate the number of positive integers and the number of queries.
Then n non-negative integers a1,a2,...,an follows in a line, 0 ≤ ai ≤ 109 for each i in range [1,n].
After that there are q positive integers p1, p2, ...,pq in q lines, 1 ≤ p≤ n for each i in range [1,q].

输出

For each query p, output three non-negative integers indicates the result of bit-operations(and, or,xor) of all non-negative integers except ap in a line.

样例输入

3 3

1 1 1

1

2

3

样例输出

1 1 0

1 1 0

1 1 0




题目大意:
n个数  q次询问  每次询问第pi个数字  求除去询问的这个数外其他全部数字的and、or、xor

分析:
分别求出每个二进制位的有多少个0   然后判断去除询问的数字外剩下的每个二进制位的and、or、转为十进制
关于xor  最后在xor一遍这个数即可



AC代码:
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include<list>
#include <bitset>
#include <climits>
#include <algorithm>
#define gcd(a,b) __gcd(a,b)
#define FIN freopen("input.txt","r",stdin)
#define FOUT    freopen("output.txt","w",stdout)
typedef long long LL;
const LL mod=1e9+7;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
using namespace std;
int a[1000005];
int count0[1000005];
int main (){
    int n,p;
    while (scanf ("%d%d",&n,&p)!=EOF){
        memset(a,0,sizeof(a));
        memset(count0,0,sizeof(count0));
        int ans3=0;
        int maxn=0;
        for (int i=0;i<n;i++){
            scanf ("%d",&a[i]);
            ans3^=a[i];
            int tt=a[i];
            int len=0;
            while (tt){
                if(tt%2) count0[len]++;
                tt>>=1;len++;
                if (maxn<len) maxn=len;
            }   
        }
        for (int i=0;i<maxn;i++) count0[i]=n-count0[i];
        int temp;
        for (int i=0;i<p;i++){
            scanf ("%d",&temp);
            int t=a[temp-1];
            int ans1=0,ans2=0;
            for (int j=0;j<maxn;j++){
                if (count0[j]==0||(count0[j]==1&&t%2==0)) ans1+=1<<j,ans2+=1<<j; 
                else if ((count0[j]==n-1&&t%2==0&&n!=2)||
				(count0[j]==1&&t%2!=0&&n!=2)||
				(count0[j]>1&&count0[j]<n-1))
                ans2+=1<<j;
                t>>=1;
            }
            printf ("%d %d %d\n",ans1,ans2,ans3^a[temp-1]);
        }
          
    }
    return 0;
} 


当前提供的引用内容中并未提及2025年CCPC郑州邀请赛的相关信息。根据现有的引用内容,仅能获取到2024年CCPC郑州邀请赛的信息[^1]。以下是对可能的2025年CCPC郑州邀请赛相关IT竞赛或活动信息的推测与分析: ### 2025 CCPC 郑州邀请赛 IT竞赛 活动 信息 1. **时间安排**: 根据过往惯例,CCPC(中国大学生程序设计竞赛)通常在每年的春季至秋季举行区域赛和邀请赛。因此,2025年的CCPC郑州邀请赛预计将在2025年下半年举行,具体日期需参考官方公告。 2. **参赛对象**: CCPC邀请赛一般面向全国高校学生,尤其是具有编程能力和算法竞赛经验的学生团队。每支队伍由三名队员组成,共同协作解决编程问题[^2]。 3. **比赛形式**: 比赛通常采用现场竞赛的形式,参赛队伍需要在规定时间内解决一系列编程问题。题目涉及算法、数据结构、数学等领域,难度从简单到复杂不等。例如,2024年的Problem F“优秀字符串”要求参赛者对字符串进行特定规则的判断[^3]。 4. **技术要求**: 参赛者需要熟练掌握C/C++、Java、Python等编程语言,并具备扎实的数据结构与算法基础。此外,团队协作能力和快速学习能力也是获胜的关键因素。 5. **活动周边**: CCPC邀请赛通常会伴随一些学术交流活动,如讲座、工作坊和技术分享会,旨在促进高校间的技术交流与合作。 以下是代码示例,展示了一个典型的CCPC竞赛题目解法: ```cpp #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { string s; cin >> s; if (s.size() == 5 && s[2] == s[4]) { set<char> unique_chars; for (int i = 0; i < 4; ++i) { unique_chars.insert(s[i]); } if (unique_chars.size() == 4) { cout << "1" << endl; continue; } } cout << "0" << endl; } return 0; } ```
评论 4
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值