首页 > 其他 > 详细

How Many Roads?

时间:2015-08-16 21:08:18      阅读:471      评论:0      收藏:0      [点我收藏+]

1005: 【2012四川省热身赛】Problem B. How Many Roads?

Time Limit: 1 Sec  Memory Limit: 32 MB

Description

As a director of cities transportation construction, Elfness is given a mission to connect n cities by
a lot of roads. Of course, the more roads to be built, the more convenient it would be. But if there
are two roads cross each other, traffic accidents may happen. So it means on Elfness’s ACM(All
Cities’ Map), there are no cross roads. And now, Elfness wants to know how many roads can be
built at most(Attention: a road won’t have to be a segment, it can be a straight line or a ray)?

Input

The first line of input is a single number T(T < 1000),means the number of test cases.Then T
cases followed, each case contains only one line with a single number n(0 < n ≤ 108),the number
of cities.

Output

For each test case,you should output one line. First, output “Case #t: ”, t means the number
of the test case which is from 1 to T. Then, output an integer indicates the maximal number of
roads can be built.

Sample Input

3
1
2
3

Sample Output

Case #1: 0
Case #2: 1
Case #3: 3

HINT

Source

2012年西部首届暨四川省第4届ACM-ICPC大学生程序设计竞赛热身赛

当城市等于4个的时候,就比3个城市的时候多三条路

当城市等于5个的时候,就比4个城市的时候多三条路

依次类推

#include<stdio.h>
int main()
{
    int n,m,i,t=1;
    scanf("%d",&n);
    while(n--)
    {
        scanf("%d",&m);
        if(m>0&&m<=100000000)
        {
            if(m==1)
                printf("Case #%d: %d\n",t++,0);
            else if(m>1&&m<=3)
                printf("Case #%d: %d\n",t++,2*m-3);
            else
                printf("Case #%d: %d\n",t++,(m-2)*3);
        }
    }
    return 0;
}

 

How Many Roads?

原文:http://www.cnblogs.com/tianmin123/p/4734898.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!