How Many Roads?

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;
}
时间: 2024-08-27 09:54:12

How Many Roads?的相关文章

POJ 2421 Constructing Roads 修建道路 最小生成树 Kruskal算法

题目链接:POJ 2421 Constructing Roads 修建道路 Constructing Roads Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 19698   Accepted: 8221 Description There are N villages, which are numbered from 1 to N, and you should build some roads such that e

Constructing Roads In JGShining&#39;s Kingdom HDU - 1025

JGShining's kingdom consists of 2n(n is no more than 500,000) small cities which are located in two parallel lines. Half of these cities are rich in resource (we call them rich cities) while the others are short of resource (we call them poor cities)

【树形dp】Rebuilding Roads

[POJ1947]Rebuilding Roads Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 11934   Accepted: 5519 Description The cows have reconstructed Farmer John's farm, with its N barns (1 <= N <= 150, number 1..N) after the terrible earthquake las

POJ——T2421 Constructing Roads

http://poj.org/problem?id=2421 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 24132   Accepted: 10368 Description There are N villages, which are numbered from 1 to N, and you should build some roads such that every two villages can con

HDU1102--Constructing Roads(最小生成树)

Problem Description There are N villages, which are numbered from 1 to N, and you should build some roads such that every two villages can connect to each other. We say two village A and B are connected, if and only if there is a road between A and B

Constructing Roads(最小生成树)

Constructing Roads Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 274 Accepted Submission(s): 172   Problem Description There are N villages, which are numbered from 1 to N, and you should build

POJ1251 Jungle Roads

Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 24307   Accepted: 11430 Description The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money was spent on extra roads between villages some years ago.

bzoj1689[Usaco2005 Open] Muddy roads 泥泞的路

bzoj1689[Usaco2005 Open] Muddy roads 泥泞的路 题意: 数轴上n个互不覆盖的区间,问要用多少个长为L的线段覆盖.n≤10000 题解: 排序区间,然后从每个区间左端点开始铺木板,如果最后一块木板能够铺到下一个区间就铺,以此类推. 代码: 1 #include <cstdio> 2 #include <algorithm> 3 #include <cstring> 4 #define maxn 10100 5 #define inc(i

Jungle Roads

Description The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money was spent on extra roads between villages some years ago. But the jungle overtakes roads relentlessly, so the large road network is too expensi

kruskal算法求最小生成树(jungle roads的kruskal解法)

注意: 注意数组越界问题(提交出现runtimeError代表数组越界) 刚开始提交的时候,边集中边的数目和点集中点的数目用的同一个宏定义,但是宏定义是按照点的最大数定义的,所以提交的时候出现了数组越界问题,以后需要注意啦. Description The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money was spent on extra roads betwe