SYU新人提高90题1(基础题)

A - Hangover
Description
How far can you make a stack of cards overhang a table? If you have one card, you can create a maximum overhang of half a card length. (We’re assuming that the cards must be perpendicular to the table.) With two cards you can make the top card overhang the bottom one by half a card length, and the bottom one overhang the table by a third of a card length, for a total maximum overhang of 1/2 + 1/3 = 5/6 card lengths. In general you can make n cards overhang by 1/2 + 1/3 + 1/4 + … + 1/(n + 1) card lengths, where the top card overhangs the second by 1/2, the second overhangs tha third by 1/3, the third overhangs the fourth by 1/4, etc., a**nd the bottom card overhangs the table by 1/(n + 1).** This is illustrated in the figure below.
加粗处就是理解题意的重点;

Input
The input consists of one or more test cases, followed by a line containing the number 0.00 that signals the end of the input. Each test case is a single line containing a positive floating-point number c whose value is at least 0.01 and at most 5.20; c will contain exactly three digits.
Output
For each test case, output the minimum number of cards necessary to achieve an overhang of at least c card lengths. Use the exact output format shown in the examples.
Sample Input
1.00
3.71
0.04
5.19
0.00
Sample Output
3 card(s)
61 card(s)
1 card(s)
273 card(s)

水题,看懂题目就ok了;

#include<stdio.h>
int main()
{
    int n;
    float a,sum;
    while(scanf("%f",&a)!=EOF&&a!=0){
        n = 0; 
        sum = 0;
        while(sum < a){
            n++;
            sum += 1.0/(n+1);
        }
        printf("%d card(s)\n",n);
    }

    return 0 ;
}

B水题;就是找平均数;要注意PE要输出$;

C题
C - I Think I Need a Houseboat
Description
Fred Mapper is considering purchasing some land in Louisiana to build his house on. In the process of investigating the land, he learned that the state of Louisiana is actually shrinking by 50 square miles each year, due to erosion caused by the Mississippi River. Since Fred is hoping to live in this house the rest of his life, he needs to know if his land is going to be lost to erosion.

After doing more research, Fred has learned that the land that is being lost forms a semicircle. This semicircle is part of a circle centered at (0,0), with the line that bisects the circle being the X axis. Locations below the X axis are in the water. The semicircle has an area of 0 at the beginning of year 1. (Semicircle illustrated in the Figure.)

Input
The first line of input will be a positive integer indicating how many data sets will be included (N). Each of the next N lines will contain the X and Y Cartesian coordinates of the land Fred is considering. These will be floating point numbers measured in miles. The Y coordinate will be non-negative. (0,0) will not be given.
Output
For each data set, a single line of output should appear. This line should take the form of: “Property N: This property will begin eroding in year Z.” Where N is the data set (counting from 1), and Z is the first year (start from 1) this property will be within the semicircle AT THE END OF YEAR Z. Z must be an integer. After the last data set, this should print out “END OF OUTPUT.”
Sample Input
2
1.0 1.0
25.0 0.0
Sample Output
Property 1: This property will begin eroding in year 1.
Property 2: This property will begin eroding in year 20.
END OF OUTPUT.
Hint
1.No property will appear exactly on the semicircle boundary: it will either be inside or outside.
2.This problem will be judged automatically. Your answer must match exactly, including the capitalization, punctuation, and white-space. This includes the periods at the ends of the lines.
3.All locations are given in miles.

看懂题目就做出来了;水;
还要注意一下思路的简单性;
可以直接去除以每年成长的速度50就是年份;注意取整和加1;

#include <stdio.h>
#define p 3.1415926

int main()
{
    int t, i,s;
    double x, y;
    scanf("%d",&t);
    for(i = 1; i <= t; i++){
        scanf("%lf %lf",&x, &y);
        s = (int)((x*x+y*y)/2*p/50)+1;
        printf("Property %d: This property will begin eroding in year %d.\n",i, s);
    }
    printf("END OF OUTPUT.\n");
    return 0;
}

D题;
D - Biorhythms
Description
人生来就有三个生理周期,分别为体力、感情和智力周期,它们的周期长度为23天、28天和33天。每一个周期中有一天是高峰。在高峰这天,人会在相应的方面表现出色。例如,智力周期的高峰,人会思维敏捷,精力容易高度集中。因为三个周期的周长不同,所以通常三个周期的高峰不会落在同一天。对于每个人,我们想知道何时三个高峰落在同一天。对于每个周期,我们会给出从当前年份的第一天开始,到出现高峰的天数(不一定是第一次高峰出现的时间)。你的任务是给定一个从当年第一天开始数的天数,输出从给定时间开始(不包括给定时间)下一次三个高峰落在同一天的时间(距给定时间的天数)。例如:给定时间为10,下次出现三个高峰同天的时间是12,则输出2(注意这里不是3)。
Input
输入四个整数:p, e, i和d。 p, e, i分别表示体力、情感和智力高峰出现的时间(时间从当年的第一天开始计算)。d 是给定的时间,可能小于p, e, 或 i。 所有给定时间是非负的并且小于365, 所求的时间小于21252。

当p = e = i = d = -1时,输入数据结束。
Output
从给定时间起,下一次三个高峰同天的时间(距离给定时间的天数)。

采用以下格式:
Case 1: the next triple peak occurs in 1234 days.

注意:即使结果是1天,也使用复数形式“days”。
Sample Input
0 0 0 0
0 0 0 100
5 20 34 325
4 5 6 7
283 102 23 320
203 301 203 40
-1 -1 -1 -1
Sample Output
Case 1: the next triple peak occurs in 21252 days.
Case 2: the next triple peak occurs in 21152 days.
Case 3: the next triple peak occurs in 19575 days.
Case 4: the next triple peak occurs in 16994 days.
Case 5: the next triple peak occurs in 8910 days.
Case 6: the next triple peak occurs in 10789 days.

这题;是第二次做了;中国剩余定理;第一次没怎么看懂;现在才知道一点点;以后会专门写一篇博客来说中国剩余定理;
现在就只摆下代码吧;
代码已经写得几乎很完整了;

#include<stdio.h>
int main()
{
    int p, e, i, d, k, m1, m2, m3, t1=0, t2=0,t3=0,x;
    k =0;
    m1 = 924;
        m2 = 759;
        m3 = 644;

        for(i = 1; i < 23; i++){
            if((m1*i)%23==1){
                t1 = i;
                break;
            }
        }
        for(i = 1; i < 28; i++){        
            if((m2*i)%28==1){
                t2 = i;
                break;
            }
        }
        for(i = 1; i < 33; i++){
            if((m3*i)%33==1){
                t3 = i;
                break;
            }
        }
        //printf("%d %d %d\n",t1,t2,t3);        
    while(scanf("%d %d %d %d",&p,&e, &i, &d) != EOF){
        k++;
        if(p==-1&&e==-1&&i==-1&d==-1){
            break;
        }
        x=924*t1*p+759*t2*e+644*t3*i;
        x = (x-d+21252)%21252;
        if(x==0){
            x = 21252;
        }
        printf("Case %d: the next triple peak occurs in %d days.\n",k, x);
    }

    return 0 ;
}

E题;
E - DNA Sorting
Description
One measure of unsortedness'' in a sequence is the number of pairs of entries that are out of order with respect to each other. For instance, in the letter sequenceDAABEC”, this measure is 5, since D is greater than four letters to its right and E is greater than one letter to its right. This measure is called the number of inversions in the sequence. The sequence AACEDGG'' has only one inversion (E and D)---it is nearly sorted---while the sequenceZWQM” has 6 inversions (it is as unsorted as can be—exactly the reverse of sorted).

You are responsible for cataloguing a sequence of DNA strings (sequences containing only the four letters A, C, G, and T). However, you want to catalog them, not in alphabetical order, but rather in order of sortedness'', frommost sorted” to least sorted''. All the strings are of the same length.
Input
The first line contains two integers: a positive integer n (0 < n <= 50) giving the length of the strings; and a positive integer m (0 < m <= 100) giving the number of strings. These are followed by m lines, each containing a string of length n.
Output
Output the list of input strings, arranged from
most sorted” to “least sorted”. Since two strings can be equally sorted, then output them according to the orginal order.
Sample Input
10 6
AACATGAAGG
TTTTGGCCAA
TTTGGCCAAA
GATCAGATTT
CCCGGGGGGA
ATCGATGCAT
Sample Output
CCCGGGGGGA
AACATGAAGG
GATCAGATTT
ATCGATGCAT
TTTTGGCCAA
TTTGGCCAAA
这题目很有意思,当初看题目看了好久;没看的就没做了,所以这次在做发现还是比较简单的;上次测试数据就搞错了;其实没有读错题;就是找逆序数的个数按升序排列,相同的就按原排序;
一个sort排序解决;

#include<stdio.h>
#include<iostream>  
#include<algorithm>  
using namespace std; 
int n;
struct DNA
{
    int ns;
    char name[105];
}dna[105];
int nxs(int i)
{
    int num=0,j,k,sum=0;
    for(j = 0; j < n-1; j++){
        num = 0;
        for(k = j+1; k < n; k++){
            if(dna[i].name[j]>dna[i].name[k]){
                num++;
            }
        }
        sum += num;
    }
    return sum;
}
bool cmp(DNA x,DNA y)
{
    if(x.ns != y.ns)    return x.ns < y.ns;
    return true;
}
int main()
{
    int m, i;
    while(scanf("%d %d",&n,&m)!=EOF){
        for(i = 0; i < m; i++){
            scanf("%s",dna[i].name);
            dna[i].ns = nxs(i);
        }

        sort(dna,dna+m,cmp);
        for(i = 0; i < m; i++){
            printf("%s\n",dna[i].name);
        }
    }

    return 0 ;
}

F题;
F - Let the Balloon Rise
Description
Contest time again! How excited it is to see balloons floating around. But to tell you a secret, the judges’ favorite time is guessing the most popular problem. When the contest is over, they will count the balloons of each color and find the result.

This year, they decide to leave this lovely job to you.

Input
Input contains multiple test cases. Each test case starts with a number N (0 < N <= 1000) – the total number of balloons distributed. The next N lines contain one color each. The color of a balloon is a string of up to 15 lower-case letters.

A test case with N = 0 terminates the input and this test case is not to be processed.

Output
For each case, print the color of balloon for the most popular problem on a single line. It is guaranteed that there is a unique solution for each test case.

Sample Input
5
green
red
blue
red
red
3
pink
orange
pink
0
找最多字符串的题目;这道题没有严格的要求,所以直接爆力解决了,其实以后学了字典树可以用这个做做;

#include<stdio.h>
#include<string.h>
int main()
{
    char s[1004][17];
    int a[1004];
    int n, i, j, t,max;
    while(scanf("%d",&n) != EOF && n != 0){
        i = 0;
        memset(s,0,sizeof(s));
        memset(a, 0, sizeof(a));
        for(i = 0; i < n; i++)
            scanf("%s",s[i]);
        for(i = 0; i < n; i++){
            for(j = 0;j <n;j++){
                if(strcmp(s[i],s[j])==0){
                    a[i]++;
                }
            }
        }
        max = a[0];
        t=0;
        for(i = 1; i < n;i++){
            if(max < a[i]){
                max = a[i];
                t = i;
            }
        }
        printf("%s\n",s[t]);
    }

    return 0 ;
}

G题;水题;
G - Elevator
Description
The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will stop, in specified order. It costs 6 seconds to move the elevator up one floor, and 4 seconds to move down one floor. The elevator will stay for 5 seconds at each stop.

For a given request list, you are to compute the total time spent to fulfill the requests on the list. The elevator is on the 0th floor at the beginning and does not have to return to the ground floor when the requests are fulfilled.

Input
There are multiple test cases. Each case contains a positive integer N, followed by N positive numbers. All the numbers in the input are less than 100. A test case with N = 0 denotes the end of input. This test case is not to be processed.

Output
Print the total time on a single line for each test case.

Sample Input
1 2
3 2 3 1
0

Sample Output
17
41

#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main()
{
    int a[103];
    int n, i, t, sum;
    while(scanf("%d",&n) != EOF && n != 0){
        for(i = 0; i < n; i++){
            scanf("%d",&a[i]);
        }
        sum = 0;
        sum += (a[0]*6);
        for(i = 1; i < n; i++){
            t = a[i]-a[i-1];
            if(t>0){
                sum += (t*6);
            }
            if(t<0){
                t =abs(t);
                sum += (t*4);
            }
        }
        printf("%d\n",sum+n*5);
    }

    return 0 ;
}

H题;看懂提;其实就是找最大公约数;
Description
Computer simulations often require random numbers. One way to generate pseudo-random numbers is via a function of the form

seed(x+1) = [seed(x) + STEP] % MOD

where ‘%’ is the modulus operator.

Such a function will generate pseudo-random numbers (seed) between 0 and MOD-1. One problem with functions of this form is that they will always generate the same pattern over and over. In order to minimize this effect, selecting the STEP and MOD values carefully can result in a uniform distribution of all values between (and including) 0 and MOD-1.

For example, if STEP = 3 and MOD = 5, the function will generate the series of pseudo-random numbers 0, 3, 1, 4, 2 in a repeating cycle. In this example, all of the numbers between and including 0 and MOD-1 will be generated every MOD iterations of the function. Note that by the nature of the function to generate the same seed(x+1) every time seed(x) occurs means that if a function will generate all the numbers between 0 and MOD-1, it will generate pseudo-random numbers uniformly with every MOD iterations.

If STEP = 15 and MOD = 20, the function generates the series 0, 15, 10, 5 (or any other repeating series if the initial seed is other than 0). This is a poor selection of STEP and MOD because no initial seed will generate all of the numbers from 0 and MOD-1.

Your program will determine if choices of STEP and MOD will generate a uniform distribution of pseudo-random numbers.

Input
Each line of input will contain a pair of integers for STEP and MOD in that order (1 <= STEP, MOD <= 100000).

Output
For each line of input, your program should print the STEP value right- justified in columns 1 through 10, the MOD value right-justified in columns 11 through 2**0 and either “Good Choice” or “Bad Choice” left-justified st**arting in column 25. The “Good Choice” message should be printed when the selection of STEP and MOD will generate all the numbers between and including 0 and MOD-1 when MOD numbers are generated. Otherwise, your program should print the message “Bad Choice”. After each output test set, your program should print exactly one blank line.

Sample Input
3 5
15 20
63923 99999

Sample Output
3 5 Good Choice

    15        20    Bad Choice

 63923     99999    Good Choice 

注意防止PE;最后面的output说明了情况;

#include<stdio.h>
int gcd(int a, int b)
{
    int t;
    while(b!=0){
        t = a%b;
        a = b;
        b = t;
    }
    return a;
}
int main()
{
    int a, b, g;
    while(scanf("%d %d",&a, &b) != EOF){
        g = gcd(a,b);
        printf("%10d%10d",a, b);
        if(g == 1){
            printf("    Good Choice\n");
        }
        else{
            printf("    Bad Choice\n");
        }
        printf("\n");
    }

    return 0 ;
}

I题;水题;sort排序一下就ok了;
I - Who’s in the Middle
Description
FJ is surveying his herd to find the most average cow. He wants to know how much milk this ‘median’ cow gives: half of the cows give as much or more than the median; half give as much or less.

Given an odd number of cows N (1 <= N < 10,000) and their milk output (1..1,000,000), find the median amount of milk given such that at least half the cows give the same amount of milk or more and at least half give the same or less.

Input
* Line 1: A single integer N

  • Lines 2..N+1: Each line contains a single integer that is the milk output of one cow.

Output
* Line 1: A single integer that is the median milk output.

Sample Input
5
2
4
1
3
5

Sample Output
3

#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int n, i,a[10000];
    while(scanf("%d",&n) != EOF){
        for(i = 0; i < n; i++){
            scanf("%d",&a[i]);
        }
        sort(a,a+n);
        printf("%d\n",a[n/2]);
    }

    return 0 ;
}

J题单独分析;
Description
A triangle field is numbered with successive integers in the way shown on the picture below.

The traveller needs to go from the cell with number M to the cell with number N. The traveller is able to enter the cell through cell edges only, he can not travel from cell to cell through vertices. The number of edges the traveller passes makes the length of the traveller’s route.

Write the program to determine the length of the shortest route connecting cells with numbers N and M.

Input
Input contains two integer numbers M and N in the range from 1 to 1000000000 separated with space(s).

Output
Output should contain the length of the shortest route.

Sample Input
6 12

Sample Output
3

#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main()
{
    int a, b, sum;
    int h1,h2,t1,t2,tt1,tt2,wz1,wz2,wy1,wy2;
    while(scanf("%d %d",&a, &b) != EOF){
        h1 = (int)sqrt(a);
        if(h1*h1!=a){
            h1=h1+1;
        }
        h2 = (int)sqrt(b);
        if(h2*h2!=b){
            h2=h2+1;
        }
        t1=h1*h1;
        t2=h2*h2;
        wz1=abs(a-t1)/2+1;
        wz2=abs(b-t2)/2+1;
        tt1=(h1-1)*(h1-1)+1;
        tt2=(h2-1)*(h2-1)+1;
        wy1=abs(a-tt1)/2+1;
        wy2=abs(b-tt2)/2+1;
        sum = abs(wy1-wy2)+abs(wz1-wz2)+abs(h1-h2);
        printf("%d\n",sum);                                                                                                                                          
    }

    return 0 ;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值