学习心得(code)

superlong@CoreCoder

  C++博客 :: 首页 :: 联系 :: 聚合  :: 管理
  74 Posts :: 0 Stories :: 5 Comments :: 0 Trackbacks

公告

文字可能放在http://blog.csdn.net/superlong100,此处存放代码

常用链接

留言簿(4)

我参与的团队

搜索

  •  

最新随笔

最新评论

  • 1. re: Poj 1279
  • 对于一个凹多边形用叉积计算面积 后能根据结果的正负来判断给的点集的时针方向?
  • --bsshanghai
  • 2. re: Poj 3691
  • 你写的这个get_fail() 好像并是真正的get_fail,也是说fail指向的串并不是当前结点的子串。为什么要这样弄呢?
  • --acmer1183
  • 3. re: HDU2295[未登录]
  • 这个是IDA* 也就是迭代加深@ylfdrib
  • --superlong
  • 4. re: HDU2295
  • 评论内容较长,点击标题查看
  • --ylfdrib
  • 5. re: HOJ 11482
  • 呵呵..把代码发在这里很不错..以后我也试试...百度的编辑器太烂了....
  • --csuft1

阅读排行榜

评论排行榜

http://acm.fzu.edu.cn/problem.php?pid=1894

志愿者选拔 O(n)
最最入门的单调队列,而且是很形象的排队问题
#include <stdio.h>
#include 
<string.h>

const int N = 1000005;

int que[N][2], v;
char op[10];
int tail, head, id, now;

inline 
void push(int v, int id) {
    
while( tail >= head && que[tail][0]<v) tail--;
    que[
++tail][0= v;
    que[tail][
1= id;
}

inline 
void pop() {
    
if( tail >= head && que[head][1== now) head ++;
    now 
++;
}

inline 
void out() {
    
if( tail < head ) puts("-1");
    
else printf("%d\n", que[head][0]);
}

int main() {
    
int t;
    scanf(
"%d"&t);
    
while( t --) {
        head 
= 0, tail = -1; id = 0, now = 0;
        
while( scanf("%s", op)!= EOF ) 
            
if ( !strcmp(op, "START") ) break;
        
while( scanf("%s", op) ) {
            
if!strcmp(op, "END") ) break;
            
if( op[0== 'C' ) {
                scanf(
"%s", op);
                scanf(
"%d"&v);
                push(v, id);
                id 
++;
            } 
else if( op[0== 'G' ) {
                pop();
            } 
else if( op[0== 'Q' ) {
                
out();
            }
        }
    }
}
Sliding Window O(n)
同上题
http://acm.pku.edu.cn/JudgeOnline/problem?id=2823
#include <stdio.h>
#include 
<string.h>

const int N = 1000005;

int n, k;
struct node {
    
int num, id;
} min[N], max[N];

int minans[N], maxans[N], x;
int head[2], tail[2], cnt = 0;

int main() {
    
while( scanf("%d %d"&n, &k) != EOF ) {
        head[
0= head[1= -1;
        tail[
0= tail[1= 0;
        cnt 
= 0;
        
for(int i = 0; i < n; i ++) {
            scanf(
"%d"&x);
            
while( head[0>= tail[0&& min[tail[0]].id + k - 1 < i ) tail[0]++;
            
while( head[1>= tail[1&& max[tail[1]].id + k - 1 < i ) tail[1]++;
            
while( head[0>= tail[0&& min[head[0]].num >= x) head[0--;
            min[
++head[0]].num = x; 
            min[head[
0]].id = i;
            
while( head[1>= tail[1&& max[head[1]].num <= x) head[1--;
            max[
++head[1]].num = x; 
            max[head[
1]].id = i;
            
if( i >= k - 1 ){
                minans[cnt] 
= min[tail[0]].num;
                maxans[cnt] 
= max[tail[1]].num;
                cnt 
++;
            }
        }
        
for(int i = 0; i < cnt; i ++
            
if(i == 0) printf("%d", minans[i]); 
            
else       printf(" %d", minans[i]); 
        puts(
"");
        
for(int i = 0; i < cnt; i ++
            
if(i == 0) printf("%d", maxans[i]); 
            
else       printf(" %d", maxans[i]);
        puts(
"");
    }
}


1
posted on 2010-07-29 11:50 superlong 阅读(263) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理