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());
    }
}
目录
相关文章
Uva10001 Garden of Eden
Uva10001 Garden of Eden
47 0
UVa11968 - In The Airport
UVa11968 - In The Airport
58 0
uva10152 ShellSort
uva10152 ShellSort
62 0
UVa 10082 WERTYU
Problem Description A common typing error is to place the hands on the keyboard one row to the right of the correct position.
891 0
|
算法
UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics 10300 - Ecological Premium 458 - The Decoder 494...
1570 0
|
机器学习/深度学习
uva 12470 Tribonacci
点击打开uva12470  思路: 矩阵快速幂 分析: 1 裸题 代码: /************************************************ * By: chenguolin ...
993 0
|
机器学习/深度学习 人工智能
uva 10870 Recurrences
点击打开uva 10870 思路:构造矩阵+矩阵快速幂 分析: 1 题目给定f(n)的表达式 f(n) = a1 f(n - 1) + a2 f(n - 2) + a3 f(n -3) + .
735 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,
939 0
|
人工智能
uva 11300 - Spreading the Wealth
点击打开链接uva 11300 思路:数学分析+贪心 分析: 1 首先最终每个人的金币数量可以计算出来,它等于金币总数除以人数n。接下来我们用m来表示每人的最终的金币数 2 现在假设编号为i的人初始化为Ai枚金币,Xi表示第i个人给第i-1个人Xi枚金币,对于第一个人来说他是给第n个人。
864 0