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);
        }
    }
}
目录
相关文章
|
9月前
UVa11420 - Chest of Drawers(动态规划)
UVa11420 - Chest of Drawers(动态规划)
31 0
|
9月前
UVa11710 - Expensive subway(最小生成树)
UVa11710 - Expensive subway(最小生成树)
27 0
HDU7018.Banzhuan(计算几何+贪心)
HDU7018.Banzhuan(计算几何+贪心)
81 0
HDU7018.Banzhuan(计算几何+贪心)
HDU 4283 You Are the One(动态规划)
HDU 4283 You Are the One(动态规划)
45 0
HDU 4283 You Are the One(动态规划)
|
人工智能
Codeforces-1260-E. Tournament贪心
题意: 有n个人,第i个人有力量值i,这n个人中,每次对局两两之间进行solo,如果说一个人的力量之大于他的对手,这个人是赢的,赢得比赛的选手会进入下一轮比赛中。 然而里面有一个人为你的朋友,他或许并不是里面最强的人,要想让朋友成为冠军,就需要对必要的人进行贿赂,求出最少需要花费多少才能使得朋友成为冠军。在每次对局中,都可以进行任意的对局安排,对局安排只取决于自己
76 0
|
人工智能
codeforces1143B Nirvana(贪心)
codeforces1143B题解(贪心)
948 0
Uva 10339 - Watching Watches【数论,暴力】
题目链接:10339 - Watching Watches 题意:两个时钟,一个每天慢a秒,一个每天慢b秒,问两钟重新相遇的时刻 1圈有12 * 60 * 60秒,然后1圈 / abs(a - b),就可以求出多少天会相遇,然后就能求出A钟一共慢了多少秒,进而可以求出该时刻的时和分! 下面给...
1141 0