https://www.luogu.org/problem/show?pid=1360

题目描述

Farmer John's N cows (1 ≤ N ≤ 100,000) share many similarities. In fact, FJ has been able to narrow down the list of features shared by his cows to a list of only K different features (1 ≤ K ≤ 30). For example, cows exhibiting feature #1 might have spots, cows exhibiting feature #2 might prefer C to Pascal, and so on.

FJ has even devised a concise way to describe each cow in terms of its "feature ID", a single K-bit integer whose binary representation tells us the set of features exhibited by the cow. As an example, suppose a cow has feature ID = 13. Since 13 written in binary is 1101, this means our cow exhibits features 1, 3, and 4 (reading right to left), but not feature 2. More generally, we find a 1 in the 2^(i-1) place if a cow exhibits feature i.

Always the sensitive fellow, FJ lined up cows 1..N in a long row and noticed that certain ranges of cows are somewhat "balanced" in terms of the features the exhibit. A contiguous range of cows i..j is balanced if each of the K possible features is exhibited by the same number of cows in the range. FJ is curious as to the size of the largest balanced range of cows. See if you can determine it.

神牛小R在许多方面都有着很强的能力,具体的说,他总共有m种能力,并将这些能力编号为1到m。他的能力是一天一天地提升的,每天都会有一些能力得到一次提升,R对每天的能力提升都用一个数字表示,称之为能力提升数字,比如数字13,转化为二进制为1101,并且从右往左看,表示他的编号为1,3,4的能力分别得到了一次提升。小R把每天表示能力提升的数字的记了下来,如果在连续的一段时间内,小R的每项能力都提升了相同的次数,小R就会称这段时间为一个均衡时期,比如在连续5天内,小R的每种能力都提升了4次,那么这就是一个长度为5的均衡时期。

于是,问题来了,给出 小R n天的能力提升数字,请求出均衡时期的最大长度。

【数据规模】对于50%的数据,N <= 1000。

输入输出格式

输入格式:

第一行有两个整数n,m,表示有n天,m种能力。接下来有n行,每行有一个整数,分别表示第1到n天的能力提升数字。能力提升数字转化为二进制后,从右到左的每一位表示对应的能力是否在当天得到了一次提升。

n<=100000, m<=30

输出格式:

输出只有一个整数,表示长度最大的均衡时期的长度。

输入输出样例

输入样例#1: 复制

7 3
7
6
7
2
1
4
2
输出样例#1: 复制

4

说明

【样例解释】

每天被提升的能力种类分别为:

第一天:1,2,3

第二天:2,3

第三天:1,2,3

第四天:2

第五天:1

第六天:3

第七天:2

第三天到第六天为长度最长的均衡时期

因为 这四天 每种能力分别提升了 2次

前缀和

判断当前每种能力与第一种能力的差是否出现过

map+vector

#include<map>
#include<vector>
#include<cstdio>
#include<iostream> using namespace std; map<vector<int>,int>mp; void read(int &x)
{
x=; char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) { x=x*+c-''; c=getchar(); }
} int main()
{
int n,m;
read(n); read(m);
int x,ans=;
vector<int>v(m);
mp[v]=;
for(int i=;i<=n;i++)
{
read(x);
for(int j=;j<m;j++)
if(x&(<<j)) v[j]++;
if(x&)
for(int j=;j<m;j++) v[j]--;
if(mp.count(v)) ans=max(ans,i-mp[v]);
else mp[v]=i;
}
printf("%d",ans);
}

[USACO07MAR]黄金阵容均衡Gold Balanced L…的更多相关文章

  1. 洛谷P1360 [USACO07MAR]黄金阵容均衡Gold Balanced L…

    P1360 [USACO07MAR]黄金阵容均衡Gold Balanced L… 题目描述 Farmer John's N cows (1 ≤ N ≤ 100,000) share many simi ...

  2. 洛谷 P1360 [USACO07MAR]黄金阵容均衡Gold Balanced L…

    P1360 [USACO07MAR]黄金阵容均衡Gold Balanced L… 题目描述 Farmer John's N cows (1 ≤ N ≤ 100,000) share many simi ...

  3. [USACO07MAR]黄金阵容均衡Gold Balanced L…(洛谷 1360)

    题目描述 Farmer John's N cows (1 ≤ N ≤ 100,000) share many similarities. In fact, FJ has been able to na ...

  4. [USACO07MAR]黄金阵容均衡Gold Balanced L… map

    题目描述 Farmer John's N cows (1 ≤ N ≤ 100,000) share many similarities. In fact, FJ has been able to na ...

  5. [luoguP1360] [USACO07MAR]黄金阵容均衡Gold Balanced L…

    传送门 真的骚的一个题,看了半天只会个前缀和+暴力.. 纯考思维.. 良心题解 #include <cstdio> #include <cstring> #include &l ...

  6. 洛谷P1360 [USACO07MAR]黄金阵容均衡题解

    题目 不得不说这个题非常毒瘤. 简化题意 这个题的暴力还是非常好想的,完全可以过\(50\%\)的数据.但是\(100\%\)就很难想了. 因为数据很大,所以我们需要用\(O(\sqrt n)\)的时 ...

  7. [LuoguP1360][USACP07MAR]黄金阵容均衡

    [LuoguP1360][USACP07MAR]黄金阵容均衡(Link) 每天会增加一个数\(A\),将\(A\)二进制分解为\(a[i]\),对于每一个\(i\)都增加\(a[i]\),如果一段时间 ...

  8. 洛谷 P1360 [USACO07MAR]Gold Balanced Lineup G (前缀和+思维)

    P1360 [USACO07MAR]Gold Balanced Lineup G (前缀和+思维) 前言 题目链接 本题作为一道Stl练习题来说,还是非常不错的,解决的思维比较巧妙 算是一道不错的题 ...

  9. 1702: [Usaco2007 Mar]Gold Balanced Lineup 平衡的队列

    1702: [Usaco2007 Mar]Gold Balanced Lineup 平衡的队列 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 510  S ...

随机推荐

  1. USACO 1.4.2 Mother's Mil 母亲的牛奶(DFS)

    Description 农民约翰有三个容量分别是A,B,C升的桶,A,B,C分别是三个从1到20的整数,最初,A和B桶都是空的,而C桶是装满牛奶的.有时,约翰把牛奶从一个桶倒到另一个桶中,直到被灌桶装 ...

  2. 软件工程android项目简介

    我们的程序名字叫做“有爱”APP,英文名“you i”.意味着you and i,是一款旨在两人聊天,生活日记,记账工具,和对方通知的小软件. 1.首先我们的创意解决了用户什么需求? 答:在当今信息爆 ...

  3. HDU 5666 Segment 数论+大数

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5666 bc(中文):http://bestcoder.hdu.edu.cn/contests ...

  4. Android工程方法数超过64k,The number of method references in a .dex file cannot exceed 64K.

    最近将一个老的Eclipse项目转到Android Studio后,用gradle添加了几个依赖,项目可以make,但是一旦run就报错 Error:The number of method refe ...

  5. HashMap和HashTable源码分析

    HashMap HashMap是一个实现了Map接口的Hash表.提供所有Map的操作,并且允许null key和null value.HashMap几乎等同于HashTable,只不过HashMap ...

  6. linux桌面使用鼠标中间健粘帖

    使用linux桌面很久了,一直习惯鼠标左键选中,右健弹出菜单复制粘帖. 没想到linux使用鼠标中间健粘帖,很方便. 参考:Linux鼠标中键复制粘贴之谜[Felix蛋疼科普贴] 用鼠标左键单击待复制 ...

  7. jdbc 3.0

    1.将Blob.Clob类型数据保存到数据库 import java.io.File; import java.io.FileInputStream; import java.io.FileReade ...

  8. 简易四则运算生成程序——添加GUI支持

    项目成员:张金生     张政 工程地址: https://coding.net/u/jx8zjs/p/paperOne/git ssh://git@git.coding.net:jx8zjs/pap ...

  9. Linux服务器启动后只读解决办法

    今天处理一个服务器,远程死活连接不上,只好跑信息中心去看了下服务器. Linux服务器启动之后,提示: give root password for maintenance (or type cont ...

  10. 【uoj#317】[NOI2017]游戏 2-SAT

    题目描述 给出 $n$ 个赛车赛道和A.B.C三种赛车,除了 $d$ 个赛道可以使用所有三种赛车以外每个都只能使用给出的两种之一.另外给出 $m$ 条限制:某个赛道使用X则某另一个赛道必须使用Y.问: ...