UVA, 10079 Pizza Cutting
来源:互联网 发布:java用户数据权限 编辑:程序博客网 时间:2024/09/21 08:55
这个学期选了大大的算法课,渣旧表示生无可恋。。。但是已经励志这个学期做学霸了,自己选的课,含着泪也要上下去QAQ
When someone calls Ivan lazy, he claims that it is his intelligence that helps him to be so. If hisintelligence allows him to do something at less physical effort, why should he exert more? He alsoclaims that he always uses his brain and tries to do some work at less effort; this is not his laziness,rather this is his intellectual smartness.
Once Ivan was asked to cut a pizza into seven pieces to distribute itamong his friends. (Size of the pieces may not be the same. In fact, hispiece will be larger than the others.) He thought a bit, and came to theconclusion that he can cut it into seven pieces by only three straight cutsthrough the pizza with a pizza knife. Accordingly, he cut the pizza in thefollowing way (guess which one is Ivan’s piece):
One of his friends, who never believed in Ivan’s smartness, was startledat this intelligence. He thought, if Ivan can do it, why can’t my computer?So he tried to do a similar (but not exactly as Ivan’s, for Ivan will criticizehim for stealing his idea) job with his computer. He wrote a program thattook the number of straight cuts one makes through the pizza, and output a number representing themaximum number of pizza pieces it will produce.Your job here is to write a similar program. It is ensured that Ivan’s friend won’t criticize you fordoing the same job he did.
Input
The input file will contain a single integer N (0 ≤ N ≤ 210000000) in each line representing the numberof straight line cuts one makes through the pizza. A negative number terminates the input.
Output
Output the maximum number of pizza pieces the given number of cuts can produce. Each line shouldcontain only one output integer without any leading or trailing space.
Sample Input
5
10
-100
Sample Output
16
56
··················································································································································································································
题目:用刀切皮萨,问n刀最多能切成几块
嗯。。。一点一点慢慢推吧
刀数 所切块数
f(0) 0 1
f(1) 1 1+2
f(2) 2 1+2+2 f(2)=f(2-1)+2
f(3) 3 1+2+2+3 f(3)=f(3-1)+3
f(4) 4 1+2+2+3+4
: :
f(n-1) n-1
f(n) n f(n)=f(n-1)+n
f(n+1) n+1 f(n+1)=f(n)+n+1
可得递推式 f(n)=n*(n+1)/2+1
然后就是套公式算啦,这道题还能安慰安慰我(哭
#include <iostream>#include<cstdio>using namespace std;int main(){ long long N; long long F; while(scanf("%I64d",&N)&&N>=0) { F=(N+1)*N/2+1; printf("%d\n",&F); } return 0;}
- UVA 10079 Pizza Cutting
- UVa 10079 - Pizza Cutting
- UVA 10079 Pizza Cutting
- uva 10079 - Pizza Cutting
- UVa 10079 - Pizza Cutting
- uva 10079 - Pizza Cutting
- UVA 10079 Pizza Cutting
- UVA 10079 - Pizza Cutting
- UVA, 10079 Pizza Cutting
- UVA 10079 Pizza Cutting(数论)
- UVa 10079 Pizza Cutting (water ver.)
- 10079 - Pizza Cutting
- Uva 10079 - Pizza Cutting 解题报告(递推)
- UVA - 10079 Pizza Cutting (直线划分平面问题,公式解决)
- UVA10079 - Pizza Cutting(数论)
- 省赛AK练习赛之Pizza Cutting
- UVA 11704 - Caper pizza
- UVa 565 - Pizza Anyone?
- Android HAL实例解析
- iOS苹果开发网址汇总
- HBase入门篇2-Java操作HBase例子
- main函数
- 改序列号增幅
- UVA, 10079 Pizza Cutting
- 图解Android View的scrollTo(),scrollBy(),getScrollX(), getScrollY()
- iOS 程序中集成iConsole 在客户端中查看控制台的日志
- Overload和Override的区别
- java String 之字节码解析
- 51Nod 1298 圆与三角形
- Google推荐的图片加载库Glide介绍
- PAT (Advanced Level) Practise 1081 Rational Sum (20)
- java面试题