HDOJ--PBD



PBD

Time Limit : 1000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 16   Accepted Submission(s) : 3
Font: Times New Roman | Verdana | Georgia
Font Size: ← →

Problem Description

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?

Input

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).

Output

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

Sample Input

1
2
3
4
0

Sample Output

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.
代码思路如下:
#include<stdio.h>
int main()
{
    int n,i,m;
    while(scanf("%d",&n),n!=0)
    {
     if(n==1 || n==2) /*很容易得知当n=1和当n=2时需要打几次电话*/
     printf("%d\n",5*(n-1));
     if(n==3 || n==4)/*当n=4的时候比较难想,下面会介绍规律,
  (实在想不出来,output上有提示) */
     printf("%d\n",5*n);
     if(n>=5)/*这里用到一种方法,就把它称作整体法和隔离法吧。
  当n=5的时候,把5分为4和1,也就是分离出1之后把4看做一个整体 ,
  4个人任意出来一个人与分离出来的人通话,知道他的想法,然后四个
  人要想知道彼此的想法需要打4次电话,在这4个人的通话中就能传递
  分离出的那个人的想法 ,然后这四个人随便出来一个人告知他们四个
  的想法即可。 这样所有人就能知道彼此的想法。如果n=6,就把6分为
  5和一,类推就能得出结果。*/
     {  for(m=6,i=1;i<=n-5;i++)
        m=m+2;
           printf("%d\n",m*5);
      
     }
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值