Pizza Cutting

              Pizza Cutting

When someone calls Ivan lazy, he claims that it is his intelligence that helps him to be so. If his
intelligence allows him to do something at less physical effort, why should he exert more? He also
claims 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 it
among his friends. (Size of the pieces may not be the same. In fact, his
piece will be larger than the others.) He thought a bit, and came to the
conclusion that he can cut it into seven pieces by only three straight cuts
through the pizza with a pizza knife. Accordingly, he cut the pizza in the
following way (guess which one is Ivan’s piece):
One of his friends, who never believed in Ivan’s smartness, was startled
at 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 criticize
him for stealing his idea) job with his computer. He wrote a program that
took the number of straight cuts one makes through the pizza, and output a number representing the
maximum 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 for
doing the same job he did.
Input
The input file will contain a single integer N (0 ≤ N ≤ 210000000) in each line representing the number
of 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 should
contain only one output integer without any leading or trailing space.

Sample Input
5
10
-100

Sample Output

16
56

题意:就是给你一个数,然后用n条线最多可把一个披萨(平面)分成几块

tip:怒送好几次WA啊,首先0条线-》一块。。。

  然后long long 有木有啊,有木有啊。。。

#include<iostream>
#define ll long long

using namespace std;

ll a[210000005];

int main()
{
    a[0]=1;
    a[1]=2;
    for(int i=2;i<=210000005;i++)
        a[i]=a[i-1]+i;

    int n;
    while(cin>>n)
    {
        if(n>=0)
            cout<<a[n]<<endl;
        else
            break;
    }
    return 0;
}
时间: 2024-08-02 11:23:41

Pizza Cutting的相关文章

10079 - Pizza Cutting

点击打开链接 题意:用n刀可以切出最多块的Pizza. 思路:线段相交越多,所分成的区域越多.每多一刀,就让这刀与之前的全部相交,即为最大值.最后有公式的:n * (n + 1) / 2 + 1 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; typedef

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块 代码: #include <iostream>#include <cstdio>using namespace std; long long s; bool datecin(){ if(scanf("%lld",&s)!=EOF) { if(s>=0)

UVA题目分类

题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics 10300 - Ecological Premium 458 - The Decoder 494 - Kindergarten Counting Game 414 - Machined Surfaces 490 - Rotating Sentences 445 - Marvelous Mazes

《算法竞赛入门经典——训练指南》第二章题库

UVa特别题库 UVa网站专门为本书设立的分类题库配合,方便读者提交: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=442 注意,下面注有"extra"的习题并没有在书中出现,但在上面的特别题库中有,属于附加习题. 基础练习 (Basic Problems) UVa11388 GCD LCM UVa11889 Benefit UVa10943 How do y

UVA - 10003 —— Cutting Sticks

很基础的一道区间DP :) #include <cstdio> #include <iostream> #define INF 0x3f3f3f3f using namespace std; int c[1005]; int dp[1005][1005]; int main () { int l, n; while(scanf("%d", &l)!=EOF && l) { scanf("%d", &n); fo

uva 10003 Cutting Sticks 简单区间dp

// uva 10003 Cutting Sticks 区间dp // 经典的区间dp // dp(i,j)表示切割小木棍i-j所需要的最小花费 // 则状态转移为dp(i,j) = min{dp(i,k) + dp(k,j) + a[j]-a[i]) // 其中k>i && k<j // a[j] - a[i] 为第一刀切割的代价 // a[0] = 0,a[n+1] = L; // dp数组初始化的时候dp[i][i+1]的值为 0,这表示 // 每一段都已经是切割了的,不

UVa 10003 (可用四边形不等式优化) Cutting Sticks

题意: 有一个长为L的木棍,木棍中间有n个切点.每次切割的费用为当前木棍的长度.求切割木棍的最小费用. 分析: d(i, j)表示切割第i个切点到第j个切点这段所需的最小费用.则有d(i, j) = min{d(i, k) + d(k, j)} + a[j] - a[i]; ( i < k < j ) 最后一项是第一刀的费用. 时间复杂度为O(n3) 最后还要注意一下输出格式中整数后面还要加一个句点. 1 //#define LOCAL 2 #include <iostream>

完美pizza,由我做主

参考:http://blog.sina.com.cn/s/blog_4a5089ff0100a6kd.html 制作过程:1.把制作pizza面饼的所有配料揉成面团,使劲揉,揉到面团变得十分劲道,抻开面团,面团能形成一张比较薄的薄膜(扩展阶段),就可以了.把面团放在26度左右的环境下,盖上保鲜膜,发酵到变成2倍大(夏天放在室温就可以).(关于面团的揉面发酵,请参考手工揉面发酵步骤图)2.面团发酵的时候,可以准备其他材料.把火腿.青椒切成丁,金枪鱼罐头滤去汁液.3.马苏里拉芝士刨成丝.4.约需要1

UVa10003 Cutting Sticks

考虑d(i,j)表示切割点i到j这段距离的最小花费,于是d(i,j)=min(d(i,k)+d(k,j))+a[j]-a[i] ,其中j<k<i,边界条件d(i,i)=d(i,i+1)=0,最终求d(0,n+1),复杂度o(n^3),可采用记忆化搜索. /*----UVa10003 Cutting Sticks 设d(i,j)为切割木棍(i,j)的最小费用,则d(i,j)=a[j]-a[i]+min{d(i,k)+d(k,j)} i<k<=j;最终求d(0,n+1) 为了方便,可以