UVa11776 - Oh Your Royal Greediness!

简介: UVa11776 - Oh Your Royal Greediness!
importjava.io.BufferedReader;
importjava.io.InputStreamReader;
importjava.io.FileReader;
importjava.io.InputStream;
importjava.io.IOException;
importjava.util.StringTokenizer;
importjava.util.Arrays;
classMain{
publicstaticfinalbooleanDEBUG=false;  
publicNode[] node;
publicintt, n;
classNodeimplementsComparable<Node>    {
intx, y;
booleanok;
publicintcompareTo(Nodeother) 
        {
returnx-other.x;
        }
    }
publicvoidinit(InputStreamin)
    {
Reader.init(in);
t=0;
    }
publicbooleaninput() throwsIOException    {
n=Reader.nextInt();
if (n==-1) returnfalse;
t++;
node=newNode[n];
for (inti=0; i<n; i++) {
node[i] =newNode();
node[i].x=Reader.nextInt();
node[i].y=Reader.nextInt();
node[i].ok=false;
        }
returntrue;
    }
publicvoidsolve()
    {
Arrays.sort(node);
intans=0;
for (inti=0; i<n; i++) {
if (node[i].ok) continue;
ans++;
inty=node[i].y;
for (intj=i+1; j<n; j++) {
if (!node[j].ok&&y<node[j].x) {
node[j].ok=true;
y=node[j].y;
                }
            }
        }
System.out.println("Case "+t+": "+ans);
    }
publicstaticvoidmain(String[] args) throwsIOException    {
Mainsolver=newMain();
solver.init(System.in);
while (solver.input()) {
solver.solve();
        }
    }
}
classReader{
staticBufferedReaderreader;
staticStringTokenizertokenizer;
staticvoidinit(InputStreaminput)
    {
reader=newBufferedReader(newInputStreamReader(input));
tokenizer=newStringTokenizer("");
    }
staticStringnext() throwsIOException    {
while (!tokenizer.hasMoreTokens()) {
tokenizer=newStringTokenizer(reader.readLine());
        }
returntokenizer.nextToken();
    }
staticintnextInt() throwsIOException    {
returnInteger.parseInt(next());
    }
}
目录
相关文章
uva10038 Jolly Jumpers
uva10038 Jolly Jumpers
37 0
Uva10001 Garden of Eden
Uva10001 Garden of Eden
46 0
uva 10340 all in all
输入两个字符串s和t,判断是否可以从t中删除0个或多个字符(其他字符顺序不变),得到字符串是。
37 0
UVa10123 No Tipping
UVa10123 No Tipping
61 0
UVa11968 - In The Airport
UVa11968 - In The Airport
55 0
uva10152 ShellSort
uva10152 ShellSort
61 0
uva375 Inscribed Circles and Isosceles Triangles
uva375 Inscribed Circles and Isosceles Triangles
39 0
uva10112 Myacm Triangles
uva10112 Myacm Triangles
42 0
uva127 "Accordian" Patience
uva127 "Accordian" Patience
42 0
UVa11876 - N + NOD (N)
UVa11876 - N + NOD (N)
63 0