LSNU_ACM三月月赛小组总结

题目链接:https://vjudge.net/contest/290592

前言:

从比赛题目上看,三月月赛的题目难度不是很大,主要包含数学、大数加法(高精度)、简单DP(C、D题除外);

从比赛结果上看,我们小组通过了7/10的题,其中I题用的Java大数处理,E题是之前比赛做过的原题(水题);

从比赛过程中看,我们小组经过7个月的磨合,每个人都配合的很好,分工明确,比如有时候我们一起讨论出一个题并有大体思路时,凯文就写代码,丹姐在旁边检查,而我就去寻觅下一个能解的题;有时候也会交换敲代码,说实话,我很喜欢这样小组一起看题、一起解题、一起讨论的感觉。

A题-Dick and Jane(ZOJ 1110)

Dick is 12 years old. When we say this, we mean that it is at least twelve and not yet thirteen years since Dick was born.

Dick and Jane have three pets: Spot the dog, Puff the Cat, and Yertle the Turtle. Spot was s years old when Puff was born; Puff was p years old when Yertle was born; Spot was y years old when Yertle was born. The sum of Spot's age, Puff's age, and Yertle's age equals the sum of Dick's age (d) and Jane's age (j). How old are Spot, Puff, and Yertle?

Each input line contains four non-negative integers: s, p, y, j. For each input line, print a line containing three integers: Spot's age, Puff's age, and Yertle's age. Ages are given in years, as described in the first paragraph.

Sample Input

5 5 10 9
5 5 10 10
5 5 11 10

Output for Sample Input

12 7 2
13 7 2
13 7 2

转载:http://blog.sina.com.cn/s/blog_d0fededb0101f67s.html

 B题-Let the Balloon Rise(ZOJ 2104)

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

Sample Output
red
pink

题目分析:

B题的题意很简单,就是求出现次数最多的一种颜色(字符串),我们第一想法就是用结构体数组来做,其中包括一个字符数组来存输入的字符串,一个int变量实时存储出现的次数。

每输入一个字符串就存储下来,并与之前所有已存的字符串作比较,一旦找到相同的串,其num++且跳出for循环;所有数据输入结束后用sort函数对结构体数组中num值进行从大到小排序,排完序后第一个数组中的字符串就是出现次数最多的。

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct f{
  char name[30];
  int num;
}x[1005];
bool cmp(struct f x,struct f y)
{
    return x.num>y.num;
}
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        if(n==0)
            break;
        for(int i=0;i<n;i++)
            x[i].num=0;
        for(int i=0;i<n;i++){
            scanf("%s",x[i].name);
            int tag=0;   //tag的作用主要是用于存储第一个字符串
            for(int j=0;j<i;j++){
                if(strcmp(x[i].name,x[j].name)==0){
                    x[j].num++;
                    tag=1;
                    break;
                }
            }
            if(!tag)
                x[i].num=1;
        }
        sort(x,x+n,cmp);
        printf("%s\n",x[0].name);
    }
    return 0;
}

E题 - Keep on Truckin'(HDU 1037)

Boudreaux and Thibodeaux are on the road again . . . 
"Boudreaux, we have to get this shipment of mudbugs to Baton Rouge by tonight!" 
"Don't worry, Thibodeaux, I already checked ahead. There are three underpasses and our 18-wheeler will fit through all of them, so just keep that motor running!" 
"We're not going to make it, I say!" 
So, which is it: will there be a very messy accident on Interstate 10, or is Thibodeaux just letting the sound of his own wheels drive him crazy? 

Input

Input to this problem will consist of a single data set. The data set will be formatted according to the following description. 
The data set will consist of a single line containing 3 numbers, separated by single spaces. Each number represents the height of a single underpass in inches. Each number will be between 0 and 300 inclusive. 

Output

There will be exactly one line of output. This line will be: 
   NO CRASH 
if the height of the 18-wheeler is less than the height of each of the underpasses, or: 
   CRASH X 
otherwise, where X is the height of the first underpass in the data set that the 18-wheeler is unable to go under (which means its height is less than or equal to the height of the 18-wheeler). 
The height of the 18-wheeler is 168 inches. 

Sample Input

180 160 170

Sample Output

CRASH 160

题目分析:

水题,只要把题意理解清楚就可以了,题意大致是,输入三个数,如果三个数全部都大于168,则输出“NO CRASH ”,如果小于等于168,则输出“CRASH +该数”。

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
        int a[3];
        int flag = 0;
        scanf("%d%d%d", &a[0], &a[1], &a[2]);
        for(int i = 0; i <3; ++i){
            if(a[i] <= 168){
                printf("CRASH %d\n", a[i]);
                flag = 1;
            }
        }
        if(!flag)
            printf("NO CRASH\n");

    return 0;
}

 

F题-Climbing Worm(HDU 1049)

An inch worm is at the bottom of a well n inches deep. It has enough energy to climb u inches every minute, but then has to rest a minute before climbing again. During the rest, it slips down d inches. The process of climbing and resting then repeats. How long before the worm climbs out of the well? We'll always count a portion of a minute as a whole minute and if the worm just reaches the top of the well at the end of its climbing, we'll assume the worm makes it out. 

Input

There will be multiple problem instances. Each line will contain 3 positive integers n, u and d. These give the values mentioned in the paragraph above. Furthermore, you may assume d < u and n < 100. A value of n = 0 indicates end of output. 

Output

Each input instance should generate a single integer on a line, indicating the number of minutes it takes for the worm to climb out of the well. 

Sample Input

10 2 1
20 3 1
0 0 0

Sample Output

17
19

题目分析:

简单题,题意大致是,深度为n的井底有一只虫,向上爬u需要1分钟,每次向上爬完都要休息1分钟,休息期间下滑d,求该虫爬出井需要多长时间。

#include<cstdio>
using namespace std;
int main()
{
    int n,u,d;
    while(~scanf("%d %d %d",&n,&u,&d)){
        if(n==0 && u==0 && d==0)
            break;
        else{
           int tag=0;
           int num=0;
           while(n>0){
               if(tag==0) {
                   n-=u;
                   tag=1;
               }
               else{
                   n+=d;
                   tag=0;
               }
               num++;
           }
           printf("%d\n",num);
        }
    }
    return 0;
}

G题 - Tiling_easy version(HDU 2501)

有一个大小是 2 x n 的网格,现在需要用2种规格的骨牌铺满,骨牌规格分别是 2 x 1 和 2 x 2,请计算一共有多少种铺设的方法。 

Input

输入的第一行包含一个正整数T(T<=20),表示一共有 T组数据,接着是T行数据,每行包含一个正整数N(N<=30),表示网格的大小是2行N列。 

Output

输出一共有多少种铺设的方法,每组数据的输出占一行。 

Sample Input

3
2
8
12

Sample Output

3
171
2731

题目分析: 

递推题,现有两种骨牌,N为1时答案为1,N为2是答案为3;从N=3开始,先考虑后边,如果最后放2*1的骨牌,那么有a[n-1]种放法;如果最后放2*2的骨牌,有可能放两个横着的2*1的骨牌,也有可能是一个2*2的骨牌,所以共有2*a[n-2]种放法,故递推式为a[n]=a[n-1]+2*a[n-2]。

#include<cstdio>
using namespace std;
int a[100];
void init()
{
    a[1]=1;
    a[2]=3;
    for(int i =3;i<35;i++)
        a[i] = a[i-1]+a[i-2]*2;
}
int main()
{
    int n;
    init();
    scanf("%d",&n);
    while(n--){
        int x;
        scanf("%d",&x);
        printf("%d\n",a[x]);
    }
    return 0;
}

H题 - Least Common Multiple(ZOJ 1797)

The least common multiple (LCM) of a set of positive integers is the smallest positive integer which is divisible by all the numbers in the set. For example, the LCM of 5, 7 and 15 is 105.

Input

Input will consist of multiple problem instances. The first line of the input will contain a single integer indicating the number of problem instances. Each instance will consist of a single line of the form m n1 n2 n3 ... nm where m is the number of integers in the set and n1 ... nm are the integers. All integers will be positive and lie within the range of a 32-bit integer.

Output

For each problem instance, output a single line containing the corresponding LCM. All results will lie in the range of a 32-bit integer.

Sample Input

2
3 5 7 15
6 4 10296 936 1287 792 1

Sample Output

105
10296

题目分析:

这个题主要是对最小公倍数的应用,题意是求所有数的最小公倍数。

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a[100000];
int f(int x, int y)
{
    int t;

    if(x < y){
        t = x;
        x = y;
        y = t;
    }
    int b = y;
    int a = x;
    while(x % y){
        int temp = x % y;
        x = y;
        y = temp;
    }
    return a / y * b;

}
int main()
{
   int n;
   scanf("%d",&n);
   while(n--){
    int t;
    scanf("%d",&t);
    for(int i =0;i<t;i++)
        scanf("%d",&a[i]);

    int res = a[0];
    for(int i = 1;i < t;i++)
        res = f(res, a[i]);

    printf("%d\n", res);
   }
    return 0;
}

I题 - 大明A+B(HDU 1753)

话说,经过了漫长的一个多月,小明已经成长了许多,所以他改了一个名字叫“大明”。 
这时他已经不是那个只会做100以内加法的那个“小明”了,现在他甚至会任意长度的正小数的加法。 
现在,给你两个正的小数A和B,你的任务是代表大明计算出A+B的值。 

Input

本题目包含多组测试数据,请处理到文件结束。 
每一组测试数据在一行里面包含两个长度不大于400的正小数A和B。

Output

请在一行里面输出输出A+B的值,请输出最简形式。详细要求请见Sample Output。 

Sample Input

1.1 2.9
1.1111111111 2.3444323343
1 1.1

Sample Output

4
3.4555434454
2.1

题目分析: 

这个题题意很简单,就是两个数求和,但是存在以下问题:1、数的位数最长可达到400位;2、答案要最简(无多余的后缀0和小数点)。我们的第一想法就是用Java中的大数来处理,但是答案最简还需要做处理(转化为字符数组,从后向前找到第一个不为0、不为‘.’的位数并标记,最后从前往后输出字符串)。这个题我们W了三次,主要是情况没有考虑完全。

其实对于后缀的处理,Java中方法解决,只是我们之前不知道而已,如下:

 System.out.println(a.add(b).stripTrailingZeros().toPlainString());
import java.math.BigDecimal;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			BigDecimal a = sc.nextBigDecimal();
			BigDecimal b = sc.nextBigDecimal();
			BigDecimal c = a.add(b);
			String s = String.valueOf(c);
			if("0".equals(s)){
				System.out.println(0);
				continue;
			}
			if(s.endsWith("0")&& s.contains(".")){
				char x[] = s.toCharArray();
				int len = x.length -1;
				
				while(x[len - 1] == '0'){
					len--;
				}
				
				if(x[len - 1] == '.')
					len--;
				for(int i = 0; i < len; ++i){	
					System.out.printf("%c", x[i]);
				}
				System.out.println();
			}
			else{
				System.out.println(s);
			}

		}

	}

}

J题 - MagicBuilding(HDU 2192)

As the increase of population, the living space for people is becoming smaller and smaller. In MagicStar the problem is much worse. Dr. Mathematica is trying to save land by clustering buildings and then we call the set of buildings MagicBuilding. Now we can treat the buildings as a square of size d, and the height doesn't matter. Buildings of d1,d2,d3....dn can be clustered into one MagicBuilding if they satisfy di != dj(i != j). 
Given a series of buildings size , you need to calculate the minimal numbers of MagicBuildings that can be made. Note that one building can also be considered as a MagicBuilding. 
Suppose there are five buildings : 1, 2, 2, 3, 3. We make three MagicBuildings (1,3), (2,3), (2) .And we can also make two MagicBuilding :(1,2,3), (2,3). There is at least two MagicBuildings obviously.

Input

The first line of the input is a single number t, indicating the number of test cases. 
Each test case starts by n (1≤n≤10^4) in a line indicating the number of buildings. Next n positive numbers (less than 2^31) will be the size of the buildings.

Output

For each test case , output a number perline, meaning the minimal number of the MagicBuilding that can be made.

Sample Input

2
1
2 
5
1 2 2 3 3

Sample Output

1
2

题目分析: 

本题的意思大致是输入n个数,把这些数分成尽可能少的组,分组的唯一条件就是“每组中不能有相同的数存在”,求那一种分法中的组数最少。

这个题我们最开始的想法是,将每个数出现的次数计算出来,每一次将每个数减一,sum++,直到出现次数最少的那个数减为0,那么此时的sum就是所求的答案;但是有个问题是,n的取值可以达到10的4次方,计算次数+遍历完后应该会超时;

然后我们又想到用数组标记法,输入的时候就记录每个数的次数,但是在后面遍历(双for)还是会超时;

最后,我们发现这个题有规律,每一次的答案都是出现最多的数的次数,我们想到的是用数组存入数据,sort排序,这样保证相同的数排在一起,之后用sum记录每个相同数出现的次数,Max记录最大值,Max即是答案。

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int main()
{
    int n;
    scanf("%d", &n);
    while(n--){
        int a[10010];
        int m;

        scanf("%d", &m);

        for(int i = 0;i < m; ++i)
            scanf("%d", &a[i]);

        sort(a, a + m);
        int Max = 1;
        int sum = 1;
        for(int i = 0; i < m - 1; ++i){
            if(a[i] == a[i + 1])
                sum++;
            else{
                if(sum > Max)
                    Max = sum;
                sum = 1;
            }
        }
        if(sum > Max)
            Max =sum;

        printf("%d\n", Max);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ava实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),可运行高分资源 Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现的毕业设计&&课程设计(包含运行文档+数据库+前后端代码),Java实现
C语言是一种广泛使用的编程语言,它具有高效、灵活、可移植性强等特点,被广泛应用于操作系统、嵌入式系统、数据库、编译器等领域的开发。C语言的基本语法包括变量、数据类型、运算符、控制结构(如if语句、循环语句等)、函数、指针等。下面详细介绍C语言的基本概念和语法。 1. 变量和数据类型 在C语言中,变量用于存储数据,数据类型用于定义变量的类型和范围。C语言支持多种数据类型,包括基本数据类型(如int、float、char等)和复合数据类型(如结构体、联合等)。 2. 运算符 C语言中常用的运算符包括算术运算符(如+、、、/等)、关系运算符(如==、!=、、=、<、<=等)、逻辑运算符(如&&、||、!等)。此外,还有位运算符(如&、|、^等)和指针运算符(如、等)。 3. 控制结构 C语言中常用的控制结构包括if语句、循环语句(如for、while等)和switch语句。通过这些控制结构,可以实现程序的分支、循环和多路选择等功能。 4. 函数 函数是C语言中用于封装代码的单元,可以实现代码的复用和模块化。C语言中定义函数使用关键字“void”或返回值类型(如int、float等),并通过“{”和“}”括起来的代码块来实现函数的功能。 5. 指针 指针是C语言中用于存储变量地址的变量。通过指针,可以实现对内存的间接访问和修改。C语言中定义指针使用星号()符号,指向数组、字符串和结构体等数据结构时,还需要注意数组名和字符串常量的特殊性质。 6. 数组和字符串 数组是C语言中用于存储同类型数据的结构,可以通过索引访问和修改数组中的元素。字符串是C语言中用于存储文本数据的特殊类型,通常以字符串常量的形式出现,用双引号("...")括起来,末尾自动添加'\0'字符。 7. 结构体和联合 结构体和联合是C语言中用于存储不同类型数据的复合数据类型。结构体由多个成员组成,每个成员可以是不同的数据类型;联合由多个变量组成,它们共用同一块内存空间。通过结构体和联合,可以实现数据的封装和抽象。 8. 文件操作 C语言中通过文件操作函数(如fopen、fclose、fread、fwrite等)实现对文件的读写操作。文件操作函数通常返回文件指针,用于表示打开的文件。通过文件指针,可以进行文件的定位、读写等操作。 总之,C语言是一种功能强大、灵活高效的编程语言,广泛应用于各种领域。掌握C语言的基本语法和数据结构,可以为编程学习和实践打下坚实的基础。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值