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);
        }
    }
}
kgduu
+关注
目录
打赏
0
0
0
0
0
分享
相关文章
UVa872 - Ordering(拓扑排序)
UVa872 - Ordering(拓扑排序)
69 0
UVa11420 - Chest of Drawers(动态规划)
UVa11420 - Chest of Drawers(动态规划)
88 0
UVa11710 - Expensive subway(最小生成树)
UVa11710 - Expensive subway(最小生成树)
89 0
UVa12032 - The Monkey and the Oiled Bamboo(贪心)
UVa12032 - The Monkey and the Oiled Bamboo(贪心)
59 0
UVa10596 - Morning Walk(并查集)
UVa10596 - Morning Walk(并查集)
94 0
luoguP2205 [USACO13JAN]Painting the Fence S(差分 扫描线思想)
luoguP2205 [USACO13JAN]Painting the Fence S(差分 扫描线思想)
83 0
UVa 11292 - Dragon of Loowater(排序贪心)
UVa 11292 - Dragon of Loowater(排序贪心)
113 0
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等