1043. 精简ID号码

1574080260

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;
}

    }
}
return 0;

}

Benson

确实数据挺水的,暴力模完全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;
}

Deuchie

这题的数据也太水了,我以为要用什么算法优化,结果直接暴力模就可以啊。

一时间没有想到怎么安排一下那个for循环,结果写出了感人的码风,有兴趣的同学可以看看23333

#include <cstdio>
#include <set>

using namespace std;

int main() {
    int n;
    scanf("%i", &n);
    for (int i = 0; i < n; ++i) {
        int g;
        scanf("%i", &g);
        int *number = new int[g];
        for (int j = 0; j < g; ++j)
            scanf("%i", number + j);

        for (int moder = g;; ++moder) {
            set<int> modulo;
            try {
                for (int j = 0; j < g; ++j) {
                    if (modulo.insert(number[j] % moder).second == false)
                        throw j;
                }
            } catch (int j) {
                continue;
            }
            printf("%i\n", moder);
            break;
        }
    }
}
你当前正在回复 博客/题目
存在问题!