- 珠心算测验
- @ 2016-07-23 17:13:12
#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 条评论
- 
  十三太保 LV 6 @ 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
- 分类
- (无)
- 标签
- 递交数
- 17156
- 已通过
- 4540
- 通过率
- 26%
- 被复制
- 30
- 上传者