UVA, 10079 Pizza Cutting

简单的一道数学题

题意:N刀能将平面分成多少块

思路:递推

0刀:1块

1刀:1+1块

2刀:1+1+2块

3刀:1+1+2+3块

……

N刀:1+1+2+3+……N块

即(1+N)*N/2 +1块

 

代码:

 1 #include <iostream>
 2 #include <cstdio>
 3 using namespace std;
 4 
 5 long long s;
 6 
 7 bool datecin()
 8 {
 9   if(scanf("%lld",&s)!=EOF)
10   {
11     if(s>=0)
12       return true;
13   return false;
14 }
15  return false;
16 }
17 
18 void showres()
19 {
20   printf("%lld\n",1+s*(s+1)/2);
21 }
22 int main()
23 {
24 
25 while(datecin())
26 {
27   showres();
28 }
29 return 0;
30 }
31 
32  
View Code

 

posted on 2016-04-10 08:37  八云紫是小loli  阅读(161)  评论(0编辑  收藏  举报

导航