洛谷P1360 [USACO07MAR]黄金阵容均衡Gold Balanced L…
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,2,3
第二天:2,3
第三天:1,2,3
第四天:2
第五天:1
第六天:3
第七天:2
第三天到第六天为长度最长的均衡时期
因为 这四天 每种能力分别提升了 2次
#include<iostream>
#include<cstdio>
using namespace std;
int n,m,sum[][];
bool check(int l,int r){
int sta=;
for(int i=;i<m;i++){
if(i!=&&sum[r][i]-sum[l-][i]!=sta)return ;
if(i==)sta=sum[r][i]-sum[l-][i];
if(sum[r][i]-sum[l-][i]==)return ;
}
return ;
}
int main(){
scanf("%d%d",&n,&m);
int x;
for(int i=;i<=n;i++){
scanf("%d",&x);
for(int j=;j<m;j++){
sum[i][j]=sum[i-][j];
if((<<j)&x)sum[i][j]++;
}
}
int ans=;
for(int i=;i<=n;i++){
int now=ans;
for(int j=i+now;j<=n;j++){
int l=j-i+;
if(check(i,j))
ans=max(ans,l);
}
}
printf("%d",ans);
}
68分 暴力
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#define mod 9901
using namespace std;
map<vector<int>,int>f;
int ans;
int main(){
int n,m;scanf("%d%d",&n,&m);
vector<int>now(m);
f[now]=;
for(int i=;i<=n;i++){
int x;scanf("%d",&x);
for(int j=;j<m;j++)
if(x&(<<j))now[j]++;
if(x&)for(int j=;j<m;j++)now[j]--;
if(f.count(now))ans=max(ans,i-f[now]);
else f[now]=i;
}
printf("%d",ans);
}
100分
洛谷P1360 [USACO07MAR]黄金阵容均衡Gold Balanced L…的更多相关文章
- 洛谷 P1360 [USACO07MAR]黄金阵容均衡Gold Balanced L…
P1360 [USACO07MAR]黄金阵容均衡Gold Balanced L… 题目描述 Farmer John's N cows (1 ≤ N ≤ 100,000) share many simi ...
- [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 ...
- 洛谷P1360 [USACO07MAR]黄金阵容均衡题解
题目 不得不说这个题非常毒瘤. 简化题意 这个题的暴力还是非常好想的,完全可以过\(50\%\)的数据.但是\(100\%\)就很难想了. 因为数据很大,所以我们需要用\(O(\sqrt n)\)的时 ...
- [USACO07MAR]黄金阵容均衡Gold Balanced L…
https://www.luogu.org/problem/show?pid=1360 题目描述 Farmer John's N cows (1 ≤ N ≤ 100,000) share many s ...
- [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 ...
- [luoguP1360] [USACO07MAR]黄金阵容均衡Gold Balanced L…
传送门 真的骚的一个题,看了半天只会个前缀和+暴力.. 纯考思维.. 良心题解 #include <cstdio> #include <cstring> #include &l ...
- 洛谷 P1360 [USACO07MAR]Gold Balanced Lineup G (前缀和+思维)
P1360 [USACO07MAR]Gold Balanced Lineup G (前缀和+思维) 前言 题目链接 本题作为一道Stl练习题来说,还是非常不错的,解决的思维比较巧妙 算是一道不错的题 ...
- [LuoguP1360][USACP07MAR]黄金阵容均衡
[LuoguP1360][USACP07MAR]黄金阵容均衡(Link) 每天会增加一个数\(A\),将\(A\)二进制分解为\(a[i]\),对于每一个\(i\)都增加\(a[i]\),如果一段时间 ...
- 洛谷P3121 审查(黄金)Censoring(Gold) [USACO15FEB] AC自动机
正解:AC自动机 解题报告: 传送门! 啊我好呆啊其实就挺模板题的,,,只是要一个栈搞一下,,,然后我就不会了,,,是看了题解才get的,,,QAQ 然后写下解法趴QwQ 首先看到多串匹配不难想到AC ...
随机推荐
- 分享知识-快乐自己:关于 String 小案例
单个字符出现的次数: /*** * 验证是否符合拆分条件 * * @param text * 原字符串 * @param sub * 判断条件 * @return */ public static i ...
- HYSBZ - 1588 splay
题意:每天给你一个数,要求统计最小波动值,强制在线的就是每次从已经出现过的数值中找与当前值间隔最小的加起来 题解:splay维护,同时求解当前值的前驱和后继,找距离小的那个就好了 splay是一种二叉 ...
- C中malloc的使用(转)
malloc函数 原型:extern void *malloc(unsigned int num_bytes); 用法:#include <malloc.h> 功能:分配长度为num_b ...
- Selenium-js弹窗浮层
学习过js的小伙伴会发现,我们在一些实例中用到了alert()方法.prompt()方法.prompt()方法,他们都是在屏幕上弹出一个对话框,并且在上面显示括号内的内容,使用这种方法使得页面的交互性 ...
- Java 集合常用特点
1:集合:1) Collection(单列集合) --------------------------------------------------------------------- ...
- C#连接solr时提示 java内存异常 (jetty和tomcat哪个更High) java.lang.OutOfMemoryError
C#连接solr时提示 java内存异常 java.lang.OutOfMemoryError 时间:20180130 09:51:13.329,消息:异常消息<?xml version=& ...
- 【JVM】jvm垃圾回收器相关垃圾回收算法
引用计数法[原理]--->引用计数器是经典的也是最古老的垃圾收集防范.--->实现原理:对于对象A,只要有任何一个对象引用A,则计数器加1.当引用失效时,计数器减1.只要对象A的计数器值为 ...
- CTSC2017 游记
Day0 从早上8点开始坐车 公交--火车--地铁--地铁--步行--打的. 下午3:30我们终于报道完毕来到了试机地点. 这电脑简直比学校的电脑高级的不知道哪里去了. 内存3.8G,,,学校就2G. ...
- CentOS6和CentOS7服务开机启动
CentOS 6和CentOS 7都可以定义开机启动哪些服务,但CentOS 6的命令是chkconfig,CentOS 7是systemctl. 本文将介绍两种命令的实现方式. 一.CentOS 6 ...
- Java标签引起的陷阱
请看下面的代码,请问下面的代码是否能够通过编译: package com.yonyou.test; /** * 测试类 * @author 小浩 * @创建日期 2015-3-2 */ public ...