• 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;
    }
  • 相关阅读:
    十六进制转十进制
    十进制转十六进制
    历届试题 高僧斗法
    历届试题 错误票据
    历届试题 大臣的旅费
    历届试题 九宫重排/八数码问题
    Skip the Class
    历届试题 剪格子
    leetcode 337. House Robber III
    猿辅导 2019年 校招提前批笔试
  • 原文地址:https://www.cnblogs.com/moqitianliang/p/4692558.html
Copyright © 2020-2023  润新知