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);
        }
    }
}
目录
相关文章
|
5月前
【洛谷 P1219】[USACO1.5]八皇后 Checker Challenge 题解(深度优先搜索+回溯法)
**USACO1.5八皇后挑战**是关于在$n\times n$棋盘上放置棋子的,确保每行、每列及两条主对角线上各有一个且仅有一个棋子。给定$6$作为输入,输出前$3$个解及解的总数。例如,对于$6\times6$棋盘,正确输出应包括解的序列和总数。代码使用DFS解决,通过跟踪对角线占用状态避免冲突。当找到所有解时,显示前三个并计数。样例输入$6$产生输出为解的前三个排列和总数$4$。
37 0
UVa11420 - Chest of Drawers(动态规划)
UVa11420 - Chest of Drawers(动态规划)
47 0
UVa11710 - Expensive subway(最小生成树)
UVa11710 - Expensive subway(最小生成树)
41 0
HDU 4283 You Are the One(动态规划)
HDU 4283 You Are the One(动态规划)
78 0
HDU 4283 You Are the One(动态规划)
Uva 10339 - Watching Watches【数论,暴力】
题目链接:10339 - Watching Watches 题意:两个时钟,一个每天慢a秒,一个每天慢b秒,问两钟重新相遇的时刻 1圈有12 * 60 * 60秒,然后1圈 / abs(a - b),就可以求出多少天会相遇,然后就能求出A钟一共慢了多少秒,进而可以求出该时刻的时和分! 下面给...
1164 0
|
算法
UVa 10341 - Solve It【经典二分,单调性求解】
原题: Solve the equation:         p*e-x + q*sin(x) + r*cos(x) + s*tan(x) + t*x2 + u = 0         where 0 0) 15 { 16 printf("No solut...
884 0
|
并行计算 算法 Java
HDU 1874 畅通工程续【Floyd算法实现】
畅通工程续 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 53806    Accepted Submission(s): 20092 Problem Description 某省自从实行了很多年的畅通工程计划后,终于修建了很多路。
1086 0
|
人工智能
POJ 2370 Democracy in danger(简单贪心)
Democracy in danger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3388   Accepted: 2508 Description In one of the...
954 0