Skip to content

Instantly share code, notes, and snippets.

@zeptometer
Created November 7, 2010 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeptometer/666151 to your computer and use it in GitHub Desktop.
Save zeptometer/666151 to your computer and use it in GitHub Desktop.
aoj0509
import java.util.*;
public class aoj0509{
static final int rowmax = 10000;
public static void main(String[] args){
Scanner scn = new Scanner(System.in);
int num,mode;
Row[] rows = new Row[rowmax];
num = scn.nextInt();
mode = scn.nextInt();
for(int i=0; i<num; i++){
int fromx = scn.nextInt();
int fromy = scn.nextInt();
int tox = scn.nextInt();
int toy = scn.nextInt();
for(int j=fromy; j<toy; j++)
rows[j].add(new RangeList(fromx,tox));
}
}
}
class Row{
RangeList first;
void add(RangeList r){
if(first == null){
if(r.from == 0){
first = r;
}else{
first = new RangeList(0,0);
first.next = r;
}
if(r.to < rowmax)
r.next = new RangeList(rowmax,rowmax);
}else{
int newfrom,newto;
RangeList tmp1,tmp2;
for(RangeList rl=first; rl != null; rl=rl.next;)
if(rl.from<=r.from && rl.to>=r.from){
newfrom = rl.from;
tmp1 = rl;
beak;
}else if(rl.to<r.from && rl.next.from>r.from){
newfrom = r.from;
tmp1 = rl;
break;
}
for(RangeList rl=tmp1; rl != null; rl=rl.next;)
if(rl.from<=r.to && rl.to>=r.to){
newto = rl.to;
tmp2 = rl;
beak;
}else if(rl.to<r.to && rl.next.from>r.to ){
newto = r.to;
tmp2 = rl;
break;
}
}
}
}
class RangeList{
int from,to;
RangeList next;
RangeList(int f,int t){
this.from = f;
this.to = t;
}
void alter(int f,int t){
this.from = f;
this.to = t;
}
int range(){
return to-from;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment