首页 > 其他分享 >hihoCoder Challenge 28 异或问题 思维

hihoCoder Challenge 28 异或问题 思维

时间:2023-04-24 22:39:37浏览次数:40  
标签:ch int hihoCoder Challenge 28 long ans include ll


Given a sequence a[1..n], you need to calculate how many integers S satisfy the following conditions:

(1). 0 ≤ S < 260

(2). For every i in [1,n-1] , (a[i] xor S) ≤ (a[i+1] xor S)

Input
On the first line there is only one integer n

On the second line there are n integers a[1..n]

1 ≤ n ≤ 50

0 ≤ a[i] < 260

Output
Output one integer : the answer

Sample Input
3
1 2 3
Sample Output
288230376151711744

题目大意很明确,思路是什么?
看到异或自然想到二进制,
比如:
00011101
00011010
比较大小从高到低进行比较,如果在某一位置开始出现不同,那么自然异或值S这一位就确定了,因为相同的异或结果还是相同,所以只需要确定哪些位置已经被确定了,那么总方案数就是 2^( 未确定位置数量 ).

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<string>
typedef long long ll;
using namespace std;
typedef unsigned long long int ull;
#define maxn 2000005
#define inf 0x3f3f3f3f
const long long int mod = 1e9 + 7;

ll read() {
    ll x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch>'9') {
        if (ch == '-') {
            f = -1;
        }
        ch = getchar();
    }
    while (ch >= '0'&&ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}

ll quickpow(ll a, ll b) {
    ll ans = 1;
    while (b > 0) {
        if (b % 2)ans = ans * a;
        b = b / 2;
        a = a * a;
    }
    return ans;
}

int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a%b);
}


bool cmp(int a, int b) {
    return a > b;
}

ll ves[maxn];
void revs() {
    for (ll i = 1; i <= 1000000; i++) {
        ves[i] = quickpow(i, mod - 2);
    }
}


//ull Mod = quickpow(2ull, 47ull);
ll a[100];
int b1[100], b2[100];
int v[100];
ll ans;
void dl(ll x, ll y) {
    int i, j;
    for (int i = 1; i <= 60; i++) {
        b1[i] = x % 2;
        x = x / 2;
    }
    for (int j = 1; j <= 60; j++) {
        b2[j] = y % 2;
        y = y / 2;
    }
     ans = 0;
    for (int i = 60; i >= 1; i--) {
        if (b1[i] == b2[i])continue;
        ans = i;
        break;
    }
    v[ans] = 1;
}

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)cin >> a[i];
    for (int i = 0; i < n - 1; i++)dl(a[i], a[i + 1]);
    ans = 0;
    for (int i = 60; i >= 1; i--) {
        if (v[i])continue;
        ans++;
    }
    ans = (ll)1 << ans;
    cout << ans << endl;
}


标签:ch,int,hihoCoder,Challenge,28,long,ans,include,ll
From: https://blog.51cto.com/u_15657999/6221924

相关文章

  • Codeforces Round #285 (Div. 2) B. Misha and Changing Handles map 映射
    MishahackedtheCodeforcessite.Thenhedecidedtoletalltheuserschangetheirhandles.Ausercannowchangehishandleanynumberoftimes.Buteachnewhandlemustnotbeequaltoanyhandlethatisalreadyusedorthatwasusedatsomepoint.Mish......
  • Codeforces Round #285 (Div. 2) C. Misha and Forest
    Let’sdefineaforestasanon-directedacyclicgraph(alsowithoutloopsandparalleledges).OnedayMishaplayedwiththeforestconsistingofnvertices.Foreachvertexvfrom0ton - 1hewrotedowntwointegers,degreevandsv,werethefirstinte......
  • Navicat连接Oracle报错:ORA-28547...
    使用Navicat连接正常的oracle数据库时,提示 可能是因为Navicat本地的OCI版本与Oracle数据库版本不符造成的,可以下载对应的OCI版本在Navicat中使用。1.下载OCI搜索oracleinstantclient找到相关下载地址OracleInstantClientDownloads根据实际oracle数据库版本选择对应in......
  • Acwing 3728-城市通电 / 最小生成树,建图,超级源点
    AcWing3728.城市通电做出来就凭之前的一句感悟:把每个动态选择变为与超级源点连的一条边,把这条边加入图里面跑最小生成树就相当于考虑了每个动态选择......
  • P9228 原神 题解
    题目传送门题目大意有一个魔法师,她可以用火元素攻击魔法把对附着冰元素的怪物的伤害\(\times2\),用冰元素攻击魔法把对附着火元素的怪物的伤害\(+5\)。每个怪物初始时没有附着任何元素,给出冰、火元素对每个怪物的初始伤害,魔法师可以任意安排攻击顺序,求最大总伤害。解题思路......
  • 基于SqlSugar的开发框架循序渐进介绍(28)-- 快速构建系统参数管理界面
    在参照一些行业系统软件的时候,发现一个做的挺不错的系统功能-系统参数管理,相当于把任何一个基础的系统参数碎片化进行管理,每次可以读取一个值进行管理,这样有利于我们快速的处理业务需求,是一个挺好的功能。本篇随笔模拟这个功能,基于SqlSugar开发框架的基础上,利用代码生成工具快速生......
  • AtCoder Beginner Contest 283 Ex Popcount Sum
    洛谷传送门AtCoder传送门记录一下这个神奇的套路。首先有\(\operatorname{popcount}(n)=n-\sum\limits_{i=1}^{\infty}\left\lfloor\frac{n}{2^i}\right\rfloor\)。证一下:\[\operatorname{popcount}(n)=\sum\limits_{i=0}^{\infty}\left\lfloor\dfrac{n}{2^i}\right......
  • SQL2000修改sa密码时提示【错误2812:未能找到储存过程’sp_passwoed’】的解决方法
    1.在用SQL2000数据库经常会遇见忘记sa密码,需要修改sa密码,但是有时候修改sa密码时会提示  错误2812:未能找到储存过程’sp_passwoed’2.遇到这种情况的解决方法是:打开开始菜单,找到SQLServer的程序组,选择运行程序组中的“查询分析器”,打开 3.打开“查询分析器”后会有一个......
  • 2023年4月21日08:29:28
    昨天学了一天怎么去写博客,进度什么的比较慢,但是我的收获很大,看懂了很多以前没有看懂的东西,很高兴。今天先把材料写好,然后再开始学习博客,争取在星期天的的00:00之前把博客写完。学博客的时候,要去理解,自己不要沉溺在刷课的快感中,你要真正学到 东西才是最重要的。理解它们跑的逻辑......
  • SDUTOJ 2128 树结构练习——排序二叉树的中序遍历
    树结构练习——排序二叉树的中序遍历TimeLimit:1000MSMemorylimit:65536K题目描述在树结构中,有一种特殊的二叉树叫做排序二叉树,直观的理解就是——(1).每个节点中包含有一个关键值(2).任意一个节点的左子树(如果存在的话)的关键值小于该节点的关键值(3).任意一个节......