| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 924 人关注过本帖
标题:这个程序居然没有结果??求助!!
只看楼主 加入收藏
tianqiao
Rank: 2
等 级:论坛游民
帖 子:80
专家分:55
注 册:2011-9-21
结帖率:85.71%
收藏
已结贴  问题点数:10 回复次数:5 
这个程序居然没有结果??求助!!
先看题目;
把6个互不相等的正整数a、b、c、d、e、f分成两组,若这两个数组具有以下两个相等特性:  a+b+c=d+e+f=s 且 a^2+b^2+c^2=d^2+e^2+f^2=s2,人们把这类数组(a,b,c)与(d,e,f)称为神秘3元数组。

设计程序求出给定s的所有神秘3元数组(约定a<b<c, d<e<f, a<d)。例如,(1,5,6)与(2,3,7)就是s=12的神秘3元数组:1+5+6=2+3+7=12;1^2+5^2+6^2=2^2+3^2+7^2=62。


Input
输入一个正整数s。


Output
输出满足条件的所有神秘3元数组。


Sample Input
18

Sample Output
(1,7,10):(2,5,11)
(1,8,9):(3,4,11)
(2,7,9):(3,5,10)
(3,7,8):(4,5,9)
先不考虑输出格式,我的程序不出现结果啊:
#include<stdio.h>
int main()
{
    int sum,i,j,k,d,s[100][3],jj,other,x1,x2,x3,x4,x5,x6;
    scanf("%d",&sum);
    d=sum/3;
    for(i=1;i<d;i++){
        for(j=i+1;j<sum;j++){
            for(k=j+1;k<sum;k++){
                if((i+j+k)==sum)
                {
                    s[i-1][0]=i;s[i-1][1]=j;s[i-1][2]=k;
                }
            }
        }
    }                                                          /*这一步之前没有问题*/
    for(jj=0;jj<20;jj++){
        for(other=jj+1;other<20;other++){
            x1=s[jj][0]*s[jj][0];x2=s[jj][1]*s[jj][1];x3=s[jj][2]*s[jj][2];
            x4=s[other][0]*s[other][0];x5=s[other][1]*s[other][1];x6=s[other][2]*s[other][2];
            if((x1+x2+x3)==(x4+x5+x6)&&x1<x4){
            printf("%d,%d,%d,%d,%d,%d\n",x1,x2,x3,x4,x5,x6);
        }
    }
    }                                        /*这个循环看起来,没问题啊;*/
    return 0;
}
求高手::
搜索更多相关主题的帖子: 设计程序 正整数 
2011-11-12 10:04
beyondyf
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:3282
专家分:12654
注 册:2008-1-21
收藏
得分:0 
原题在哪儿?
s的定义域是多少?

重剑无锋,大巧不工
2011-11-12 11:01
tianqiao
Rank: 2
等 级:论坛游民
帖 子:80
专家分:55
注 册:2011-9-21
收藏
得分:0 
回复 2楼 beyondyf
这里面第一个s是给定的数,第二个s2对题目没有影响,
题目来源是浙江工商大学acm平台problemset第11页.
谢谢
2011-11-12 11:27
beyondyf
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:3282
专家分:12654
注 册:2008-1-21
收藏
得分:10 
唉,题目描述的太含糊。没有s的范围,这往往是水题的标志。下面的代码AC,但它能计算的范围只有 s <= 112
程序代码:
#include<stdio.h>
int main()
{
    int s, s_3, a, b, c, t[10000][4], len, i, j;
    scanf("%d", &s);
    s_3 = s / 3;
    len = 0;
    for(a = 1; a <= s_3; a++)
    for(b = a + 1, c = s - a - b; b < c; b++, c--)
    {
        t[len][0] = a * a + b * b + c * c;
        t[len][1] = a;
        t[len][2] = b;
        t[len++][3] = c;
    }
    for(i = 0; i < len; i++)
    for(j = i + 1; j < len; j++)
    if(t[i][0] == t[j][0])
    printf("(%d,%d,%d):(%d,%d,%d)\n", t[i][1], t[i][2], t[i][3], t[j][1], t[j][2], t[j][3]);
    return 0;
}

重剑无锋,大巧不工
2011-11-12 11:47
tianqiao
Rank: 2
等 级:论坛游民
帖 子:80
专家分:55
注 册:2011-9-21
收藏
得分:0 
回复 4楼 beyondyf
谢谢高手,顺便问一下水题是什么意思,菜鸟做的题目吗???
2011-11-12 12:01
hahayezhe
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:湖南张家界
等 级:贵宾
威 望:24
帖 子:1386
专家分:6999
注 册:2010-3-8
收藏
得分:0 
#include <iostream>
using namespace std;
#include <list>
#include <vector>
#include <iterator>
#include <algorithm>
#include <functional>  
struct Data{
    __int32 m_I1;
    __int32 m_I2;
    __int32 m_I3;
    __int32 m_Multiply;
};
bool UDgreater ( Data &elem1, Data &elem2 )
{
    return elem1.m_Multiply > elem2.m_Multiply;
}
int main()
{
    __int32 _sum;
    cin>>_sum;
    //cout<<"\n";

    vector<Data> _data;
    __int32 _times = _sum/3;
    for(__int32 i=1;i<_times;i++){
        for(__int32 j=i+1;;j++){
            __int32 k = _sum- i-j;
            if(k<=j)
                break;
            else{
                Data d;
                d.m_I1 = i;
                d.m_I2 = j;
                d.m_I3 = k;
                d.m_Multiply = i*i+j*j+k*k;
                _data.push_back(d);
            }
        }
    }
   
    sort(_data.begin(),_data.end(),UDgreater);
    vector<Data>::iterator _iter1,_iter2;
    _iter1 = _iter2 = _data.begin();
    for(;_iter1!=_data.end();_iter1++){
        if((_iter1->m_Multiply == _iter2->m_Multiply) && (_iter1 != _iter2)){
            if((_iter1->m_I1!=_iter2->m_I1)&&(_iter1->m_I2!=_iter2->m_I2)&&(_iter1->m_I3!=_iter2->m_I3)){
                cout<<"("<<_iter1->m_I1<<"."<<_iter1->m_I2<<"."<<_iter1->m_I3<<")";
                cout<<"("<<_iter2->m_I1<<"."<<_iter2->m_I2<<"."<<_iter2->m_I3<<")"<<endl;
            }
        }
        else
            _iter2 = _iter1;
    }
    return 0;
}
2011-11-12 12:08
快速回复:这个程序居然没有结果??求助!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021159 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved