首页 > ACM题库 > HDU-杭电 > Hdu 1703 PBD-递推[解题报告] C++
2013
12-21

Hdu 1703 PBD-递推[解题报告] C++

PBD

问题描述 :

PrisonBreak is a popular TV programme in HDU. ACboy likes it very much, and he join a PrisonBreak discussing team called "PBD".Every Tuesday night, a lot of PBDers will contact with each other to discuss the newest plot of PrisonBreak season2. Generally speaking, every PBDer has distinct ideas about the play, so everyone want to know all the others’ ideas. For example, when ACboy contract with Sam, ACboy will tell all the ideas he konws to Sam, and Sam will also tell all the ideas he konws to ACboy, and the call costs 5 yuan.
If there are N people in the "PBD" team, what is the minimum cost to let everyone knows all the others’ ideas?

输入:

The input contains multiple test cases.
Each test case contains a number N, means there are N people in the "PBD" team.N = 0 ends the input.(A call cost 5 yuan).

输出:

for each case, output a integer represent the minimum cost to let everyone knows all the others’ ideas.

样例输入:

1
2
3
4
0

样例输出:

0
5
15
20

Hint
If there are 2 people, for example, named A, B. Then A calls B, then A and B will know each other's ideas, so it only needs one call, so the minimum cost is 1*5 = 5 yuan.


找规律
当大于五个人时每加一个人只要把这个人的想法传出去给其余一人,
再从剩下的任何一人知道所有人的想法,每加一个人就加两次费用
c[n]=c[n-1]+10(n>=5)

#include<stdio.h>
int f[5];
int main()
{
	int i,j,n;
	f[1]=0;f[2]=1;f[3]=3;f[4]=4;
	for(i=5;i<100;i++)
		f[i]=f[i-1]+2;
	while(scanf("%d",&n),n)
	{
		if(n<5)
		printf("%d\n",f[n]*5);
		else printf("%d\n",f[4]*5+(n-4)*10);
	}
	return 0;
}

 


  1. #include <stdio.h>
    int main(void)
    {
    int arr[] = {10,20,30,40,50,60};
    int *p=arr;
    printf("%d,%d,",*p++,*++p);
    printf("%d,%d,%d",*p,*p++,*++p);
    return 0;
    }

    为什么是 20,20,50,40,50. 我觉得的应该是 20,20,40,40,50 . 谁能解释下?