bool is_repeat(vector data)
{
if (data.size() == 1)
return false;
auto left = data.begin(), right = left + 1;
while (left < data.end())
{
right = left + 1;
while (right < data.end())
{
if (right == left)
return true;
++right;
}
++left;
}
return false;
}
int main(int argc, char* argv[])
{
int n;
cin >> n;
vector answer(n);
for (auto k = 0; k < n; k++)
{
int g;
cin >> g;
vector data(g);
for (auto& da : data)
cin >> da;
auto mod = 0;
auto temp_data = data;
do
{
temp_data = data;
mod++;
for (auto& da : temp_data)
da %= mod;
} while (is_repeat(temp_data));
answer[k] = mod;
}
for (auto ans : answer)
cout << ans << endl;
return 0;
}
include
include
int main()
{
int N;
scanf(“%d”,&N);//输入次数
int i;
for(i=0; i<N; i++){
int G;
scanf(“%d”,&G);//输入个数
int j,sin[G];
for(j=0; j<G; j++){
scanf(“%d”,&sin[j]);//输入数组
}
int a[G];
int k;
for(k=1;; k++){
if(G == 1){
printf(“1\n”);//特殊情况
break;
}
for(j=0; j<G; j++){
a[j] = sin[j] % k;//取余
}
int x = 0, p;
for(j=0; j<G-1; j++){
for(p=j+1; p<G; p++){
x += (a[j] == a[p]);//验证
}
}
if(x == 0){
printf(“%d\n”,k);//输出
break;
}
}
确实数据挺水的,暴力模完全ok!
include
include
include
using namespace std;
bool is_repeat(vector data)
{
if (data.size() == 1)
return false;
auto left = data.begin(), right = left + 1;
while (left < data.end())
{
right = left + 1;
while (right < data.end())
{
if (right == left)
return true;
++right;
}
++left;
}
return false;
}
int main(int argc, char* argv[])
{
int n;
cin >> n;
vector answer(n);
for (auto k = 0; k < n; k++)
{
int g;
cin >> g;
vector data(g);
for (auto& da : data)
cin >> da;
auto mod = 0;
auto temp_data = data;
do
{
temp_data = data;
mod++;
for (auto& da : temp_data)
da %= mod;
} while (is_repeat(temp_data));
answer[k] = mod;
}
for (auto ans : answer)
cout << ans << endl;
return 0;
}
这题的数据也太水了,我以为要用什么算法优化,结果直接暴力模就可以啊。
一时间没有想到怎么安排一下那个for循环,结果写出了感人的码风,有兴趣的同学可以看看23333