P1360 [USACO07MAR]黄金阵容均衡Gold Balanced L…

题目描述

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: 复制

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

  1. 4

说明

【样例解释】

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

第一天:1,2,3

第二天:2,3

第三天:1,2,3

第四天:2

第五天:1

第六天:3

第七天:2

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

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

  1. #include<iostream>
  2. #include<cstdio>
  3. using namespace std;
  4. int n,m,sum[][];
  5. bool check(int l,int r){
  6. int sta=;
  7. for(int i=;i<m;i++){
  8. if(i!=&&sum[r][i]-sum[l-][i]!=sta)return ;
  9. if(i==)sta=sum[r][i]-sum[l-][i];
  10. if(sum[r][i]-sum[l-][i]==)return ;
  11. }
  12. return ;
  13. }
  14. int main(){
  15. scanf("%d%d",&n,&m);
  16. int x;
  17. for(int i=;i<=n;i++){
  18. scanf("%d",&x);
  19. for(int j=;j<m;j++){
  20. sum[i][j]=sum[i-][j];
  21. if((<<j)&x)sum[i][j]++;
  22. }
  23. }
  24. int ans=;
  25. for(int i=;i<=n;i++){
  26. int now=ans;
  27. for(int j=i+now;j<=n;j++){
  28. int l=j-i+;
  29. if(check(i,j))
  30. ans=max(ans,l);
  31. }
  32. }
  33. printf("%d",ans);
  34. }

68分 暴力

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <algorithm>
  5. #include <vector>
  6. #include <map>
  7. #define mod 9901
  8. using namespace std;
  9. map<vector<int>,int>f;
  10. int ans;
  11. int main(){
  12. int n,m;scanf("%d%d",&n,&m);
  13. vector<int>now(m);
  14. f[now]=;
  15. for(int i=;i<=n;i++){
  16. int x;scanf("%d",&x);
  17. for(int j=;j<m;j++)
  18. if(x&(<<j))now[j]++;
  19. if(x&)for(int j=;j<m;j++)now[j]--;
  20. if(f.count(now))ans=max(ans,i-f[now]);
  21. else f[now]=i;
  22. }
  23. printf("%d",ans);
  24. }

100分

洛谷P1360 [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. [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 ...

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

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

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

    https://www.luogu.org/problem/show?pid=1360 题目描述 Farmer John's N cows (1 ≤ N ≤ 100,000) share many s ...

  5. [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 ...

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

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

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

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

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

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

  9. 洛谷P3121 审查(黄金)Censoring(Gold) [USACO15FEB] AC自动机

    正解:AC自动机 解题报告: 传送门! 啊我好呆啊其实就挺模板题的,,,只是要一个栈搞一下,,,然后我就不会了,,,是看了题解才get的,,,QAQ 然后写下解法趴QwQ 首先看到多串匹配不难想到AC ...

随机推荐

  1. Python—is和==

    首先要知道Python中对象包含的三个基本要素,分别是:id(身份标识).type(数据类型)和value(值). ==是python运算符中的比较操作符,用来比较判断两个对象的value(值)是否相 ...

  2. Python — pandas

    Pandas有两种数据结构:Series和DataFrame. 1.Series Series类似于一维数组,和numpy的array接近,由一组数据和数据标签组成.数据标签有索引的作用.数据标签是p ...

  3. notepad++如何移除重复的行

    Removing duplicate rows in Notepad++ (so链接) 1. 插件 TextFX 2. 正则表达式:^(.*?)$\s+?^(?=.*^\1$)

  4. Xposed模块开发学习记录

    Xposed模块相关API可以参考在线文档: https://api.xposed.info/reference/packages.html     入门教程可以参考: https://github. ...

  5. Gym - 100851G:Generators(人尽皆知但是WA题)

    题意:现在有函数,每一项Xi=(A*X(i-1)+B)%C.现在给定N个函数以及K:X0,A,B,C.然你再每个函数选择一个数,使得其和最大,而且不被K整除. X0,A,B,C<=1e3 :K& ...

  6. 20179203 《Linux内核原理与分析》第十周作业

    第17章 设备与模块 一.设备类型 1. Linux及Unix系统: 块设备 字符设备 网络设备 2.块设备: 通常缩写为blkdev,它是可寻址的,寻址以块为单位,块大小随设备不同而不同:块设备通常 ...

  7. Muduo 多线程模型:一个 Sudoku 服务器演变

    陈硕 (giantchen AT gmail) blog.csdn.net/Solstice Muduo 全系列文章列表: http://blog.csdn.net/Solstice/category ...

  8. Gson小记

    Gson过滤字段,只要在字段前面添加“transient”关键字即可:之前就是因为Channel字段序列化的时候导致了stack over异常.

  9. IDEA 热部署 + 下载jar包放到maven中

    IDEA 热部署: 1 :  POM中加入devtools的依赖,就可以实现热部署 <dependency> <groupId>org.springframework.boot ...

  10. 面向对象(Java中普通代码块,构造代码块,静态代码块区别及代码示例)

    //执行顺序:(优先级从高到低.)静态代码块>mian方法>构造代码块>构造方法. 其中静态代码块只执行一次.构造代码块在每次创建对象是都会执行. 1 普通代码块 //普通代码块:在 ...