sgu 135 Drawing Lines

题意:画n条线最多将平面分成多少块?

画线的时候,尽量与原有的先相交,且不经过原先的交点,这样能新生成最多块。如果原先有a条线,这样切能产生a+1块。最开始有1块,线有0条。找规律发现一条在0条基础上+1,2条在1条基础上+2,3条在2条基础上+3.n条就是1+一个等差n项和。

#pragma comment(linker,"/STACK:1024000000,1024000000")
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <cassert>
#include <list>
#define mkp make_pair 
using namespace std;
const double EPS=1e-8;
const int SZ=33,INF=0x7FFFFFFF;
const long long mod=19999997;
typedef long long lon;

int main()
{
    std::ios::sync_with_stdio(0);
    //freopen("d:\\1.txt","r",stdin);
    lon casenum;
    //cin>>casenum;
    //scanf("%d",&casenum);
    //for(lon time=1;time<=casenum;++time)
    //for(lon time=1;cin>>n;++time)
    {
        lon n;
        cin>>n;
        cout<<1+(n*(n+1)/2)<<endl;
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/gaudar/p/9767603.html
sgu
今日推荐