验证中...
本周日【珠海源创会】一起聊聊:PingCAP分布式事务、支付宝移动端实践、GSBN技术框架选型,点此报名占座
片段 1 片段 2 片段 3
gistfile1.txt
原始数据 复制代码
#include<iostream>
#include<math.h>
using namespace std;
#define ARRSIZE 200000
int Hash_Fun(int x, int times) { return (x % ARRSIZE + pow(times, 2)); }
void Cow()
{
int N, K; //读取奶牛数和特点数
cin >> N >> K;
int* Cows = new int[N]; //所有奶牛
int features = pow(2, K); //特点值
int Sum = 0;
int maxRange = 0;
int* binary = new int[K];
for (int u = 0; u < K; u++)
binary[u] = 0;
static int record[ARRSIZE][33] = { 0 };
for (int i = 0; i < N; i++)//读取每一头奶牛的特点值
{
cin >> Cows[i];
Sum = (Sum + Cows[i]) % (features - 1);
bool flag = true;
for (int w = 0; w < K; w++)
{
binary[w] += Cows[i] % 2;
if (w > 0 && binary[w] != binary[w - 1])flag = false;
Cows[i] /= 2;
}
if (flag && (i + 1) > maxRange)maxRange = i + 1;
//Sum = (Sum + Cows[i]) % (features - 1);
int count = 0;
while (true)
{
flag = true;
for (int f = 1; f < K; f++)
if (binary[f] - record[Hash_Fun(Sum, count)][f] != binary[f - 1] - record[Hash_Fun(Sum, count)][f - 1]) { flag = false; break; }
if (flag)
{
record[Hash_Fun(Sum, count)][K + 1] = i - record[Hash_Fun(Sum, count)][K];
break;
}
else if (record[Hash_Fun(Sum, count)][K + 2] == 0)
{
record[Hash_Fun(Sum, count)][K + 2] = 1;
for (int f = 0; f < K; f++)
record[Hash_Fun(Sum, count)][f] = binary[f];
record[Hash_Fun(Sum, count)][K] = i;
break;
}
count ++;
}
}
for (int i = 0; i < ARRSIZE; i++)
{
if (record[i][K + 1] > maxRange)
maxRange = record[i][K + 1];
}
cout << maxRange;
}
int main()
{
Cow();
}
屏幕截图(91).png
屏幕截图(92).png

评论列表( 0 )

你可以在登录后,发表评论

搜索帮助

12_float_left_people 12_float_left_close