跨届大侠
- 积分
- 6167
- 威望
- 3955
- 贡献
- 1878
- 兑换币
- 597
- 注册时间
- 2014-5-20
- 在线时间
- 167 小时
- 毕业学校
- 西北民族大学
|
#include<stdio.h>
int FinalLine=10,BasedLine=0;
int AvaliableLines,MiddleLine;
int SumX,SumY;
int Path[10];
int AverageX,AverageY,SumUp,SumDown,B,A;
void main()
{
int i;
for(i=0;i<10;i++)
scanf("%d",&Path[i]);
AvaliableLines=FinalLine-BasedLine; // FinalLine为终止行,
MiddleLine=(BasedLine+FinalLine)/2;
SumX=0;
SumY=0;
for(i=BasedLine;i<FinalLine;i++)
{
SumX+=i;
SumY+=Path[i];
}
AverageX=SumX/AvaliableLines;
AverageY=SumY/AvaliableLines;
SumUp=0;
SumDown=0;
for(i=BasedLine;i<FinalLine;i++)
{
SumUp+=(Path[i]-AverageY)*(i-AverageX);
SumDown+=(i-AverageX)*(i-AverageX);
}
if(SumDown==0) B=0;
else B=(int)(SumUp/SumDown);
A=(SumY-B*SumX)/AvaliableLines;
printf("%d %d",A,B);
}
|
|