Smiling & Weeping

              ----玫瑰花你拿才好看,风景要和你看才浪漫--<-<-<@
B. Hamon Odyssey
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Jonathan is fighting against DIO's Vampire minions. There are n� of them with strengths a1,a2,…,an�1,�2,…,��.

Denote (l,r)(�,�) as the group consisting of the vampires with indices from l� to r�. Jonathan realizes that the strength of any such group is in its weakest link, that is, the bitwise AND. More formally, the strength level of the group (l,r)(�,�) is defined as

f(l,r)=al&al+1&al+2&…&ar.�(�,�)=��&��+1&��+2&…&��.

Here, && denotes the bitwise AND operation.

Because Jonathan would like to defeat the vampire minions fast, he will divide the vampires into contiguous groups, such that each vampire is in exactly one group, and the sum of strengths of the groups is minimized. Among all ways to divide the vampires, he would like to find the way with the maximum number of groups.

Given the strengths of each of the n� vampires, find the maximum number of groups among all possible ways to divide the vampires with the smallest sum of strengths.

Input

The first line contains a single integer t� (1≤t≤104)(1≤�≤104) — the number of test cases. The description of test cases follows.

The first line of each test case contains a single integer n� (1≤n≤2⋅1051≤�≤2⋅105) — the number of vampires.

The second line of each test case contains n� integers a1,a2,…,an�1,�2,…,�� (0≤ai≤1090≤��≤109) — the individual strength of each vampire.

The sum of n� over all test cases does not exceed 2⋅1052⋅105.

Output

For each test case, output a single integer — the maximum number of groups among all possible ways to divide the vampires with the smallest sum of strengths.

题目链接:Problem - B - Codeforces

思路:咱们找一下规律,主要分为两个情况:

1.所有数的&值非零:

&到最后一个数仍旧非零,虽然分组为一但能保证最小,多&一个 (新值) <= (旧值) , 即使等于,值+旧值 > 新值 ,并不能保证最小

所以分组只能为1,才能保证所有值的&最小

2.所有数的&值为零:

  贪心算法:向前运算 if(an == 0) ans++ , an = num[i]; 最后判断一下an的值是否为0

现在是代码时间欢迎━(*`∀´*)ノ亻!

 1 #include<bits/stdc++.h>
2 using namespace std;
3 int t , n;
4 int main()
5 {
6 scanf("%d",&t);
7 while(t--)
8 {
9 scanf("%d",&n);
10 vector<int> num(n+10);
11 int sum = 0;
12 for(int i = 1; i <= n; i++)
13 scanf("%d",&num[i]);
14 sum = num[1];
15 for(int i = 1; i <= n; i++)
16 sum &= num[i];
17 if(sum != 0) { printf("1\n"); continue; }
18 int an = num[1] , ans = 0;
19 for(int i = 2; i <= n; i++)
20 {
21 if(an == 0)
22 an = num[i] , ans++;
23 else
24 an &= num[i];
25 }
26 if(an == 0 || ans == 0) ans++;
27 printf("%d\n",ans);
28 }
29 return 0;
30 }

没有长亭古道,没有劝君更尽一杯酒,和所有文章的结尾一样,我们下次再见

ヾ( ̄▽ ̄)Bye~Bye~

Codeforces Round 882 div.2 B的更多相关文章

  1. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  2. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  3. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  4. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  5. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  6. Codeforces Round #262 (Div. 2) 1003

    Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...

  7. Codeforces Round #262 (Div. 2) 1004

    Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...

  8. Codeforces Round #371 (Div. 1)

    A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...

  9. Codeforces Round #268 (Div. 2) ABCD

    CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...

  10. 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts

    题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...

随机推荐

  1. Java(包机制、doc、Scanner对象)

    包机制 本质:文件夹 用于区别类名的命名空间 一般利用公司域名倒置作为包名 import与通配符* 导入包 例: import java.util.Scanner; import com.xxx.xx ...

  2. vim 之中 U 命令的浅析

    以下文章来源于CSDN,作者黑翼天使56,本文章经原作者同意后授权转载. 今天看 vim帮助文档的 user-manual 的第二章,发现了还有U(大写)这个命令,于是反复实验,略微搞懂了一点它的用处 ...

  3. hvv面试常见框架漏洞问题合集

    1.thinkphp 特征判断 直接在url后加/?s=1 whatweb进行探测,方式:whatweb URL 漏洞 5.0 RCE 原理 thinkphp底层没有对控制器名进行很好的合法性校验,导 ...

  4. 快速上手kettle(四)壶中可以倒出些啥?

    目录 前言 一 .kettle 这壶里能倒出啥? 二 .Access输出 2.1 Access输出设置 2.2 启动转换,查看输出 三 .Excel输出 3.1 选择excel扩展名 3.2 1 将表 ...

  5. 【HarmonyOS】如何获取公共目录的图片等文件(API7 FA模型JS语言)

    ​ [关键字] API7.JS.公共目录.@ohos.multimedia.mediaLibrary [前言] 在使用API7 JS开发HarmonyOS应用时,需要获取非应用目录即内部存储公共目录下 ...

  6. 非常简单好用实用的轮播图swiper banner组件

    非常简单好用实用的轮播图swiper banner组件; 下载完整代码请访问uni-app插件市场地址:https://ext.dcloud.net.cn/plugin?id=12786 效果图如下: ...

  7. 让AI更好地服务于人类社会:如何确保其安全和透明度

    目录 让AI更好地服务于人类社会:如何确保其安全和透明度 随着人工智能技术的不断发展和应用,人们越来越关注其安全和透明度.安全和透明度是人工智能发展的重要保障,能够保护人工智能系统免受恶意攻击和滥用, ...

  8. 【技术积累】C语言中基础知识【三】

    什么是C语言[了解即可] C语言是一种通用的高级编程语言,由美国贝尔实验室的Dennis Ritchie在20世纪70年代早期开发出来的.它在计算机科学和软件工程领域中被广泛使用. C语言具有以下特点 ...

  9. 1.1 Metasploit 工具简介

    Metasploit 简称(MSF)是一款流行的开源渗透测试框架,由Rapid7公司开发,可以帮助安全和IT专业人士识别安全性问题,验证漏洞的缓解措施,并管理专家驱动的安全性进行评估,提供真正的安全风 ...

  10. PHP检查更新加载本地版本号并解压覆盖

    <?phperror_reporting(0);ob_implicit_flush(true);$begin = microtime(true);//检查更新,加载本地版本号$config = ...