UVa668 - Parliament(贪心)

简介: UVa668 - Parliament(贪心)
importjava.io.BufferedReader;
importjava.io.InputStreamReader;
importjava.io.FileReader;
importjava.io.PrintWriter;
importjava.io.OutputStreamWriter;
importjava.io.StreamTokenizer;
importjava.io.IOException;
classMain{
publicstaticfinalbooleanDEBUG=false;
publicStreamTokenizertokenizer;
publicPrintWritercout;
publicvoidinit() throwsIOException    {
BufferedReadercin;
if (DEBUG) {
cin=newBufferedReader(newFileReader("d:\\OJ\\uva_in.txt"));
        } else {
cin=newBufferedReader(newInputStreamReader(System.in));
        }
tokenizer=newStreamTokenizer(cin);
cout=newPrintWriter(newOutputStreamWriter(System.out));
    }
publicintnext() throwsIOException    {
tokenizer.nextToken();
if (tokenizer.ttype==StreamTokenizer.TT_NUMBER) {
return (int)tokenizer.nval;
        }
return-1;
    }
privateintsum(intx)
    {
returnx* (x+1) /2-1;
    }
publicvoidsolve(intcas, intn)
    {
int[] num=newint[110];
for (inti=2; i<=n; i++) {
if (sum(i+1) >n) {
inttmp=sum(i);
intaverage= (n-tmp) / (i-1);
intremainder= (n-tmp) % (i-1);
for (intj=2; j<=i-remainder; j++) num[j] =j+average;
for (intj=i-remainder+1; j<=i; j++) num[j] =j+average+1;
for (intj=2; j<=i; j++) {
if (j!=2) cout.print(" ");
cout.print(num[j]);
                }
cout.println();
if (cas!=0) cout.println();
cout.flush();
return;
            }
        }
    }
publicstaticvoidmain(String[] args) throwsIOException    {
Mainsolver=newMain();
solver.init();
intt=solver.next();
while (t-->0) {
intn=solver.next();
solver.solve(t, n);
        }
    }
}
目录
相关文章
UVa11420 - Chest of Drawers(动态规划)
UVa11420 - Chest of Drawers(动态规划)
49 0
UVa11710 - Expensive subway(最小生成树)
UVa11710 - Expensive subway(最小生成树)
46 0
UVa12032 - The Monkey and the Oiled Bamboo(贪心)
UVa12032 - The Monkey and the Oiled Bamboo(贪心)
51 0
|
Go
[Nowcoder / POJ2728] 最优比率生成树 | 二分 + prim
有n个点,其中,每个点给出位置坐标( x , y ) 以及高度z ,两点之间的距离为两点之间的欧几里得距离 两点之间建立一条路的代价为两点之间的高度差,问将n 个点联通的情况下,求出最大的cost/dis
132 0
|
C语言
HDOJ/HDU Tempter of the Bone(深搜+奇偶性剪枝)
HDOJ/HDU Tempter of the Bone(深搜+奇偶性剪枝)
101 0
UVa 11292 - Dragon of Loowater(排序贪心)
UVa 11292 - Dragon of Loowater(排序贪心)
99 0
|
人工智能 BI 机器学习/深度学习