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());
    }
}
目录
相关文章
UVa 10082 WERTYU
UVa 10082 WERTYU
101 0
|
机器学习/深度学习
|
算法
UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics 10300 - Ecological Premium 458 - The Decoder 494...
1540 0
|
C++
UVA 之10010 - Where's Waldorf?
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/SunnyYoona/article/details/24863879 ...
685 0
|
机器学习/深度学习 人工智能
uva 10870 Recurrences
点击打开uva 10870 思路:构造矩阵+矩阵快速幂 分析: 1 题目给定f(n)的表达式 f(n) = a1 f(n - 1) + a2 f(n - 2) + a3 f(n -3) + .
716 0
|
人工智能
uva 10189 Minesweeper
/* Minesweeper WA了n次才知道uva格式错了也返回wa没有pe啊尼玛 */ #include&lt;iostream&gt; #include&lt;stdio.h&gt; #include&lt;string.h&gt; using namespace std; char a[105][105]; int main() { int i,j,n,m,
917 0