poj 3049 City Skyline

逗逼題,什麼棧的應用,瞎逼貪心就是了

import java.io.*;
import java.math.BigInteger;
import java.util.*;

class idx{
    int x,y;
    public idx(int a, int b){
        x=a;y=b;
    }
}
class problem1 {
    int n,w;
    idx arr[];
    int vis[];
    void solver() throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));        
        StringTokenizer st = new StringTokenizer(reader.readLine());
        n = Integer.valueOf(st.nextToken());
        w = Integer.valueOf(st.nextToken());
        arr = new idx[n];
        vis = new int[n];
        for(int i=0;i<n;i++){
            st = new StringTokenizer(reader.readLine());
            int t1 = Integer.valueOf(st.nextToken());
            int t2 = Integer.valueOf(st.nextToken());
            arr[i] = new idx(t1,t2);
        }
        int count=1;
        for(int i=0;i<n;i++){
            if(vis[i]!=0||arr[i].y==0) continue;
            search(i,count);
            count++;
        }
        System.out.println(count-1);
        //Dumper.print_1_arr(vis, n);
    }
    void search(int start, int count){
        int tmp = start;
        vis[start]=count;
        while(tmp<n&&arr[tmp].y>=arr[start].y){
            if(arr[tmp].y==arr[start].y) vis[tmp]=count;
            tmp++;            
        }
    }
}
 
public class stackingbox {
    public static void main(String[] args) throws Exception {
        problem1 p = new problem1();
        p.solver();
    }
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章