173 条题解
-
0xuelvchun LV 6 @ 2017-08-31 20:39:38
program num;
var
i,ans,n,j,k:longint;
a:array [1..100] of longint;
g:array [1..10000] of longint;
procedure kp(l,r:longint);
var
i,j,m,t:longint;
begin
i:=l; j:=r;
m:=a[(l+r) div 2];
repeat
while a[i]<m do inc(i);
while a[j]>m do dec(j);
if i<=j then begin
t:=a[i]; a[i]:=a[j]; a[j]:=t;
inc(i); dec(j);
end;
until i>j;
if l<j then kp(l,j);
if i<r then kp(i,r);
end;
begin
fillchar(g,sizeof(g),0);
readln(n); ans:=0;
for i:=1 to n do read(a[i]);
kp(1,n);
for i:=1 to n-2 do
for j:=i+1 to n-1 do
for k:=j+1 to n do
if (a[i]+a[j]=a[k])and(g[a[k]]=0) then begin inc(g[a[k]]); inc(ans); end;
writeln(ans);
end. -
02017-08-17 15:44:33@
#include<bits/stdc++.h> using namespace std; const int MAXN=111; int N,a[MAXN],vis[101000]; int main() { cin>>N; for(int i=1;i<=N;i++) cin>>a[i]; sort(a+1,a+1+N); int ans=0; for(int i=1;i<=N;i++) vis[a[i]]=1; for(int i=1;i<N;i++) for(int j=i+1;j<=N;j++) if(vis[a[i]+a[j]]==1) { vis[a[i]+a[j]]=0;//vis要清零 ans++; } cout<<ans<<endl; return 0; }
-
02017-08-14 10:57:22@
亲测AC代码(NB指the bigger number)
#include <bits/stdc++.h> using namespace std; int n, i, j, sum, N[110], NB[100010]; int main() { cin >> n; for(i = 0; i < n; i++) { cin >> N[i]; NB[N[i]] = 1; } for(i = 0; i < n; i++) for(j = i + 1; j < n; j++) NB[N[i] + N[j]] = 0; for(i = 0; i < n; i++) if(NB[N[i]] == 0) sum++; cout << sum; return 0; }
-
02017-08-12 16:34:19@
#include<stdio.h>
#include<map>
using namespace std;
const int maxn = 105;
int a[maxn];
int main()
{
int n;
map<int, int> mp;while (scanf("%d", &n) != EOF)
{
int i, j;
for (i = 0; i < n; i++)
scanf("%d", &a[i]);
for (i = 0; i < n; i++)
{
mp[a[i]] = 1;
}
for (i = 0; i < n; i++)
{
for (j = i + 1; j < n; j++)
{
mp[a[i] + a[j]] = 0;
}
}
int c = 0;
for (i = 0; i < n; i++)
{
if (mp[a[i]] == 0)
c++;
}
printf("%d\n", c);
}
return 0;
} -
02017-08-12 16:34:17@
#include<stdio.h>
#include<map>
using namespace std;
const int maxn = 105;
int a[maxn];
int main()
{
int n;
map<int, int> mp;while (scanf("%d", &n) != EOF)
{
int i, j;
for (i = 0; i < n; i++)
scanf("%d", &a[i]);
for (i = 0; i < n; i++)
{
mp[a[i]] = 1;
}
for (i = 0; i < n; i++)
{
for (j = i + 1; j < n; j++)
{
mp[a[i] + a[j]] = 0;
}
}
int c = 0;
for (i = 0; i < n; i++)
{
if (mp[a[i]] == 0)
c++;
}
printf("%d\n", c);
}
return 0;
} -
02017-08-12 11:19:00@
#include<vector>
#include<algorithm>
#include<iostream>
using namespace std;inline void input(vector<int> &p, int n){
int i;
for(i = 0; i < n; ++i){
cin>>p[i];
}
}
inline int count(vector<int> &p, int n){
int i, j, k;
int c = 0;
char is;
for(k = 2; k < n; ++k){is = 0;
for(i = 0; i < k; ++i){
if(p[k] > p[i] + p[k - 1]){
continue;
}
for(j = k - 1; j > i; --j){
if(p[k] < p[i] + p[j]){
continue;
}else{
if(p[k] > p[i] + p[j]){
break;
}else{
is = 1;
break;
}
}
}
if(is){
++c;
break;
}
}}
return c;
}int main(){
int n;
cin>>n;vector<int> s(n, 0);
input(s, n);sort(s.begin(), s.end());
int c = count(s, n);
cout<<c<<endl;
return 0;
}
-
02017-08-12 10:04:16@
#include"stdio.h"
int a[101];
int b[101];
int main()
{
int n,i,j,k,sum=0,l;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}for(i=1;i<=n;i++)
{
for(j=i;j<=n;j++)
{
if(a[i]>a[j])
{
k=a[i];
a[i]=a[j];
a[j]=k;
}
}
}for(i=1;i<=n;i++)
{
b[i]=a[i];
}for(i=1;i<=n;i++)
{
for(j=i+1;j<=n;j++)
{k=a[i]+a[j];
for(l=j+1;l<=n;l++)
{
if(k==b[l])
{
sum++;
b[l]=0;
}
}
}
}printf("%d",sum);
return 0;
} -
02017-08-01 09:46:10@
不要和我比简洁
var a:array[1..100]of longint;
f:array[1..20000]of boolean;
n,i,j,s:longint;
begin
read(n);
fillchar(f,sizeof(f),false);
for i:=1 to n do
begin
read(a[i]);
for j:=i-1 downto 1 do
f[a[i]+a[j]]:=true;
end;
for i:=1 to n do
if f[a[i]] then inc(s);
write(s);
end. -
02017-07-20 17:58:05@
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <cctype>
#include <vector>
#include <queue>
#include <set>
#include <bitset>
#include <cassert>
#include <map>
#include <string>
#include <sstream>
#include <ctime>
using namespace std;
int z[10010];
bool a[10010];
int main()
{
int n,s=0;
memset(a,0,sizeof(a));
scanf("%d",&n);
for(int i=0;i<=n-1;i++)
{
scanf("%d",&z[i]);
}
sort(z,z+n);
for(int i=1;i<=n-1;i++)
{
for(int j=0;j<i;j++)
{
for(int k=i;k<=n-1;k++)
{
if(z[k]==z[i]+z[j])
{
if(a[k]==0)
{
a[k]=1;
s++;
}
}
}
}
}
printf("%d",s);
return 0;
} -
02017-07-10 10:43:34@
pascal 暴力解决(题目太坑,做错了好几遍
var n,i,j,k,t,x,m:integer; a:array[1..100]of integer;b:array[1..10000]of boolean; begin readln(n);m:=0; fillchar(b,sizeof(b),true); for i:= 1 to n do begin read(a[i]); if a[i]>m then m:=a[i]; end; for i:= 1 to n do for j:= i+1 to n do begin x:=a[i]+a[j]; if (i<>j)and(x<=m)and(b[x]=true) then for k:= 1 to n do if x=a[k] then begin t:=t+1; b[x]:=false; end; end; write(t); end.
-
02017-06-17 13:02:31@
pascal AC
var a,g:array[0..100001] of longint;
n,i,j:longint;
s:qword;
begin
readln(n);
for i:=1 to n do
begin
read(a[i]);
inc(g[a[i]]);
end;
for i:=1 to n-1 do
for j:=i+1 to n do
if g[a[i]+a[j]]=1 then begin inc(s); inc(g[a[i]+a[j]]); end;
write(s);
end. -
02017-06-07 23:05:41@
怎么说呢,本来用这个代码的时候是int Number[n]的,结果次次Runtime Error,只好看了看题,改了100和100000,因为10000也报错……
#include <iostream> using namespace std; int main() { int n,i,j,total=0; cin>>n; int Number[100]={0}; int NumberBiger[100000]={0}; for(i=0;i<n;i++) { cin>>Number[i]; NumberBiger[Number[i]]=1; } for(i=0;i<n;i++) for(j=i+1;j<n;j++) NumberBiger[Number[i]+Number[j]]=0; for (i=0;i<n;i++) if(NumberBiger[Number[i]]==0) total++; cout<<total; return 0; }
-
02017-05-25 16:47:25@
这道题的思路主要是如何处理重复的情况,比如1+2=3,2+1=3。可以选择这样一种方法,对于某个数,使用三层循环遍历。最外面一层是为了验证每个数,里面两层分别验证加数和被加数。对于每个数,只要找到一种情况比如对于3找到1+2,那么就强制退出内两层循环并继续验证下一个数。
#include<iostream> int quantity(); int* init(int n); int compute(int temp[], int n); int main() { int n = quantity(); int* temp = init(n); int result = compute(temp, n); std::cout << result << std::endl; return 0; } int quantity() { using namespace std; int n = 0; cin >> n; return n; } int* init(int n) { using namespace std; int* temp = new int[n]; for(int i = 0;i < n;i++) { cin >> temp[i]; } return temp; } int compute(int temp[] ,int n) { using namespace std; int count = 0; for(int i = 0;i < n;i++) for(int j = 0;j < n;j++) { bool HaltJ = true; for(int k = 0;k < n;k++) { bool HaltK = true; if(temp[i] >= 3 && temp[j] != temp[k] && (temp[j] + temp[k]) == temp[i]) { count++; HaltJ = false; HaltK = false; } if(!HaltK) { break; } } if(!HaltJ) { break; } } return count; }
-
02017-05-09 12:55:38@
#include <stdio.h> //goto的妙用 int main() { int n; scanf("%d",&n); int nums[n]; int times=0; for(int i=0;i<n;i++) { scanf("%d",&nums[i]); } /* one:需要找到两个数的和为它 two:寻找数1 three:寻找数2 */ for(int one=0;one<n;one++) { for(int two=0;two<n;two++) { if(one!=two) { for(int three=0;three<n;three++) { if(three!=two&&three!=one&&nums[one]==(nums[two]+nums[three])) { times++; //我知道用goto不推荐,但确实很方便 goto out; } } } } out:continue; } printf("%d",times); }
-
02017-04-19 19:36:52@
用了STL
#include <iostream> #include <unordered_set> using namespace std; int main() { int n; cin >> n; std::unordered_set<int> in; for (int i = 0; i < n; ++i) { int tmp; cin >> tmp; in.insert(tmp); } std::unordered_set<int> out; for (const auto i : in) { for (const auto j : in) { if ((i != j) && (in.find(i + j) != end(in))) { out.insert(i + j); } } } std::cout << out.size() << std::endl; }
-
02017-04-15 09:45:35@
注意一下题目是问和的个数,也就是说(2+4=6 和 3+3=6 还有 1+5=6 都只算一种),所以就用一个
f[]
数组来记录这个数是否被算过和了。#include <cstdio> int a[200],f[30010],ans,n; int main(){ scanf("%d",&n); for (int i=1; i<=n; i++) f[(scanf("%d",&a[i]),a[i])]=1; for (int i=1; i<n; i++) for (int j=i+1; j<=n; j++) ans+=f[a[i]+a[j]],f[a[i]+a[j]]=0; printf("%d",ans); }
-
02017-01-03 01:04:53@
来一份逻辑清晰的代码,不过下面有更加酷炫代码可以参考。
编译成功
测试数据 #0: Accepted, time = 0 ms, mem = 512 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 508 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 512 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 508 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 512 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 512 KiB, score = 10
测试数据 #6: Accepted, time = 0 ms, mem = 512 KiB, score = 10
测试数据 #7: Accepted, time = 15 ms, mem = 508 KiB, score = 10
测试数据 #8: Accepted, time = 0 ms, mem = 508 KiB, score = 10
测试数据 #9: Accepted, time = 0 ms, mem = 512 KiB, score = 10
Accepted, time = 15 ms, mem = 512 KiB, score = 100
#include<cstdio> #include<algorithm> #include<cstdlib> #include<cstring> int main() { int ch[101]; int sh[101]; memset(sh,0,sizeof(sh)); int n; scanf("%d",&n); for(int i=0; i<n; i++) scanf("%d",&ch[i]); std::sort(ch,ch+n); int count=0; 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(ch[i]+ch[j] == ch[k]&&sh[k] == 0) { sh[k] = 1; count++; } printf("%d\n",count); return 0 ; }
-
02016-12-22 18:59:57@
分站
给洛谷投食
应用搜索
Alextokc
P2141 珠心算测验
1.6K
通过
5K
提交
题目提供者soha
标签 NOIp普及组 2014 云端评测
难度 普及-
提交 讨论 题解最新讨论
80分,不知道哪里出问题了
怎么还有被加数之说……?!
最后一个超时
pj第一题60+查不出错的的戳…
忘记去重了
评测结果:Accepted
得分: 100
提交时间:2016-12-22 18:58 耗时:0ms
内存:11878kb
编译信息编译成功
没有编译信息
分点信息(鼠标移到方块上有详细信息)#1
AC
0ms/11878kB#2
AC
0ms/11878kB#3
AC
0ms/11878kB#4
AC
0ms/11878kB#5
AC
0ms/11878kB#6
AC
0ms/11878kB#7
AC
0ms/11878kB
#8
AC
0ms/11878kB#9
AC
0ms/11878kB#10
AC
0ms/11878kB
测试数据下载因为该记录状态(AC或CE等)不能提供数据下载。
洛谷免费提供该记录第一个非AC的输入输出数据下载;部分题目因为版权等原因,不开放数据下载。24小时内,蓝名允许下载一次(一对输入及输出算一次),绿名2次,橙名3次,红名4次。灰名暂时不能下载数据。
源代码
#include <bits/stdc++.h>
using namespace std;
typedef long long int64;int x[109];
int main(){
ios_base::sync_with_stdio(false);
int n , flag , beta = 0;
cin >> n;
for (int i=1;i<=n;++i) cin >> x[i];
sort(x+1,x+1+n);
for (int i=1;i<=n;++i){
flag=0;
for (int j=1;j<i;++j){
for (int k=1;k<j;++k){
if (x[j]+x[k]==x[i] && x[j]!=x[k]) {
flag=1;break;
}
}
}
beta+=flag;
}
cout << beta << endl;
return 0;
} -
02016-11-25 21:55:04@
枚举
c++
#include<cstdio>
#include<algorithm>
int num[150];
int main()
{
int n,ans=0;scanf("%d",&n);
for (int i=1;i<=n;++i)
scanf("%d",num+i);
std::sort(num+1,num+n+1);
for (int k=3;k<=n;++k)
{
int f=1;
for (int i=k-2;f&&i;--i)
for (int j=k-1;f&&j>i;--j)
if (num[i]+num[j]==num[k])
{f=0;++ans;}
}
printf("%d\n",ans);
return 0;
}
-
02016-11-21 01:12:55@
#include <iostream> #include <cmath> #include <string.h> #include <stdlib.h> #include <stdio.h> #include <climits> #include <algorithm> #include <set> using namespace std; int main() { int n; cin>>n; int sum=0; int a[105]; memset(a,0,sizeof(a)); for(int i=1; i<=n; i++){cin>>a[i];} set<int> s; for(int i=1; i<=n; i++) { for(int j=1; j<=n&&j!=i; j++){s.insert(a[i]+a[j]);} } for(int i=1; i<=n; i++) { if(s.find(a[i])!=s.end()){sum++;} } cout<<sum; return 0; }
信息
- ID
- 1911
- 难度
- 6
- 分类
- (无)
- 标签
- 递交数
- 17097
- 已通过
- 4518
- 通过率
- 26%
- 被复制
- 28
- 上传者