简单的数论题目zju1652(不知道有没有AC,因为我在zju上没帐号)PKU上没有
2006-07-22 17:53
513 查看
代码是在新校区机房写的,关键是找出递归公式!
/*
Count the Regions
--------------------------------------------------------------------------------
Time limit: 1 Seconds Memory limit: 32768K
Total Submit: 318 Accepted Submit: 207
--------------------------------------------------------------------------------
What's the maximum number of regions definable by N zig-zag lines, each of which consists of two parallel infinite half-lines joined by a straight line segment?
Here is an example of 2 zig-zag lines yield 12 regions at the most.
Input
The input consists of a sequence of N (<= 10000), which is the number of the zig-zag lines, one per line.
Output
For each N, you should output the number of the maximum regions.
Sample Input
1
2
Sample Output
2
12
*/
#include "stdio.h"
#include "vector"
using namespace std;
int main()
{
int n,i,j;
vector<int> p;
scanf("%d",&n);
if(n<0||n>10000)
return 0;
p.push_back(2);
for(i=1;i<n;i++){
j=p.back()+9*i+1;
p.pop_back();
p.push_back(j);
}
j=p.back();
printf("%d/n",j);
return 0;
}
/*
Count the Regions
--------------------------------------------------------------------------------
Time limit: 1 Seconds Memory limit: 32768K
Total Submit: 318 Accepted Submit: 207
--------------------------------------------------------------------------------
What's the maximum number of regions definable by N zig-zag lines, each of which consists of two parallel infinite half-lines joined by a straight line segment?
Here is an example of 2 zig-zag lines yield 12 regions at the most.
Input
The input consists of a sequence of N (<= 10000), which is the number of the zig-zag lines, one per line.
Output
For each N, you should output the number of the maximum regions.
Sample Input
1
2
Sample Output
2
12
*/
#include "stdio.h"
#include "vector"
using namespace std;
int main()
{
int n,i,j;
vector<int> p;
scanf("%d",&n);
if(n<0||n>10000)
return 0;
p.push_back(2);
for(i=1;i<n;i++){
j=p.back()+9*i+1;
p.pop_back();
p.push_back(j);
}
j=p.back();
printf("%d/n",j);
return 0;
}
相关文章推荐
- 因为这两天比较忙,所以没有及时把要发表的东西写来.废话少说:我前面把两个简单的滚动说了下.接下来介绍第三种集合循环滚动.
- pku,zju题目分类
- ural, pku, zju online judger 题目分类[转载]
- AC题目简解-数论
- C语言字符串库函数的实现也是笔试题常考的题目,以下代码没有严格测试,只是简单的实现:
- 2016华为软件精英挑战赛初赛题目,个人分析与代码,尚未测试代码,因为没有judge系统啊!
- 问题 E : 坤哥的难题 (题目本来觉得很难,但是数据很水,居然简单的for就AC)
- 呵呵,刚刚水了一道题目。简单题就要水!PKU2895,精简到70行代码!
- 使用了博客园的备份后得到一个xml文件,不知道有没有css或者xslt文件可以在本地阅读文章,在网上找了半天也没有找到解决办法,难道要自己写?
- 解析“一道考遍东北三省和青岛没有一人做出来的简单题目 ”
- p1984_因为没有仔细看样例导致题目理解错误
- ZOJ 1005题解 这题数据有点问题没有按照题目要求也能被AC,我无语了。
- 因为有点事情,好久没有做usaco的题目了,今天从第五章开始就绪搞
- PKU 2769 Reduced ID Numbers(简单数论)
- 补上以前没有AC的PKU儿八死三
- HDOJ,数论简单入门题目,杭电1262,寻找素数对
- 因为业务需要,用nodejs写了一个css解析器,因为是基础库,想开源,不知道有没有人需要。
- AC题目简解-数论
- ural pku Zju 题目分类
- zz 关于一个flex 加 SFS的配置 但是我自己没有测试出来 那个SFSEvent报错 不知道有没有人能解决