题解

173 条题解

  • 0
    @ 2014-12-14 18:45:42

    水爆了。。
    var n,i,j,k,sum:longint;
    a,b:array[1..100] of longint;
    begin
    read(n);
    fillchar(b,sizeof(b),0);
    for i:=1 to n do read(a[i]);
    for i:=1 to n do
    for j:=i+1 to n do
    for k:=1 to n do
    if (a[i]<>a[j]) and (a[i]+a[j]=a[k]) then b[k]:=1;
    for i:=1 to n do inc(sum,b[i]);
    writeln(sum);
    end.

  • 0
    @ 2014-12-13 19:25:57

    大水题。。。。

  • 0
    @ 2014-11-30 09:36:50

    var
    a:array[1..100] of longint;
    b:array[1..10000] of boolean;
    n,i,j,k,t:longint;
    begin
    readln(n);
    for i:=1 to n do
    read(a[i]);
    for i:=1 to n do
    for j:=(i+1) to n do
    for k:=1 to n do

    if a[i]+a[j]=a[k] then b[a[k]]:=true;
    for i:=1 to n do
    if b[a[i]]=true then inc(t);
    writeln(t);
    end.

  • 0
    @ 2014-11-29 08:34:41

    #include<iostream>
    #include<algorithm>
    #include<math.h>
    #include<string.h>
    #include<stdio.h>
    #include<stdlib.h>
    using namespace std;
    bool cmp(int a,int b)
    {
    if(a>b)return 1;
    return 0;
    }
    int a[10000];
    int main()
    {
    int n,ans=0;
    cin>>n;
    for(int i=0;i<n;i++)
    cin>>a[i];
    sort(a,a+n,cmp);
    for(int i=0;i<n-1;i++)
    {
    int y=i,z=n;
    while(a[y+1]!=a[z-1]&&a[y+1]!=0&&a[z-1]!=0)
    {
    if(a[i]==a[y+1]+a[z-1]){
    ans++;

    break;
    }
    else if(a[i]>a[y+1]+a[z-1])z--;
    else if(a[i]<a[y+1]+a[z-1])y++;

    }
    }
    cout<<ans<<endl;
    system("pause");
    return 0;
    }

  • 0
    @ 2014-11-26 13:18:29

    var n,i,j,k,z:longint;
    c:array[1..100] of longint;
    d:array[1..100] of longint;
    begin
    readln(n);
    for i:=1 to n do read(c[i]);
    fillchar(d,sizeof(d),0);
    for i:=1 to n do
    for j:=i+1 to n do
    for k:=1 to n do
    if (c[i]+c[j]=c[k]) then inc(d[k]);
    for i:=1 to n do
    if d[i]>0 then inc(z);
    writeln(z);
    end.

  • 0
    @ 2014-11-24 16:54:54

    var a,b,c,d,e:longint;
    k,j:array[1..100]of longint;
    begin
    read(a);
    for b:=1 to a do
    read(k[b]);
    for b:=1 to a do
    for c:=1 to a do
    for d:=c+1 to a do
    if k[c]+k[d]=k[b] then begin j[b]:=1; break; break; end;
    for b:=1 to a do
    if j[b]=1 then inc(e);
    writeln(e);
    end.

  • -1
    @ 2018-09-06 12:37:32

    看看下一张

  • -1
    @ 2018-08-11 10:55:20

    #include <cstdio> // 这题可以用桶排序的思想
    #include <iostream>
    using namespace std;
    int t[20005], g[20005]; // t是桶,t[i]表示的值为i的数在集合中两两相加的次数;g[i]表示值为i的数是否在集合中,1为在,0为不在
    int main(){
    int n;
    int sum = 0, a[101];
    scanf("%d",&n);
    for(int i = 1; i <= n; i++){
    scanf("%d",&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 <= 20002; i++){
    if(t[i] > 0 && g[i]) //判断是否满足条件
    sum++;
    }
    printf("%d",sum);
    return 0;

    }

  • -1
    @ 2018-04-23 20:29:17

    import java.util.Scanner;

    public class Main {

    public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int a = in.nextInt();
    int sum[] = new int[a];
    boolean num[] = new boolean[a];
    int x = 0, y = 0, d = 0;
    for (int i = 0; i < sum.length; i++)
    sum[i] = in.nextInt();
    for (int i = 0; i < sum.length; i++) {
    for (int j = i; j < sum.length; j++) {
    for (int z = 0; z < sum.length; z++) {
    if (sum[i] + sum[j] == sum[z] && i != j && i != z && j != z&&(!num[z])) {
    num[z]=true;
    y++;
    }
    }
    }
    }
    System.out.println(y);
    }
    }

  • -1
    @ 2018-04-15 19:55:51

    #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;
    return 0;
    }

  • -1
    @ 2018-04-08 19:52:25

    有没有python做的

  • -1
    @ 2018-03-14 23:42:48

    简单的模拟 加一次排序可以减少重复 代码如下

    #include <cstdio>
    #include <algorithm>
    using namespace std;
    int n, ans;
    int a[101];
    bool v[101];
    int main(){
        int n;
        scanf("%d", &n);
        for(int i = 1; i <= n; ++ i)
            scanf("%d", &a[i]);
        sort( a + 1, a + 1 + n);
        for(int i = 1; i <= n - 2; ++ i)
        for(int j = i + 1; j <= n - 1; ++ j)
        for(int k = j + 1; k <= n; ++ k)
        if(a[i] + a[j] == a[k] && v[k] == 0){
            ans ++;
            v[k] = 1;
        }
        printf("%d", ans);
        return 0;
    }
    
  • -1
    @ 2018-03-11 00:03:05

    #include<stdio.h>
    int main()
    {
    int n,i,j,k,flag;
    scanf ("%d",&n);
    int a[n],count=0;
    for (i=0;i<n;i++)
    {
    scanf ("%d",&a[i]);
    }
    for (i=0;i<n;i++)
    {
    flag=0;
    for (j=0;j<n;j++)
    {
    if (j!=i)
    for (k=0;k<n;k++)
    {
    if (k!=j&&k!=i)
    {
    if (a[i]==a[k]+a[j])
    {
    count++;
    flag=1;
    }
    }
    if (flag==1)
    break;
    }
    if (flag==1)
    break;
    }
    }
    printf ("%d",count);
    }

  • -1
    @ 2018-02-28 15:30:46

    #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;
    }

  • -1
    @ 2017-11-26 23:43:43

    #include <stdio.h>
    #include <iostream>
    #include <string.h>
    using namespace std;
    int a[105];
    int b[105];
    int m;
    void input(int n)
    {
    int i;
    for(i=1;i<=n;i++)
    {
    cin>>a[i];
    }

    }
    void sort(int n){
    int i;
    int j;
    int tmp;
    for(i=1;i<=n-1;i++)
    for(j=1;j<=n-i;j++)
    {
    if(a[j]>a[j+1])
    {
    tmp=a[j];
    a[j]=a[j+1];
    a[j+1]=tmp;

    }
    }
    }
    int look(int aim,int left,int right){
    int mid=(left+right)/2;
    while(left<right)
    {

    if(a[mid]>aim)
    {
    right=mid;
    mid=(right+left)/2;
    continue;
    }

    if(a[mid]<aim)
    {

    left=mid+1;
    mid=(right+left)/2;
    continue;

    }
    // cout<<"mid="<<mid<<endl;
    if(a[mid]==aim )
    return 1;
    }
    return 0;
    }
    int main()
    {
    int i;
    int j;
    int n;
    int aim;
    int num=0;
    cin>>n;
    ///cout<<"n="<<n<<endl;
    input(n);
    sort(n);///输入以及排序OK;01
    memset(b,1,sizeof(b));
    ///cout<<"数组a=";
    ///for(i=1;i<=n;i++)
    ///{
    /// cout<<a[i]<<',';
    /// }
    ///cout<<endl;
    for(i=1;i<=n;i++)
    for(j=i+1;j<=n;j++)
    {
    if(b[j]==0)
    continue;
    aim=a[j]-a[i];
    ///cout<<"aim="<<aim<<endl;
    if((a[i]==aim) ||(aim<a[i]))
    continue;
    else
    {
    if(look(aim,i,j))
    {
    /// cout<<"true"<<endl;
    num++;
    /// cout<<"aim="<<aim<<endl;
    /// cout<<"num="<<num<<endl;
    b[j]=0;
    }
    }

    }

    cout<<num<<endl;
    return 0;
    PS:想得有点麻烦了。。。

  • -1
    @ 2017-11-19 11:36:24

    #include<iostream>
    #include<cstdio>
    using namespace std;
    bool c[100000]={false},ct[100000]={false};
    int in[1000]={0};
    int main()
    {
    int n,ans=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
    cin>>in[i];
    c[in[i]]=true;
    }
    for(int i=1;i<=n;i++)
    {
    for(int j=1;j<=n;j++)
    {
    if(j==i)
    {
    continue;
    }
    if(c[in[i]+in[j]]==true)
    {
    ct[in[i]+in[j]]=true;
    }
    }
    }
    for(int i=0;i<100000;i++)
    {
    if(ct[i]==true)
    {
    ans++;
    }
    }
    cout<<ans;
    return 0;
    }

  • -1
    @ 2017-09-09 19:19:07
    //居然错了好几次。。。自己真的是智商下线了lol
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <iostream>
    
    using namespace std;
    
    int n, num[105], revans[100005], cnt;
    
    int main() {
        cin >> n;
        for (int i = 1; i <= n; i++) cin >> num[i];
        for (int i = 1; i <= n; i++) {
            for (int j = i + 1; j <= n; j++) {
                revans[num[i] + num[j]] += 1;
            }
        }
        for (int i = 1; i <= n; i++) {
            cnt += (revans[num[i]] > 0);
        }
        cout << cnt << endl;
        return 0;
    }
    
    
  • -1
    @ 2016-05-15 14:32:17

    FUCK YOUR DICK SHIT FUCK DICK BALL ALSO MOTHER
    GO AND EAT SHIT BITCH
    FUCK YOUR DICK SHIT FUCK DICK BALL ALSO MOTHER
    GO AND EAT SHIT BITCH
    FUCK YOUR DICK SHIT FUCK DICK BALL ALSO MOTHER
    GO AND EAT SHIT BITCH
    氮碘硫氢碘锑

  • -2
    @ 2017-06-21 11:16:44

    #include <iostream>
    #include <algorithm>
    #include <vector>

    using namespace std;

    int main(){
    int n=0,res=0,num=0,tmp=0;
    cin>>n;
    vector<int> arr;
    bool vis[10001]={0};
    while(n--){
    cin>>num;
    vis[num]=1;
    arr.push_back(num);
    }
    sort(arr.begin(),arr.end());
    for(int i=arr.size()-1;i>=0;--i){
    for(int j=i-1;j>=0;--j){
    tmp=arr[i]-arr[j];
    if(tmp!=arr[i]&&tmp!=arr[j]&&vis[tmp]){
    ++res;
    break;
    }
    }
    }
    cout<<res;
    system("pause");
    return 0;
    }

  • -2
    @ 2017-06-06 10:26:51

    #include<stdio.h>
    #include<stdlib.h>
    int main(void)
    {
    int a,b,c,d,e=0,n;
    scanf("%d",&n);
    int *ar;
    ar=(int *)malloc(sizeof(int)*n);
    for(a=0;a<n;a++)
    scanf("%d",&ar[a]);
    for(a=0;a<n;a++)
    {
    for(b=0;b<n;b++)
    {
    if(ar[a]<=ar[b])
    continue;
    for(c=0;c<n;c++)
    {
    if(ar[a]<=ar[c]||b==c)
    continue;
    d=ar[a]-ar[b]-ar[c];
    if(d==0)
    {
    e++;
    break;
    }
    }
    if(d==0)
    break;
    }
    }
    printf("%d\n",e);

    return 0;
    }

信息

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