您的位置:首页 > 其它

南邮2014程序设计新生赛暨蓝桥杯校内自主选拔赛2

2014-11-26 22:32 417 查看
南邮2014程序设计新生赛暨蓝桥杯校内自主选拔赛2

比赛链接:http://acm.njupt.edu.cn/vjudge/contest/view.action?cid=136#overview
比赛密码:iloveacmicpc

A - Lift





PDF (English)
Statistics
Forum
Time Limit: 2 second(s)Memory Limit: 32 MB
All of you must have noticed that the lift of AIUB is notavailable for students. But since you deny obeying usual rules, you always usethis lift no matter what happens!

Now one day you were sleeping in the class and when you wokeup you found none in the department except the guard who was in a deep sleep inhis room. But luckily you found the lift on. So, you want to go to the groundfloor using
the lift. But the lift can be in a different floor. Then you mustwait for the lift to come to your floor. Assume that it takes 4 seconds for thelift to go from any floor to its adjacent floor (up or down). It takes 3seconds to open or close the door of the
lift and you need 5 seconds to enteror exit the lift. Given your position and the lift's position you have tocalculate the time for you to reach the ground floor (floor 0). Reaching groundfloor means you must get out of the lift in ground floor.

Input

Input starts with an integer T (≤ 25),denoting the number of test cases.

Each case contains two integers. The first integer meansyour position (different than 0) and the second integer means the position ofthe lift. Assume that the department has
100 floors (may be one day itwill be :D).

Output

For each case, print the case number and the calculated timein seconds.

Sample Input

Output for Sample Input

3

1 2

3 10

5 5

Case 1: 27

Case 2: 59

Case 3: 39

题目分析:如题,小模拟

#include <cstdio>
int main()
{
    int T;
    scanf("%d", &T);
    for(int i = 1; i <= T; i++)
    {
        int a, b;
        scanf("%d %d", &a, &b);
        printf("Case %d: %d\n", i, 4 * (b - a > 0 ? b : 2 * a - b) + 10 + 9);
    }
}


B.MUH and Sticks

time limit per test
1 second

memory limit per test
256 megabytes

Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant
or a bear from those sticks. They can make an animal from sticks in the following way:

Four sticks represent the animal's legs, these sticks should have the same length.

Two remaining sticks represent the animal's head and body. The bear's head stick must be shorter than the body stick. The elephant, however, has a long trunk, so his head stick must be as long as the body stick. Note that there
are no limits on the relations between the leg sticks and the head and body sticks.

Your task is to find out which animal can be made from the given stick set. The zoo keeper wants the sticks back after the game, so they must never be broken, even bears understand it.

Input
The single line contains six space-separated integers
li (1 ≤ li ≤ 9) — the lengths of the six sticks. It is guaranteed that the input is such that you cannot
make both animals from the sticks.

Output
If you can make a bear from the given set, print string "Bear" (without the quotes). If you can make an elephant, print string "Elephant" (wıthout
the quotes). If you can make neither a bear nor an elephant, print string "Alien" (without the quotes).

Sample test(s)

Input
4 2 5 4 4 4


Output
Bear


Input
4 4 5 4 4 5


Output
Elephant


Input
1 2 3 4 5 6


Output
Alien


Note
If you're out of creative ideas, see instructions below which show how to make a bear and an elephant in the first two samples. The stick of length 2 is in red, the sticks of length 4 are in green, the sticks of length 5 are
in blue.



题目分析:如题,小模拟

#include <cstdio>
#include <cstring>
int hash[10], num[6];
int main()
{
    memset(hash, 0, sizeof(hash));
    for(int i = 0; i < 6; i++)
    {
        scanf("%d", &num[i]);
        hash[num[i]] ++;
    }
    bool flag = false;
    bool animal = false;
    for(int i = 1; i < 10; i++)
    {
        if(hash[i] == 6)
        {
            printf("Elephant\n");
            animal = true;
            break;
        }
        else if(hash[i] == 5)
        {
            printf("Bear\n");
            animal = true;
            break;
        }
        else if(hash[i] == 4)
        {
            for(int i = 1; i < 10; i++)
            {
                if(hash[i] == 2)
                {
                    flag = animal = true;
                    printf("Elephant\n");
                    break;
                }
            }
            if(flag)
                break;
            animal = true;
            printf("Bear\n");
            break;
        }
    }
    if(!animal)
        printf("Alien\n");
}


c.Sumsets
Time Limit: 2000MSMemory Limit: 200000K
Total Submissions: 13291Accepted: 5324
Description
Farmer John commanded his cows to search for different sets of numbers that sum to a given number. The cows use only numbers that are an integer power of 2. Here are the possible sets of numbers that
sum to 7:

1) 1+1+1+1+1+1+1

2) 1+1+1+1+1+2

3) 1+1+1+2+2

4) 1+1+1+4

5) 1+2+2+2

6) 1+2+4

Help FJ count all possible representations for a given integer N (1 <= N <= 1,000,000).

Input
A single line with a single integer, N.
Output
The number of ways to represent N as the indicated sum. Due to the potential huge size of this number, print only last 9 digits (in base 10 representation).
Sample Input
7

Sample Output
6

Source
USACO 2005 January Silver

题目分析:找规律,规律还是很好发现的,或者直接分析题目,奇数的数目肯定和其前面的偶数相同,比如6有6种分解,7只比6大1,不存在别的分解,只是将6的所有分解加1,故数目与6相同,偶数间的关系为num[i] = num[i - 2] + num[i / 2] 因为多出来的无非两种情况,一是num[i - 2]直接加2,二是除2,举个例子,比如8,它的分解数目可以理解为6的分解数加上4的分解数

8:

1 + 1 + 1 + 1 + 1 + 1 + 1 + 1

1 + 1 + 1 + 1 + 2 + 2

2 + 2 + 2 + 2

4 + 4

1 + 1 + 1 + 1 + 1 + 1 + 2

1 + 1 + 1 + 1 + 4

1 + 1 + 2 + 2 + 2

1 + 1 + 2 + 4

2 + 2 + 4

8

6:

1+ 1 + 1 + 1 + 1 + 1

1 +1 + 1 + 1 + 2

1 +1 + 2 + 2

1 +1 + 4

2 +2 + 2

2 +4

4:

1 + 1 + 1 + 1

1 + 1 + 2

2 + 2

4

这样看的很清楚了,8的分解种包含了4的分解乘2和6的分解加2两种情况

#include <cstdio>
const int MAX = 1000000 + 1;
const int MOD = 1000000000;
int num[MAX];
int main()
{
    int n;
    num[1] = 1;
    num[2] = 2;
    for(int i = 3; i < MAX; i++)
    {
        if(i % 2 == 1)
            num[i] = num[i - 1];
        else
        {
            num[i] = num[i - 2] + num[i / 2];
            num[i] %= MOD;
        }
    }
    while(scanf("%d",&n) != EOF)
        printf("%d\n",num
);
}


D.Leftmost Digit

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

Total Submission(s): 13082 Accepted Submission(s): 5009


Problem Description
Given a positive integer N, you should output the leftmost digit of N^N.



Input
The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.

Each test case contains a single positive integer N(1<=N<=1,000,000,000).



Output
For each test case, you should output the leftmost digit of N^N.



Sample Input
2
3
4




Sample Output
2
2

Hint
[code]In the first case, 3 * 3 * 3 = 27, so the leftmost digit is 2.
In the second case, 4 * 4 * 4 * 4 = 256, so the leftmost digit is 2.


题目大意 :求解n的n次方的最左边的数

题目分析 :  因为数字太大,考虑用对数  
           主要思路是任意数num可以表示为:num ^ num = a * 10 ^ n(a的整数部分即为所求解, n为位数)
           两边取对数:num * lg(num) = lg(a) + n,  令x = num * lg(num)  
           则n为x的整数部分,lg(a)为x的小数部分,所以lg(a) = x - n
           a = 10 ^ (x - n) => a = 10 ^ (x - (long long)x) 这里注意转换的的时候不能用int, 因为double表示的范围远大于int


#include <cmath>
#include <cstdio>
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {   
        int num;
        scanf("%d",&num);
        double x = num * log10(num);
        printf("%d\n", (int) pow(10.0 , (x - (long long)x)));
    }
    return 0;
}




E.Wooden Sticks

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

Total Submission(s): 11619 Accepted Submission(s): 4800

Problem Description
There is a pile of n wooden sticks. The length and weight of each stick are known in advance. The sticks are to be processed by a woodworking machine in one by one fashion. It needs some time, called setup
time, for the machine to prepare processing a stick. The setup times are associated with cleaning operations and changing tools and shapes in the machine. The setup times of the woodworking machine are given as follows:

(a) The setup time for the first wooden stick is 1 minute.

(b) Right after processing a stick of length l and weight w , the machine will need no setup time for a stick of length l' and weight w' if l<=l' and w<=w'. Otherwise, it will need 1 minute for setup.

You are to find the minimum setup time to process a given pile of n wooden sticks. For example, if you have five sticks whose pairs of length and weight are (4,9), (5,2), (2,1), (3,5), and (1,4), then the minimum setup time should be 2 minutes since there is
a sequence of pairs (1,4), (3,5), (4,9), (2,1), (5,2).



Input
The input consists of T test cases. The number of test cases (T) is given in the first line of the input file. Each test case consists of two lines: The first line has an integer n , 1<=n<=5000, that represents
the number of wooden sticks in the test case, and the second line contains n 2 positive integers l1, w1, l2, w2, ..., ln, wn, each of magnitude at most 10000 , where li and wi are the length and weight of the i th wooden stick, respectively. The 2n integers
are delimited by one or more spaces.



Output
The output should contain the minimum setup time in minutes, one per line.



Sample Input
3 
5 
4 9 5 2 2 1 3 5 1 4 
3 
2 2 1 1 2 2 
3 
1 3 2 2 3 1




Sample Output
2
1
3




Source
Asia 2001, Taejon (South Korea)

题目大意 :有n根木条,加工第一根需要1时间,如果后一根的长度和重量都大于等于前一根那么机器不用化费额外的时间

现给定n根木条的长度和重量,求出加工这些木条最少需要的时间

题目分析 :采用贪心策略,先对木条的长度或者重量排序,长度排完序后再对重量排序,找到一组重量单调增(减)的集合则做出标记,最后求得的集合的数目即为问题的答案。

#include<cstdio>
#include<algorithm>
using namespace std;
int const MAX = 5000 + 5;
struct STICK
{
    int l;
    int w;
}sticks[MAX];

int flag[MAX];

bool cmp(const STICK &a,const STICK &b)
{
    if(a.l != b.l)
        return a.l < b.l;
    else
        return a.w < b.w;
}

int main()
{
    int num,min = 0,cases;
    scanf("%d",&cases);
    while(cases--)
    {
        scanf("%d",&num);
        for(int i = 0; i < num; i++)
        {
            scanf("%d%d",&sticks[i].l,&sticks[i].w);
            flag[i]=0;
        }
        sort(sticks,sticks + num,cmp);
        int cnt = 0;
        for(int i = 0; i < num; i++)
        {
            if( flag[i] )
                continue;
            min = sticks[i].w;
            for(int j = i + 1; j < num; j++)
            {
                if(min <= sticks[j].w && !flag[j])
                {
                    min = sticks[j].w;
                    flag[j] = 1;
                }
            }
            cnt++;
        }
        printf("%d\n",cnt);
    }
}


F.Image Perimeters
Time Limit: 1000MSMemory Limit: 10000K
Total Submissions: 7906Accepted: 4719
Description
Technicians in a pathology lab analyze digitized images of slides. Objects on a slide are selected for analysis by a mouse click on the object. The perimeter of the boundary of an object is one useful
measure. Your task is to determine this perimeter for selected objects.

The digitized slides will be represented by a rectangular grid of periods, '.', indicating empty space, and the capital letter 'X', indicating part of an object. Simple examples are

XX   Grid 1       .XXX   Grid 2 

XX                .XXX 

                  .XXX 

                  ...X 

                  ..X. 

                  X...


An X in a grid square indicates that the entire grid square, including its boundaries, lies in some object. The X in the center of the grid below is adjacent to the X in any of the 8 positions around it. The grid squares for any two adjacent X's overlap on
an edge or corner, so they are connected.

XXX 

XXX    Central X and adjacent X's 

XXX


An object consists of the grid squares of all X's that can be linked to one another through a sequence of adjacent X's. In Grid 1, the whole grid is filled by one object. In Grid 2 there are two objects. One object contains only the lower left grid square.
The remaining X's belong to the other object.

The technician will always click on an X, selecting the object containing that X. The coordinates of the click are recorded. Rows and columns are numbered starting from 1 in the upper left hand corner. The technician could select the object in Grid 1 by clicking
on row 2 and column 2. The larger object in Grid 2 could be selected by clicking on row 2, column 3. The click could not be on row 4, column 3.



One useful statistic is the perimeter of the object. Assume each X corresponds to a square one unit on each side. Hence the object in Grid 1 has perimeter 8 (2 on each of four sides). The perimeter for the larger object in Grid 2 is illustrated in the figure
at the left. The length is 18.

Objects will not contain any totally enclosed holes, so the leftmost grid patterns shown below could NOT appear. The variations on the right could appear:

Impossible   Possible 

XXXX         XXXX   XXXX   XXXX 

X..X         XXXX   X...   X... 

XX.X         XXXX   XX.X   XX.X 

XXXX         XXXX   XXXX   XX.X 

.....        .....  .....  ..... 

..X..        ..X..  ..X..  ..X.. 

.X.X.        .XXX.  .X...  ..... 

..X..        ..X..  ..X..  ..X.. 

.....        .....  .....  .....


Input
The input will contain one or more grids. Each grid is preceded by a line containing the number of rows and columns in the grid and the row and column of the mouse click. All numbers are in the range
1-20. The rows of the grid follow, starting on the next line, consisting of '.' and 'X' characters.

The end of the input is indicated by a line containing four zeros. The numbers on any one line are separated by blanks. The grid rows contain no blanks.

Output
For each grid in the input, the output contains a single line with the perimeter of the specified object.
Sample Input
<span style="font-size:14px;">2 2 2 2
XX
XX
6 4 2 3
.XXX
.XXX
.XXX
...X
..X.
X...
5 6 1 3
.XXXX.
X....X
..XX.X
.X...X
..XXX.
7 7 2 6
XXXXXXX
XX...XX
X..X..X
X..X...
X..X..X
X.....X
XXXXXXX
7 7 4 4
XXXXXXX
XX...XX
X..X..X
X..X...
X..X..X
X.....X
XXXXXXX
0 0 0 0</span>

Sample Output
<span style="font-size:14px;">8
18
40
48
8</span>

Source
Mid-Central USA 2001

题目大意 :输入一个n*m的矩阵,从一个给定点搜与其在八个方向上能连在一起的X,求这块图形的周长

题目分析 :在矩阵外套一层'.'每次搜到一个'X'就在其上下左右记下'.'的个数

#include <cstdio>
#include <cstring>
int const MAX  = 21;
char map[MAX][MAX];
bool vis[MAX][MAX];
int n, m, x, y;
int dirx[8] = {1, -1, 0, 0, 1, -1, 1, -1};
int diry[8] = {0, 0, 1, -1, 1, -1, -1, 1};
int ans;

int DFS(int x, int y)
{
    vis[x][y] = true;
    for(int i = 0; i < 4; i++)
        if(map[x + dirx[i]][y + diry[i]] == '.')
            ans++;
    for(int i = 0; i < 8; i++)
    {
        int xx = x + dirx[i];
        int yy = y + diry[i];
        if(xx <= n && xx >= 1 && yy <= m && yy >= 1 && !vis[xx][yy] && map[xx][yy] == 'X')
            DFS(xx, yy);
    }
    return ans;
}

int main()
{
    while(scanf("%d %d %d %d", &n, &m, &x, &y) != EOF && n + m)
    {
        ans = 0;
        memset(vis, false, sizeof(vis));
        for(int i = 1; i <= n; i++)
            scanf("%s", map[i] + 1);
        for(int i = 0; i <= n + 1; i++)
            map[i][0] = map[i][m + 1] = '.';
        for(int i = 0; i <= n + 1; i++)
            map[0][i] = map[n + 1][i] = '.';
        DFS(x, y);
        printf("%d\n", ans);
    }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: