哪位大神愿为小弟指点迷津?

#include<iostream>
int n,number[201]={0},x[1001]={0},x1[1001]={0},total=0;
using namespace std;
void putin()
{
cin>>n;
for(int i=1;i<=n;i++)
cin>>number[i];
}
void floyd()
{
int i,j,k;
for(k=1;k<=n;k++)
for(i=1;i<=k;i++)
for(j=1;j<=k;j++)
if(i+j==k && i!=j){
x[x[0]]=k;
x[0]++;
}
}
void work()
{
bool panduan=false;
for(int i=1;i<=n;i++){
panduan=false;
for(int j=1;j<=n;j++){
if(x[i]==x1[j])
panduan=true;
}
if(panduan==false){
total++;
x1[0]++;
x1[x1[0]]=x[i];
}
}
}
void putout()
{
cout<<total;
}
int main()
{
putin();
x[0]=1;
floyd();//我不知道这样讲准不准确,但它也是三重循环的……
work();
putout();
return 0;
}

2 条评论

  • @ 2016-09-05 18:59:27

    哈希?

  • @ 2016-07-25 16:40:36

    直接hash表
    c++
    #include <cstdio>
    #include <cstring>
    using namespace std;
    bool hash[20001];
    int a[1001],n,ans = 0;
    int main()
    {
    //freopen("count.in","r",stdin);
    //freopen("count.out","w",stdout);
    scanf("%d",&n);
    memset(hash,false,sizeof(hash));
    for (int i = 1;i <= n;i++)
    scanf("%d",&a[i]);
    for (int i = 1;i <= n;i++)
    for (int j = 1;j <= n;j++)
    {
    if(i == j) continue;
    hash[a[i]+a[j]] = true;
    }
    for (int i = 1;i <= n;i++)
    if(hash[a[i]])
    ans++;
    printf("%d",ans);
    return 0;
    }

  • 1

信息

ID
1911
难度
6
分类
(无)
标签
递交数
16923
已通过
4475
通过率
26%
被复制
26
上传者