HDU 1556 Color the ball【算法的优化】
/*
解题思路:每次仅仅求解一開始的第一个数字,让第一个数字加一,最后的一个数字的后面一个数减一。我们能够想想,最后加的时候,就是加上前面一个数出现的次数和自己本身出现的次数。
解题人:lingnichong
解题时间:2014-10-25 10:30:46
解题体会:因为測试区间非常大,所以此题非常easy超时
*/
Color the ball
当N = 0,输入结束。
3
1 1
2 2
3 3
3
1 1
1 2
1 3
0
1 1 1
3 2 1
#include<stdio.h>
#include<string.h>
#define MAXN 100000+10
int arr[MAXN];
int main()
{
int N,i,j;
int a,b,t,m;
while(scanf("%d",&N),N)
{
m=0;
memset(arr,0,sizeof(arr));
for(i=0;i<N;i++)
{
scanf("%d%d",&a,&b);
arr[a]++,arr[b+1]--;
}
for(i=1;i<N;i++)
{
m+=arr[i];
printf("%d ",m);
}
printf("%d\n",m+arr[N]);
}
return 0;
}
HDU 1556 Color the ball【算法的优化】的更多相关文章
- hdu 1556:Color the ball(第二类树状数组 —— 区间更新,点求和)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hdu 1556:Color the ball(线段树,区间更新,经典题)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- HDU.1556 Color the ball (线段树 区间更新 单点查询)
HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...
- HDU 1556 Color the ball (数状数组)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- 线段树(求单结点) hdu 1556 Color the ball
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hdu 1556 Color the ball(区间更新,单点求值)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- HDU 1556 Color the ball(线段树区间更新)
Color the ball 我真的该认真的复习一下以前没懂的知识了,今天看了一下线段树,以前只会用模板,现在看懂了之后,发现还有这么多巧妙的地方,好厉害啊 所以就应该尽量搞懂 弄明白每个知识点 [题 ...
- hdu 1556 Color the ball (线段树+代码详解)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- hdu 1556 Color the ball(线段树区间维护+单点求值)
传送门:Color the ball Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/3276 ...
随机推荐
- Your Ruby version is 2.2.3, but your Gemfile specified 2.2.2
在文章 Ruby On Rails中REST API使用演示样例--基于云平台+云服务打造自己的在线翻译工具 中,从Bluemix上下载的初始Hello World演示样例代码在本地环境下运行调试时提 ...
- Vectorized implementation
Vectorization Vectorization refers to a powerful way to speed up your algorithms. Numerical computin ...
- Codefroces Educational Round 27 (A,B,C,D)
A. Chess Tourney time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- CSS Loading 特效
全页面遮罩效果loading css: .loading_shade { position: fixed; left:; top:; width: 100%; height: 100%; displa ...
- Java第三方工具库/包汇总
一.科学计算或矩阵运算库 科学计算包: JMathLib是一个用于计算复杂数学表达式并能够图形化显示计算结果的Java开源类库.它是Matlab.Octave.FreeMat.Scilab的一个克隆, ...
- 用了Redis里面的map和set
map的操作用 hset,hget等 set的操作有 sadd sismember等 参考下面: http://blog.csdn.net/kwsy2008/article/details/48467 ...
- hdu5400Arithmetic Sequence
//一个序列,两个公差d1,d2 //问有多少个区间使得这个区间存在一个点,它的左边是公差为d1的序列 //它的右边是公差为d2的序列 //直接存入每一个点向左和向右延伸的公差长度,乘一下即可 //还 ...
- 怎样解决git提交代码冲突
当我们使用git提交代码时,别人可能也同一时候改动了我们改动的文件,可是别人的先合入到配置库里边,这样当我们的提交要合入时.就会产生冲突,能够使用下面步骤来解决冲突: (1) git rebase ...
- jQuery高级选择器和其等价方法
jQuery选择器和css一样,但兼容性更好 <body> <p>p1</p> <p>p1</p> <p>p1</p> ...
- Direct2D 如何关闭抗锯齿
// Each pixel is rendered if its pixel center is contained by the geometry. // D2D1_ANTIALIAS_MODE_A ...