题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2015
方法:无,瞎搞
思路:很长时间刷题的时候这道题就没过,今天总算是过了,题目不复杂,就是下标让人头疼,另外还要注意输出的格式。
难点:输出格式
#include <iostream>
using namespace std;
int main()
{
int n,m,num[110],head;
while(cin>>n>>m)
{
for(int i = 1;i <= 100;i++)
{
num[i] = 2*i;
}
head = 1;
int left = n%m;
while(n >= m)
{
int sum = 0,i;
for(i = head;i <= head+m-1;i++)
{
sum += num[i];
}
if(i == m+1)
cout<<sum/m;
else
cout<<" "<<sum/m;
head += m;
n -= m;
}
if(left!=0)
{
int sum2 = 0;
for(int i = head;i <= head+left-1;i++)
{
sum2 += num[i];
}
cout<<" "<<sum2/left<<endl;
}
else
cout<<endl;
}
}