HDU - 2018杭电ACM集训队单人排位赛 - 2 - Problem E. Travel

简介: HDU - 2018杭电ACM集训队单人排位赛 - 2 - Problem E. Travel

Problem E Travel

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 138    Accepted Submission(s): 66


Problem Description

It is said Guilin's scenery is the best in the world. Now since the first Guangxi Province Collegiate Programming Contest is held in Guilin, Luras decided to travel around Guilin. She knows that there will be n nodes in the travel map. Luras will pick a shortest way to go from node 1 to node n. You are a city designer who could decide if there is a bi-directional edge with the length of 1 between every two nodes. And you hope to build the roads to make the shortest path from 1 to n to be as many as possible. Could you tell Luras how many shortest path could it be at most between node 1 and node n in your final city graph?

Input

The first line is an integer T which indicates the case number.

And as for each case,  there will be one lines

In the line, there is 1 integer n, which indicates the number of node.

It is guaranteed that——

T is about 100.

for 100% cases, 2 <= n <= 40.

Output

As for each case, you need to output a single line.

There should be one integer in the line which means the maximum shortest path could be between node 1 and node n.

Sample Input

6

2

3

4

5

6

7

Sample Output

1

1

2

3

4

6

解题思路:点击打开链接


AC 代码


#include<bits/stdc++.h>
#include<cmath>
#define mem(a,b) memset(a,b,sizeof a);
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
int main()
{
    int T; scanf("%d",&T);
    int n;
    while(T-- && ~scanf("%d",&n))
    {
        n-=2;
        int rs;
        if(n==0) rs=1;
        else if(n<4) rs=n;
        else
        {
            int cnt3,cnt2;
            if(n%2==1)
            {
                cnt3=(n-3)/6*2+1;
                cnt2=(n-3)%6/2;
            }
            else
            {
                cnt3=n/6;
                cnt2=n%6/2;
            }
            rs=pow(3,cnt3) * pow(2,cnt2);
        }
        printf("%d\n",rs);
    }
    return 0;
}
目录
相关文章
|
11月前
2022天梯赛三月冲刺——PAT (Advanced Level)1013 Battle Over Cities (并查集找连通块)
2022天梯赛三月冲刺——PAT (Advanced Level)1013 Battle Over Cities (并查集找连通块)
63 0
|
C++ 网络架构
【PAT甲级 - C++题解】1013 Battle Over Cities
【PAT甲级 - C++题解】1013 Battle Over Cities
52 1
|
存储 C++
【PAT甲级 - C++题解】1056 Mice and Rice
【PAT甲级 - C++题解】1056 Mice and Rice
47 0
|
C++
【PAT甲级 - C++题解】1061 Dating
【PAT甲级 - C++题解】1061 Dating
56 0
upc2021秋组队训练赛第一场 ICPC North Central NA Contest 2020
upc2021秋组队训练赛第一场 ICPC North Central NA Contest 2020
77 0
upc2021秋组队训练赛第一场 ICPC North Central NA Contest 2020
UPC组队赛第三场——G: The Famous ICPC Team Again (主席树)
UPC组队赛第三场——G: The Famous ICPC Team Again (主席树)
79 0
|
人工智能
upc 2021秋组队训练赛第三场 2020 Rocky Mountain Regional Contest
upc 2021秋组队训练赛第三场 2020 Rocky Mountain Regional Contest
80 0
|
人工智能 安全
UPC-2021个人训练赛第20场-部分题解
RGB Triplets 题目描述 输入 输出 样例输入 Copy 样例输出 Copy 提示 Select Half 题目描述 输入 输出 样例输入 Copy 样例输出 Copy 提示 心灵的抚慰 题目描述 输入 输出 样例输入 Copy 样例输出 Copy 提示
149 0
|
机器学习/深度学习 算法 Java
HDU - 2018杭电ACM集训队单人排位赛 - 3 - Problem B. Bullet
HDU - 2018杭电ACM集训队单人排位赛 - 3 - Problem B. Bullet
143 0
|
Java
HDU - 2018杭电ACM集训队单人排位赛 - 3 - Problem F. Four-tuples
HDU - 2018杭电ACM集训队单人排位赛 - 3 - Problem F. Four-tuples
125 0