173 条题解
-
0任雨蒙 (Amamiyaren) LV 5 @ 2021-01-20 21:44:19
python 暴力枚举
n = eval(input()) num = [eval(x) for x in input().split()] lst = [] count = 0 for i in num: for j in num: if i==j: continue else: sum=i+j if sum in lst: continue else: lst.append(sum) if sum in num: count+=1 print(count)
-
02020-12-22 21:41:39@
n = int(input()) num = list(input().split(' ')) sum = list() ans = 0 k = list() Temp = list() for i in range(n): for j in range(n): if i != j: k.append(int(num[i])+int(num[j])) for a in range(0,(n*n - n)): for b in range(0,n): if int(k[a]) == int(num[b]): if k[a] not in Temp: ans+=1 Temp.append(k[a]) print(ans)
-
02020-05-19 05:32:41@
#include <stdio.h>
main() {
int N,n, x, l = 0;
scanf("%d %d", &n, &x);
for (int i = 1; i <= n; i++)
{
for (int j = 0,k=i; k >0; j++)
{N = k % 10;
if (N == x)
l += 1;
k = k / 10;
}
}
printf("%d", l);
} -
02020-04-13 14:08:33@
#include <iostream> //[2014普及组-A]珠心算测验 #include <algorithm> #include <map> using namespace std; int main() { //map<int, int> m; int m[20001] = {0}; int n, num, ans = 0; int N[100] = {0}; cin >> n; for (int i = 0; i < n; i++) { cin >> num; N[i] = num; m[num] = 1; } for (int i = 0; i < n - 1; i++) for (int j = i + 1; j < n; j++) if(m[N[i] + N[j]] == 1) { m[N[i] + N[j]] = 0; ans++; } cout << ans << endl; return 0; }
-
02020-03-10 18:02:27@
思路:数组计数,由于只记是否出现,用bitset压缩空间
#include <iostream> #include <bitset> using namespace std; int main() { bitset<20001> t;//其无参构造函数将全部元素置0,不需初始化 int n, n_set[100], ans = 0; scanf("%d", &n); for (int i = 0; i < n; ++i) scanf("%d", &n_set[i]); for (int i = 0; i < n; ++i) for (int j = 0; j < i; ++j) t[n_set[i] + n_set[j]] = 1; for (int i = 0; i < n; ++i) if (t[n_set[i]])++ans; printf("%d", ans); }
-
02020-03-05 22:18:26@
#include<iostream>
#include<cstdio>
#include<algorithm>using namespace std;
int a[110]={};
int b[20002]={};int main(){
int n;
cin>>n;
int *q;
int count=0;
for(int i=0;i<n;i++){
cin>>a[i];
b[a[i]]=1;
}
int x;
for(int j=0;j<n-1;j++){
for(int k=j+1;k<n;k++){
x=a[j]+a[k];
if(b[x]==1){
count++;
b[x]=0;
}
}
}
cout<<count<<endl;
return 0;
} -
02019-12-22 10:30:55@
#include<stdio.h>
int main()
{
int n;
int i,b,c,a[100],count=0;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
for(b=0;b<n;b++)
for(c=0;c<n;c++)
if(b!=c && (a[i]==a[b]+a[c]))
{
count++;
i++;
b=0;c=0;
}
printf("%d",count);
return 0;
} -
02019-12-12 14:31:10@
#include<iostream>
using namespace std;int main()
{
int N;
cin >> N;
int *num = new int[N];
int a = 0;
int res = 0;
int temp = 0;
for (int i = 0; i < N; i++)
{
cin >> a;
num[i] = a;
}
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
for (int k = j+1; k < N; k++)
{
temp = res;
if ((num[i] == num[j] + num[k])&&(j!=k))//对num里的每个数进行遍历,为避免重复,(5 = 1+4,5=2+3),应跳出两重循环。
{
res++;
break;
}
}
if (res > temp)
{
break;
}
}
}
cout << res << endl;
return 0;
} -
02019-11-21 09:17:35@
#include<iostream>
using namespace std;
int main(){
int n;
cin >> n;
int num;
num = (int)malloc(sizeof(int)*n);
for (int i = 0; i < n; i++){
cin >> num[i];
}
int lable = 0;
int current = 0;
while (current<=(n-1))
{
int limit = 0;
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++){
if (j != i&&j != current&&i != current&&limit==0){
if (num[i] + num[j] == num[current]){
lable++;
limit++;
cout << "hhh" << endl;
cout << " " << num[i] << " " << num[j] << " " << num[current]<<endl;
break;
}
}
}
}
current++;
}
cout << lable << endl;
return 0;
} -
02019-11-15 15:24:35@
/*此算法虽然不高级,但是好理解,
就是建立一个数组b来存两数相加的值,然后遍历a[0]-a[n-1]
如有a[i]==数组b中的一个值,sum++;并且要break避免重复。
*/#include<iostream> #include<cstdio> #include<cstring> using namespace std; int main() { int b[100002]; int h=0; int i=0; int sum=0; int n; int j; cin>>n; int a[n]; for(int k=0;k<n;k++) cin>>a[k]; for(i=0;i<n;i++){ for(j=i+1;j<n;j++){ b[h]=a[i]+a[j]; h++; } } for(j=0;j<n;j++){ for(i=0;i<h;i++){ if(a[j]==b[i]){ sum++; break; } } } cout<<sum; return 0; }
-
02019-10-19 23:58:14@
#include<iostream>
#include<algorithm>
using namespace std;
bool cmp(int a,int b)
{
return a<b;
}
int main()
{
int n;
cin>>n;
int *num = new int[n];
for(int i=0;i<n;i++)
{
cin>>num[i];
}
sort(num,num+n,cmp);
int cnt = 0;
for(int i=2;i<n;i++)
{
for(int j=0,k=i-1;j<k;)
{
if(num[j]+num[k]==num[i])
{
cnt++;
break;
}else if(num[j]+num[k]<num[i]) j++;
else k--;
}
}
cout<<cnt<<endl;
} -
02019-10-10 14:58:47@
#include<iostream>
using namespace std;
int main(){
int number;
const int N=100;
long int test[N];
int op=0;
int i=0;
int u;
int count=0;
int iffind=0;
cin>>number;
for(;i<number;i++){
cin>>test[i];
}
for(i=0;i<number;i++){
iffind=0;
for(u=0;u<number-1;u++){
if(iffind==1) break;
for(op=u+1;op<number;op++){
if(op!=i&&u!=i&&test[i]==test[u]+test[op]){
count++;
iffind=1;
break;
}
}
}
}
cout<<count;
} -
02018-12-06 20:45:40@
#include <iostream>
using namespace std;
int main()
{
int a[20002]={0};
bool visited[20002]={0};
int n;
cin>>n;
int x,sum=0;
int maxi = 0;
while(n--){
cin>>x;
a[x] = 1;
if(maxi<x)
maxi = x;
}
for(int i = 1;i < maxi; i++){
if(a[i]==1)
for(int j = i+1;j <= maxi; j++){
if(a[j]==1){
if(a[i+j]==1&&visited[i+j]!=1){
sum++;
visited[i+j] = 1;
}
}
}
}
cout<<sum;}
-
02018-11-04 12:52:40@
c++代码
#include<bits/stdc++.h>
using namespace std;
int a[103],b[103];
int main(){
int n,s=0;
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
for(int q=1;q<=n;q++)
if(a[j]!=a[q] && a[j]+a[q]==a[i]) b[i]=1;
for(int i=1;i<=n;i++)
if(b[i]==1) s++;
cout<<s;
return 0;
} -
02018-10-07 08:26:04@
#include<iostream>
#include<cstdio>
using namespace std;
int t[200005],g[200005];
int n,a[105],ans;
int main(){
cin>>n;
for (int i=1;i<=n;i++){
cin>>a[i];
g[a[i]]=1;
}
for (int i=1;i<n;i++){
for (int j=i+1;j<=n;j++){
t[a[i]+a[j]]++;
}
}
for (int i=1;i<=200002;i++){
if (t[i]>0&&g[i]) ans++;
}
cout<<ans<<endl;
return 0;
} -
02018-10-06 11:02:01@
题目略坑,看懂就行
#include <stdio.h>
#include <string.h>
int main()
{
int n,ans;
int a[20000];
int b[20000];
memset(b,0,sizeof(b));
ans=0;
scanf("%d",&n);
for (int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
b[a[i]]=1;
}
for (int j=1;j<=n;j++)
{
for (int k=j+1;k<=n;k++)
{
if (b[a[j]+a[k]]==1)
{
b[a[j]+a[k]]=2;
}
}
}
for (int l=1;l<=n;l++)
{
if (b[a[l]]==2)
{
ans++;
}
}
printf("%d",ans);
return 0;
} -
02018-08-16 20:34:44@
#include <stdio.h> #include <stdlib.h> #include <math.h> int main() { int counter = 0; int num[100]; int n; int i, j, k, flag; scanf("%d",&n); for(i = 0; i < n; i++) scanf("%d",num + i); for(i = 0; i < n; i++) { flag = 0; for(j = 0; j < n; j++) for(k = 0; k < n; k++) if(num[i] == (num[j] + num[k]) && i != k && i != j && j != k) flag = 1; if(flag) counter++; } printf("%d",counter); return 0; }
-
02018-08-07 15:03:49@
#include<iostream>
using namespace std;
int b[110];
int main(){
int n;
int a,sum=0;
cin>>n;
for(int i=0;i<n;i++){
cin>>a;
b[i]=a;
}
for(int i=0;i<n;i++)
{
int flag=0;
for(int j=0;j<n;j++)
{
for(int w=0;w<n;w++)
{
if(b[i]==b[w]+b[j]&&flag==0&&i!=w&&i!=j&&j!=w)
{
flag=1;
sum++;
}
}
}
}
cout<<sum;
return 0;
} -
02018-07-19 20:26:48@
#include<stdio.h>
int main ()
{
int i,j,k=0,l=0,n,x,m=0;
scanf("%d",&n);
int a[n];
for(i=0;i<n;i++)
scanf("%d",&a[i]);while(k<n)
{
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
if(a[i]+a[j]==a[k]&&a[i]!=a[j]&&k<n)
{
m++;
k++;
break;
}
if(l==k)
k++;
l++;}
printf("%d",m);
return 0;
} -
02018-04-25 19:54:39@
int n, count = 0; scanf("%d",&n); int *a = (int *)malloc(sizeof(int)*n); int *c = (int *)malloc(sizeof(int)*20000); for (int i = 0; i != n;++i) { scanf("%d",a+i); } for (int i = 0; i != n - 1;++i) { for (int j = i + 1; j != n;++j) { c[a[i] + a[j]] = 1; } } for (int i = 0; i != n;++i) { if (c[a[i]]==1){ ++count; } } printf("%d\n", count); free(a); free(c);
信息
- ID
- 1911
- 难度
- 6
- 分类
- (无)
- 标签
- 递交数
- 17097
- 已通过
- 4518
- 通过率
- 26%
- 被复制
- 28
- 上传者