点点滴滴”

导航

F - Cookies Piles

Description

The kids in my son's kindergarten made Christmas cookies with their teacher, and piled them up in columns.  They then arranged the columns so that the tops of the columns, going from shortest to tallest, were in a nice straight ramp.  The cookies were all of uniform size.  Given that there were A cookies in the shortest pile, that the difference in height between any two adjacent piles was D cookies, and that there were N piles, can you write a program to figure out how many cookies there were in total?
 
INPUT
The first line contains the number of test cases T. T lines follow, one corresponding to each test case, containing 3 integers : N, A and D.
 
OUTPUT
Output T lines, each line containing the required answer for the corresponding test case.
 
CONSTRAINTS
T <= 100
1 <= N, A, D <=100
 
SAMPLE INPUT
3
1 1 1
3 5 6
2 1 2
 
SAMPLE OUTPUT
1
33
4
 
EXPLANATION
In the second test case the sequence is: 5, 11, 17 whose sum is 33.

 

题意: n   a   d   大概就是n个盘子  默认从小到大排序   最小的里面放了a个东西   从最小到最大一次增加d个物品     求全部盘子里的全部物品

         5+(5+6)+((5+6)+6)   ==   33

 

 #include <iostream>
 #include <string.h>
 #include <stdio.h>

 using namespace std;

 int main()
 {
     int n,a,d;
     int t;
     scanf("%d",&t);
     while(t--)
     {
         scanf("%d%d%d",&n,&a,&d);
         int sum=0;
         sum+=(a*n);
         for(int i=0;i<n;i++)
         {
             sum+=d*i;
         }
         printf("%d\n",sum);
     }
     return 0;
 }

 

posted on 2014-08-20 11:19  点点滴滴”  阅读(192)  评论(0编辑  收藏  举报