SGU - 135 - Drawing Lines (简单数学!)

SGU - 135

Drawing Lines

Time Limit: 250MS   Memory Limit: 4096KB   64bit IO Format: %I64d & %I64u

Submit Status

Description

Little Johnny likes to draw a lot. A few days ago he painted lots of straight lines on his sheet of paper. Then he counted in how many zones the sheet of paper was split by these lines. He noticed that this number is not always the same.
For instance, if he draws 2 lines, the sheet of paper could be split into 43 or even 2 (if the lines are identical) zones. Since he is a very curious kid, he would like to know which is
the maximum number of zones into which he can split the sheet of paper, if he draws N lines. The sheet of paper is to be considered a very large (=infinite) rectangle.

Input

The input file will contain an integer number: N (0<=N<=65535).

Output

You should output one integer: the maximum number of zones into which the sheet of paper can be split if Johnny draws N lines.

Sample Input #1

0

Sample Output #1

1

Sample Input #2

1

Sample Output #2

2

Author : Mugurel Ionut Andreica
Resource : SSU::Online Contester Fall Contest #2
Date : Fall 2002

Source

也是一个数学题,找规律的。。

规律:1,2,4,7,11,16......        a(n) = n*(n+1)/2+1;(n从0开始)

AC代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <cstdlib>
using namespace std;

int main()
{
	int n;
	scanf("%d", &n);
	printf("%d\n", (int)((long long)n*(n+1)/2+1));
	return 0;
} 
时间: 2024-08-11 05:43:44

SGU - 135 - Drawing Lines (简单数学!)的相关文章

SGU[135] Drawing Lines

Description 描述 Little Johnny likes to draw a lot. A few days ago he painted lots of straight lines on his sheet of paper. Then he counted in how many zones the sheet of paper was split by these lines. He noticed that this number is not always the sam

SGU - 123 - The sum (简单数学!)

SGU - 123 The sum Time Limit: 250MS   Memory Limit: 4096KB   64bit IO Format: %I64d & %I64u Submit Status Description Here is your second problem, keep calm and solve it . Nacci sequence of numbers is known to all : F1 = 1; F2 = 1; Fn+1 = Fn + Fn-1,

HDU 1018 Big Number (简单数学)

Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 25649    Accepted Submission(s): 11635 Problem Description In many applications very large integers numbers are required. Some of these

hdu 2200 Eddy&#39;s AC难题(简单数学。。)

题意: N个人,每个人AC的题数都不一样. Eddy想从中选出一部分人(或者全部)分成两组.必须满足第一组中的最小AC数大于第二组中的最大AC数. 问共有多少种不同的选择方案. 思路: 简单数学.. 代码: ll C(int n,int x){ ll ans=1; rep(i,1,x){ ans = ans*(n+1-i)/i; } return ans; } int main(){ int n; while(cin>>n){ ll ans = 0; rep(i,2,n){ ans += (C

编译器--简单数学表达式计算器

做了一个能够计算简单数学表达式值的小计算器,算不上是编译器,但用到了编译器的知识.最近在看一些编译器的东西,所以动手写这个最简单的计算器,既是对那些抽象的编译器知识有个形象的认识,也为后面添加复杂的东西--语句打下基础.此计算器是以<编译原理与实践>中实现的tiny编译器为参考写的,tiny是一个值得去研究的编译器,可以说是麻雀虽小,五脏俱全.从词法分析到代码生成都有,并且代码非常清晰易懂.我觉得想要了解编译器,可以从tiny入手,去将它跑起来并分析.废话不多说,开始记录这个小计算器. 先说下

【龙书笔记】用Python实现一个简单数学表达式从中缀到后缀语法的翻译器(采用递归下降分析法)

上篇笔记介绍了语法分析相关的一些基础概念,本篇笔记根据龙书第2.5节的内容实现一个针对简单表达式的后缀式语法翻译器Demo. 备注:原书中的demo是java实例,我给出的将是逻辑一致的Python版本的实现. 在简单后缀翻译器代码实现之前,还需要介绍几个基本概念. 1. 自顶向下分析法(top-down parsing) 顾名思义,top-down分析法的思路是推导产生式时,以产生式开始符号作为root节点,从上至下依次构建其子节点,最终构造出语法分析树.在具体实现时,它会把输入字符串从左到右

简单数学(组合数+求数列通项公式)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6467 看到这题,简单数学???对不起我给数学老师丢脸了! 这里解释一下第二步到第三步:假设n=3,第二步{1*C(1,1)+1*C(1,2)+1*C(1,3)+2*C(2,2)+2*C(2,3)+3*C(3,3)},第三步{1*C(1,1)+1*C(1,2)+2*C(2,2)+1*C(1,3)+2*C(2,3)+3*C(3,3)}.可以发现是相等的 之后最后一步就是组合数求和公式2^n. 之后便可以

Drawing Lines - SGU 135(简单递推)

求N条直线最多能把一个平面分成几部分. 代码如下: ============================================================================================================================== #include<stdio.h> #include<algorithm> #include<string.h> #include<vector> usin

SGU - 107 - 987654321 problem (简单数学!)

SGU - 107 987654321 problem Time Limit: 250MS   Memory Limit: 4096KB   64bit IO Format: %I64d & %I64u Submit Status Description For given number N you must output amount of N-digit numbers, such, that last digits of their square is equal to 987654321