62,621
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
void PrintTwo()
{
int nDist1(0),nDist2(0);
for ( int i = 0;i <= 1000;i++ )
{
for ( int j = i;j <= 1000-i;j++ )
{
int nFirst = 5*i;
int nCount = (3000-nFirst)/1000;
int nSecond = (j-i)*(2*(1+nCount)-1);
if ( nFirst+nSecond==2000 )
{
if ( j > nDist2 )
{
nDist1 = i;
nDist2 = j;
}
}
}
}
cout<<nDist1<<" "<<nDist2<<"\n";
}
void PrintThree()
{
int nDist1(0),nDist2(0),nDist3(0);
for ( int i = 0;i <= 1000;i++ )
{
for ( int j = i;j <= 1000-i;j++ )
{
for ( int k = j;k <= 1000 -k;k++ )
{
int nFirst = 5*i;
int nCount = (3000-nFirst)/1000;
int nSecond = (j-i)*(2*(1+nCount)-1);
nCount = (3000-nSecond)/1000;
int nThird = (k-j)*(2*(1+nCount)-1);
if ( nFirst+nSecond+nThird==2000 )
{
if ( k > nDist3 )
{
nDist1 = i;
nDist2 = j;
nDist3 = k;
}
}
}
}
}
cout<<nDist1<<" "<<nDist2<<" "<<nDist3<<"\n";
}
void main()
{
PrintTwo();
PrintThree();
}
200M 533M 1000M
-----A--------B-------终点
2000个 1000个 533个