首页 > 专题系列 > Java解POJ > POJ 1032 Parliament [解题报告] Java
2013
11-08

POJ 1032 Parliament [解题报告] Java

Parliament

问题描述 :

New convocation of The Fool Land’s Parliament consists of N delegates. According to the present regulation delegates should be divided into disjoint groups of different sizes and every day each group has to send one delegate to the conciliatory committee. The composition of the conciliatory committee should be different each day. The Parliament works only while this can be accomplished.

You are to write a program that will determine how many delegates should contain each group in order for Parliament to work as long as possible.

输入:

The input file contains a single integer N (5<=N<=1000 ).

输出:

Write to the output file the sizes of groups that allow the Parliament to work for the maximal possible time. These sizes should be printed on a single line in ascending order and should be separated by spaces.

样例输入:

7

样例输出:

3 4

解题代码:

//* @author: [email protected]
import java.util.Scanner;
public class Main
{
	public static void main(String[] args)
	{
		Scanner in=new Scanner(System.in);
		int[] u=new int[]{
		1,2,5,9,14,20,27,35,44,54,65,77,90,104,119,135,152,170,189,209,230,252,275,299,324,
		350,377,405,434,464,495,527,560,594,629,665,702,740,779,819,860,902,945,989,1034,1111
		};
		int a=in.nextInt();
		int b=0;
		int k=22;
		int m=0;
		int h=45;
		while(!(a< u[k+1]&&a>=u[k]))
		{
			if(a>=u[k+1])
				{
					m=k;
					k=(k+h)/2;
				}
			else if(a< u[k])
			{
				h=k;
				k=(m+k)/2;
			}
		}
		b=a-u[k];
		int e=b/k;
		b=k-b%k;
		for(int i=2+e;i< k+e+2;i++)
		{
			if(b>0)
			System.out.print(i);
			else System.out.print((i+1));
			if(i!=k+e+1)System.out.print(" ");
			b--;
		}
	}
}

  1. 其实国内大部分公司对算法都不够重视。特别是中小型公司老板根本都不懂技术,也不懂什么是算法,从而也不要求程序员懂什么算法,做程序从来不考虑性能问题,只要页面能显示出来就是好程序,这是国内的现状,很无奈。

  2. 如果两个序列的最后字符不匹配(即X [M-1]!= Y [N-1])
    L(X [0 .. M-1],Y [0 .. N-1])= MAX(L(X [0 .. M-2],Y [0 .. N-1]),L(X [0 .. M-1],Y [0 .. N-1])
    这里写错了吧。

  3. “可以发现,树将是满二叉树,”这句话不对吧,构造的树应该是“完全二叉树”,而非“满二叉树”。

  4. 站长好。我是一个准备创业的互联网小白,我们打算做一个有关国*际*游*学的平台。手上也有了一些境外资源。现阶段的团队现在没有cto.原意出让一些管理股寻找一个靠谱的技术专家做合伙人, 不知道是不是能得到您的帮助。发个帖子或者其他方式。期待您的回应。可以加我微信tianxielemon聊聊。