173 条题解
-
0蛟川洋 LV 5 @ 2018-03-18 20:24:07
数据太水了,暴力都能过……
#include<bits/stdc++.h> using namespace std ; //Vijos P1911 bool x[20000] ; int main() { int y[100] , n , ans = 0 ; scanf("%d" , &n) ; for (int i = 0 ; i < n ; i ++) { scanf("%d" , &y[i]) ; } for (int i = 0 ; i < n - 1 ; i ++) for (int j = i + 1 ; j < n ; j ++) { x[y[i] + y[j]] = true ;//有这个和的打上标记 } for (int i = 0 ; i < n ; i ++) { if (x[y[i]]) ans ++ ;//打过标记的个数就是答案 } printf("%d" , ans) ; return 0 ; }
-
02018-02-28 15:22:59@
#include<iostream>
#include<cstdio>
using namespace std;
int t[200005],g[200005];//t是桶,t[i]表示值为i的数在集合中两两相加出现了几次,g[i]表示值为i的数是否在集合中,1为在,0为不在
int n,a[105],ans;
int main(){
cin>>n;
for (int i=1;i<=n;i++){
cin>>a[i];//读入
g[a[i]]=1;//在集合中赋值为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++;//判断是否满足,满足ans++
}
cout<<ans<<endl;
return 0;
} -
02018-02-27 10:19:50@
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;public class Main {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
List<Integer> list = new ArrayList<Integer>();
for(int i=0;i<n;i++){
int m = scanner.nextInt();
list.add(m);
}
Set<Integer> set = new HashSet<Integer>();
for(Integer i:list){
for(Integer j:list){
if(i != j){
int m = i + j;
if(list.contains(m) && !set.contains(m)){
set.add(m);
}
}
}
}
System.out.println(set.size());
scanner.close();
}
} -
02018-02-27 10:15:16@
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;public class Main {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
List<Integer> list = new ArrayList<Integer>();
for(int i=0;i<n;i++){
int m = scanner.nextInt();
list.add(m);
}
Set<Integer> set = new HashSet<Integer>();
for(Integer i:list){
for(Integer j:list){
if(i != j){
int m = i + j;
if(list.contains(m)){
set.add(m);
}
}
}
}
System.out.println(set.size());
scanner.close();
}
} -
02018-02-09 09:12:47@
#include<iostream> #include<cstdio> using namespace std; bool flag[100010]; int a[1010]; int main(){ int n;int ans=0; scanf("%d",&n); for(int i=1;i<=n;++i){ scanf("%d",&a[i]); flag[a[i]]=1; } for(int i=1;i<=n;++i){ for(int j=i+1;j<=n;++j){ if(flag[a[i]+a[j]]==1){ flag[a[i]+a[j]]=0; ans++; } } } printf("%d",ans); return 0; }
-
02018-01-14 11:28:45@
-
02018-01-07 11:11:38@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>int main()
{
int n,i,j,k,c=0,a[100],t,b[100];
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n-1;i++)
for(j=0;j<n-1;j++)
{
if(a[j]>a[j+1])
{
t=a[j];a[j]=a[j+1];a[j+1]=t;
}
}
for(i=0;i<n;i++)
b[i]=a[i];
for(i=0;i<n-2;i++)
for(j=i+1;j<n-1;j++)
for(k=j+1;k<n;k++)
{
if(a[i]+a[j]==a[k]&&b[k]!=0)
{c++;b[k]=0;}
}
printf("%d\n",c);
return 0;
} -
02018-01-05 14:28:14@
C++比较好理解的方法:
#include<iostream>
using namespace std;int main()
{
int n,tot=0;
cin>>n;
int m[n];
for(int i=0;i!=n;++i)
cin>>m[i];
//先排序:
for(int i=0;i!=n-1;++i)
{
int maxid=0;
for(int j=1;j!=n-i;++j)
if(m[j]>m[maxid]) maxid=j;
int t=m[maxid];
m[maxid]=m[n-1-i];
m[n-1-i]=t;
}
//定义一个数组避免重复得结果:
int a[n];
for(int i=0;i!=n;++i)
a[i]=m[i];
//循环判断:
for(int i=0;i!=n-2;++i)
{
for(int j=i+1;j!=n-1;++j)
{
for(int k=j+1;k!=n;++k)
if(m[i]+m[j]==a[k]) {++tot;a[k]=0;}
}
}
cout<<tot<<endl;
} -
02017-12-07 14:40:08@
#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;int main()
{
int N;
unordered_map<int, int> s;
std::cin >> N;
vector<int> nums(N, 0);
for (int i = 0; i < N; ++i) {
std::cin >> nums[i];
s[nums[i]]++;
}int result = 0;
for (int i=0; i<nums.size(); ++i) {
for (int j=i+1; j<nums.size(); ++j) {
if (s.find(nums[i]+nums[j])!=s.end()) {
if (s[nums[i]+nums[j]] == 1)
result++;
s[nums[i]+nums[j]]++;
}
}
}
std::cout << result;
} -
02017-12-07 11:09:53@
n = int(raw_input())
a = [int(i) for i in raw_input().split()]
s = set([i + j for i in a for j in a if i != j and i + j in a])
print len(s) -
02017-12-01 11:25:19@
//可以不用数组保存的啊,有个计数器就好啦,下面是已通过的代码 #include <stdio.h> #include <stdlib.h> int main() { int n = 0; scanf("%d", &n); int *nums = (int*)malloc(sizeof(int)*n); for (int i = 0; i < n; i++) { scanf("%d", &nums[i]); } int count = 0; for (int i = 0; i < n; i++) { int had_find = 0; for (int j = 0; j < n - 1; j++) { for (int k = j+1; k < n; k++) { if (k == i || k == j) continue; if (nums[j] + nums[k] == nums[i]) { ++count; had_find = 1; break; } } if (had_find != 0) break; } } printf("%d", count); }
-
02017-11-28 14:18:06@
#include<cstdio> int t[200010], g[200010]; int n, a[105], count=0; int main() { scanf("%d", &n); for(int i=1; i<=n; i++) { scanf("%d", &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]) count++; printf("%d", count); return 0; }
-
02017-11-10 21:21:09@
终于过了
#include <stdio.h>
int main()
{
int a[100];
int c[100];
int i,j,n,k,l,b,s;
scanf("%d",&n);
s=0;
for(i=1;i<=n;i++) scanf("%d",&a[i]);
for(i=1;i<=n;i++) c[i]=-1;
for(i=1;i<=n;i++)
for(j=i+1;j<=n;j++)
for(k=1;k<=n;k++) {
b=a[i]+a[j];
if(b==a[k]){
for(l=1;l<=n;l++) if(a[k]==c[l]) {
l=0;break;}
if(l==0) break;
s++;
c[s]=b;}}
printf("%d",s);}
-
02017-11-09 19:43:11@
//以通过
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;bool equal(vector<int>&vec2, int val)
{
for (auto i = vec2.begin(); i != vec2.end(); i++)
{
if (val == *i)
{
i = vec2.erase(i); //注意erase用法
return 1;
}
}
return 0;}
int main()
{
vector<int>vec1,vec2;
int n, t , count = 0;
cin >> n;while (n--)
{
cin >> t;
vec1.push_back(t); //存入
}
sort(vec1.begin(),vec1.end()); //排序 注意排序用法
vec2 = vec1;for (auto i = vec1.begin(); i != vec1.end(); i++)
{
for (auto i2 = i+1; i2 != vec1.end(); i2++)
{
auto temp = *i2 + *i;if (equal(vec2, temp))
count++;
}
}cout << count;
return 0;
} -
02017-11-01 17:16:25@
program lx; var a:array[1..110]of integer; b:array[1..110]of boolean; i,j,k,n,sum:longint; begin readln(n); for i:=1 to n do begin read(a[i]); b[i]:=false; end; i:=0; repeat i:=i+1; for j:=1 to n do for k:=1 to n do if (a[k]+a[j]=a[i])and(a[j]<>a[k]) then begin // writeln(a[j],'+',a[k],'=',a[i]); b[i]:=true; break; end; until i=n; for i:=1 to n do if b[i] then sum:=sum+1; write(sum); end.
做了快不下10次 最后发现没看懂题 想复杂了(逃
-
02017-11-01 11:38:54@
//纯暴力
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
int N[101],ans,vis[101];
int main()
{
int n;cin>>n;
for(int i=1;i<=n;i++)
cin>>N[i];
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
for(int k=1;k<=n;k++)
if(N[j]+N[k]==N[i]&&!vis[i]&&j!=k&&i!=j&&i!=k)
{
vis[i]=1;
ans++;
}
}
cout<<ans;
return 0;
} -
02017-10-19 23:08:31@
#include<iostream>
using namespace std;
const int maxn=200000;
int a[maxn],fin[maxn],n,ans;
int main ()
{
cin>>n;
for (int i=1;i<=n;i++)
cin>>a[i];
for (int i=1;i<=n;i++)
for(int j=i+1;j<=n;j++)
fin[a[i]+a[j]]=1;
for (int i=1;i<=n;i++)
if (fin[a[i]])
ans++;
cout<<ans;
} -
02017-10-01 00:34:34@
注意需要处理第二行数字的个数
n = int(input()) lst = list(input().split(' ')) lst1=lst[:n] lst2= list(map(int,lst1)) times = [] for i in lst2: for j in lst2: if i < j and i + j in lst2 and i+j not in times: times.append(i+j) print(len(times))
-
02017-09-27 21:29:06@
#include<iostream>
using namespace std;
int main()
{
int n,i,j,sum=0,c[20100],a[110];
cin>>n;for(i=0;i<n;i++)
cin>>a[i];
for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
c[a[i]+a[j]]=1;
for(i=0;i<n;i++) if(c[a[i]]==1)
sum++;
cout<<sum;
} -
02017-09-05 21:23:44@
#include <cstdio> int num[100086],n,cnt; bool exist[100086]; int main() { scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d",&num[i]); exist[num[i]] = 1; } for(int i=1;i<=n;i++) { for(int j=i+1;j<=n;j++) { exist[num[i]+num[j]]=0; } } for(int i=1;i<=n;i++) { if(exist[num[i]] == 0) cnt++; } printf("%d\n",cnt); return 0; }
信息
- ID
- 1911
- 难度
- 6
- 分类
- (无)
- 标签
- 递交数
- 17097
- 已通过
- 4518
- 通过率
- 26%
- 被复制
- 28
- 上传者