SCAU--ACM--team--2019级寒假训练Beginers Problem(一)合集---SCAU--LEO

作为刚进ACM校队的新手,一定量的题目是很有必要的,对于想学算法的同学来说,一定量的题目也是加强算法的好办法。

这里是后面写完补上的!!
终于写完啦哈哈!!
唔,别急,这只是寒假第一周的作业嘞,嗯哼,我们估计要提早一个多星期开学,后面还有更多大的安排,更多的挑战,加油面对哈!!
写完的感觉真的爽,省赛加油!!!

一.A - Hex-a-bonacci

A - Hex-a-bonacci
Given a code (not optimized), and necessary inputs, you have to find the output of the code for the inputs. The code is as follows:
int a, b, c, d, e, f;
int fn( int n ) {
if( n == 0 ) return a;
if( n == 1 ) return b;
if( n == 2 ) return c;
if( n == 3 ) return d;
if( n == 4 ) return e;
if( n == 5 ) return f;
return( fn(n-1) + fn(n-2) + fn(n-3) + fn(n-4) + fn(n-5) + fn(n-6) );
}
int main() {
int n, caseno = 0, cases;
scanf("%d", &cases);
while( cases-- ) {
scanf("%d %d %d %d %d %d %d", &a, &b, &c, &d, &e, &f, &n);
printf(“Case %d: %d\n”, ++caseno, fn(n) % 10000007);
}
return 0;
}
Input
Input starts with an integer T (≤ 100), denoting the number of test cases.

Each case contains seven integers, a, b, c, d, e, f and n. All integers will be non-negative and 0 ≤ n ≤ 10000 and the each of the others will be fit into a 32-bit integer.

Output
For each case, print the output of the given code. The given code may have integer overflow problem in the compiler, so be careful.

Sample Input
5

0 1 2 3 4 5 20

3 2 1 5 0 1 9

4 12 9 4 5 6 15

9 8 7 6 5 4 3

3 4 3 2 54 5 4

Sample Output
Case 1: 216339

Case 2: 79

Case 3: 16636

Case 4: 6

Case 5: 54

我对题目的理解与思路

首先看到这道题目的时候,应该已经知道了,这题就是优化代码,原代码是正确的但是会超时,不难发现,对于一个大于6的数他的值等于前6个数之和,所以这题可以这样写。
1.创建一个数组(稍微比n的值大一点),用来存每个数对应的值。
2.将0–5的数全部存入数组,然后两个循环,第一个循环是从6开始到n,第二个循环是从i-6开始到i,累加和。(注意此处,对于累加的过程和结果都要求余)
3.输出a[n],即得正确结果。

代码如下

#include<stdio.h>
int a, b, c, d, e, f;
int main() {
   
    int n, caseno = 0, cases;
    scanf("%d", &cases);
    while( cases-- ) {
   
        scanf("%d %d %d %d %d %d %d", &a, &b, &c, &d, &e, &f, &n);
        long long g[10003]={
   0};
        g[0]=a;g[1]=b;g[2]=c;g[3]=d;g[4]=e;g[5]=f;
        for(int i=6;i<=n;i++)
        {
   
            for(int j=i-6;j<i;j++)
            {
   
                g[i]=(g[i]%10000007+g[j]%10000007)% 10000007;
            }
        }
        printf("Case %d: %d\n", ++caseno, g[n] % 10000007);
    }
    return 0;
}

所以本题的思想就是打一个表,直接输出答案,可能会有更好的算法,如果有更好的算法,欢迎楼下留言~~~

二.J - Division by 3

There is sequence 1, 12, 123, 1234, …, 12345678910, … . Now you are given two integers A and B, you have to find the number of integers from Ath number to Bth (inclusive) number, which are divisible by 3.

For example, let A = 3. B = 5. So, the numbers in the sequence are, 123, 1234, 12345. And 123, 12345 are divisible by 3. So, the result is 2.

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

Each case contains two integers A and B (1 ≤ A ≤ B < 231) in a line.

Output
For each case, print the case number and the total numbers in the sequence between Ath and Bth which are divisible by 3.

Sample Input
2

3 5

10 110

Sample Output
Case 1: 2

Case 2: 67

个人理解和解题方法。

对于这题,有两种判断方法,第一种:求各个位数的和,可以发现,每3个数中就会有两个可以被3整除。第二种:找规律,将情况列出几种出来,不难发现,规律和上面一样。所以这题就很简单了,直接套公式。
1.首先,将(a-1)和b分别除3再乘2,可以知道里面最少的可以被3整除的个数。(至于为什么是a-1,是因为要避免边界带来的麻烦)

2.对于b再进行一次判断,判断它被3求余后是否等于2,若为2的话能被3整除的个数就加一。具体原理我举个例子,比如说3,4,5.
5能被3求余得2,5/3*2后得到的是前3项对应的可以被3整除的个数,因为由规律不难发现每次若出现余2则个数加1,所以要加1.

3.将得到的个数相减即是答案。

代码如下

#include<stdio.h>
int main()
{
   
    int T;
    scanf("%d",&T);
    int i=1;
    while(T--)
    {
   
        int a,b;
        scanf("%d%d",&a,&b);
        a=a-1;
        int numa=0,numb=0;
        numa=a/3*2;
        if(a%3==2)
            numa++;
        numb=b/3*2;
        if(b%3==2)
            numb++;
        printf("Case %d: %d\n",i,numb-numa);
        i++;
    }
    return 0;
}

三.Circle in Square

A circle is placed perfectly into a square. The term perfectly placed means that each side of the square is touched by the circle, but the circle doesn’t have any overlapping part with the square. See the picture below.
在这里插入图片描述
Now you are given the radius of the circle. You have to find the area of the shaded region (blue part). Assume that pi = 2 * acos (0.0) (acos means cos inverse).
Input
Input starts with an integer T (≤ 1000), denoting the number of test cases.

Each case contains a floating point number r (0 < r ≤ 1000) denoting the radius of the circle. And you can assume that r contains at most four digits after the decimal point.

Output
For each case, print the case number and the shaded area rounded to two places after the decimal point.

Sample Input
3

20

30.091

87.0921

Sample Output
Case 1: 343.36

Case 2: 777.26

Case 3: 6511.05

Note
This problem doesn’t have special judge. So, be careful about precision problems. Better to add a small value to your result to avoid precision problems. For example, add 10-9 to your result.

个人理解和方法

这道题目可以说是一道学过C语言的人都会写的题,但是有几个坑点,首先注意题目后面说的精度问题,所以在计算结果后面要加上1e-9.
本题就是一个公式解决:s=2r2r-2acos(0.0)rr+1e-9;
具体为什么是这样,还请重回初中学习数学知识。
代码如下

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
   
    int T,i=1;
    cin>>T;
    while(T--)
    {
   
        double r,s;
        cin>>r;
        s=2*r*2*r-2*acos(0.0)*r*r+1e-9;
        printf("Case %d: %.2lf\n",i,s);
        i++;
    }
    return 0;
}

四.Ekka Dokka

Ekka and his friend Dokka decided to buy a cake. They both love cakes and that’s why they want to share the cake after buying it. As the name suggested that Ekka is very fond of odd numbers and Dokka is very fond of even numbers, they want to divide the cake such that Ekka gets a share of N square centimeters and Dokka gets a share of M square centimeters where N is odd and M is even. Both N and M are positive integers.

They want to divide the cake such that N * M = W, where W is the dashing factor set by them. Now you know their dashing factor, you have to find whether they can buy the desired cake or not.

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

Each case contains an integer W (2 ≤ W < 263). And W will not be a power of 2.

Output
For each case, print the case number first. After that print “Impossible” if they can’t buy their desired cake. If they can buy such a cake, you have to print N and M. If there are multiple solutions, then print the result where M is as small as possible.

Sample Input
3

10

5

12

Sample Output
Case 1: 5 2

Case 2: Impossible

Case 3: 3 4

个人理解和方法

这题很明显是用暴力,但是要注意以下几点,因为奇数和偶数相乘一定是偶数,所以如果W是奇数就直接输出impossible;还要注意,如果有多个答案的话,就输出偶数为最小的那一组,所以我们暴力的时候,从偶数小的到偶数大的开始找;
方法:
1.首先判断W是否为奇数,若为奇数,输出impossible,建议判断奇偶性用位运算,即M&1(若为奇数则返回true,若为偶数则返回false。)
2.接下来的情况都是偶数的情况,因为2是偶数的一个因子,所以我们直接从2开始找,判断M/2是否为奇数,且M/22是否等于M,若满足以上两个条件则输出答案,若不满足则将偶数数字2,继续找。

要注意的点有,这题必须用longlong,否则会溢出。
代码如下:

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
#define ll long long
bool flag=true;
int main()
{
   
    int T,i=1;
    cin>>T;
    while(T--)
    {
   
         ll M;
         cin>>M;
         if(M&1) printf("Case %d: Impossible\n",i);
         else
         {
   
             for(ll j=2;j<=M/2;j=j*2)
             {
   
                 if(((M/j)&1)&&(M/j*j==M))
                 {
   
                     printf("Case %d: %lld %lld\n",i,M/j,j);
                     flag=false;
                     break;
                 }
             }
             if(flag) {
   
                    printf("Case %d: 1 %lld\n",i,M);
             flag=true;
             }
         }
        i++;
    }
    return 0;
}

五.S - Hidden Secret!

In this problem you are given two names, you have to find whether one name is hidden into another. The restrictions are:

  1.  You can change some uppercase letters to lower case and vice versa.
    
  2.  You can add/remove spaces freely.
    
  3.  You can permute the letters.
    

And if two names match exactly, then you can say that one name is hidden into another.

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

Each case starts with two lines. Each line contains a name consists of upper/lower case English letters and spaces. You can assume that the length of any name is between 1 and 100 (inclusive).

Output
For each case, print the case number and “Yes” if one name is hidden into another. Otherwise print “No”.

Sample Input
3

Tom Marvolo Riddle

I am Lord Voldemort

I am not Harry Potter

Hi Pretty Roar to man

Harry and Voldemort

Tom and Jerry and Harry

Sample Output
Case 1: Yes

Case 2: Yes

Case 3: No

个人理解和方法

首先呢,这题打大概意思是能否通过以下三个步骤使得两个字符串相同,
1.删除或增加若干个空格
2.交换字母顺序
3.字母可以从大写变小写或者从小写变大写。

方法:
1.对于第一种操作,我们可以看成,整个字符串没有空格。
2.对于第3个操作我们可以将大写字母全部转换为小写字母,以便处理方便。
3.对于交换顺序后是否相等,我们可以统计字母的个数是否相等。
所以综上,这题可以转换为统计单词个数,个数相等就输出yes否则输出no。

代码如下:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<queue>
#include<cstring>
#include<string>
using namespace std;
#define ll long long
bool flag=true;
int main()
{
   
    int T,k=1;
    cin>>T;
    getchar();
    while(T--){
   
    string a,b;
    int c[150]={
   0},d[150]={
   0};
    int lena,lenb;
       getline(cin,a);
       getline(cin,b);
       for(int i=0;i<=a.size();i++){
   
           if(a[i]!=' '&&a[i]!='\0'){
   
                if(a[i]<97) a[i]+=32;
               c[a[i]]++;
           }
       }
       for(int i=0;i<=b.size();i++){
   
           if(b[i]!=' '&&b[i]!='\0'){
   
                if(b[i]<97) b[i]+=32;
               d[b[i]]++;
           }
       }
       for(int i=97;i<=122;i++)
           if(c[i]!=d[i]) flag=false;

       if(flag) printf("Case %d: Yes\n",k);
       else{
   
           printf("Case %d: No\n",k);
           flag=true;
       }
       k++;
    }
    return 0;
}

六.Calm Down

George B. wants to be more than just a good American. He wants to make his daddy proud and become a hero. You know, like Shakib Khan.

But sneaky as he is, he wants a special revolver that will allow him to shoot more often than just the usual six times. This way he can fool and kill the enemy easily (at least that’s what he thinks, and that’s the best he can think). George has kidnapped . . . uh, I mean . . . “invited” you and will only let you go if you help him with the math. The piece of the revolver that contains the bullets looks like this (examples for 6 and 17 bullets):
在这里插入图片描述
There is a large circle with radius R and n little circles each having radius r, are placed inside on the border of the large circle. George wants his bullets to be as large as possible, so there should be no space between the circles. George will decide how large the whole revolver will be and how many bullets it shall contain. Your job is, given R and n, to compute r. You have decided to help, because you know that an idiot can’t make a revolver even if you help him with the math.

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

Each case contains a real number R (0 < R < 1000 and contains up to at most two places after the decimal point) and an integer n (2 ≤ n ≤ 100).

Output
For each test case, print the case number and r in a single line. Errors less than 10-6 will be ignored.

Sample Input
4

4.0 6

4.0 17

3.14 100

42 2

Sample Output
Case 1: 1.3333333333

Case 2: 0.6209067545

Case 3: 0.0956260953

Case 4: 21

个人理解与做法

这道题目就是一个普通的数学问题,可以通过作图发现
r=sin(pai/n)*R/(1+sin(pai/n))。
代码如下

#include<iostream>
#include<cstdio>
#include<cmath>
#include<queue>
#include<cstring>
#include<string>
using namespace std;
#define ll long long
#define pai acos(-1.0)
int main()
{
   
    int T,k=1;
    cin>>T;
    while(T--){
   

        int n;
        double R,r;
        cin>>R>>n;
        r=sin(pai/n)*R/(1+sin(pai/n));
        printf("Case %d: %.10lf\n",k,r);
        k++;
    }
    return 0;
}

七.Agent J

Agent J is preparing to steal an antique diamond piece from a museum. As it is fully guarded and they are guarding it using high technologies, it’s not easy to steal the piece. There are three circular laser scanners in the museum which are the main headache for Agent J. The scanners are centered in a certain position, and they keep rotating maintaining a certain radius. And they are placed such that their coverage areas touch each other as shown in the picture below:
在这里插入图片描述
Here R1, R2 and R3 are the radii of the coverage areas of the three laser scanners. The diamond is placed in the place blue shaded region as in the picture. Now your task is to find the area of this region for Agent J, as he needs to know where he should land to steal the diamond.
Input
Input starts with an integer T (≤ 1000), denoting the number of test cases.

Each case starts with a line containing three real numbers denoting R1, R2 and R3 (0 < R1, R2, R3 ≤ 100). And no number contains more than two digits after the decimal point.

Output
For each case, print the case number and the area of the place where the diamond piece is located. Error less than 10-6 will be ignored.

Sample Input
3

1.0 1.0 1.0

2 2 2

3 3 3

Sample Output
Case 1: 0.16125448

Case 2: 0.645017923

Case 3: 1.4512903270

简单说下个人思路和做法

这题的意思很明显,就是让你算蓝色部分的面积,做法就是将三个圆的圆心连起来,用三角形的面积减去三个扇形的面积,三角形的面积可以通过海伦公式算出,公式:p=(a+b+c)/2,
S=sqrt(p*(p-a)(p-b)(p-c));
扇形的面积可以通过公式S=1/2*(弧度)rr;
有人也许会问弧度怎么算,下面给出方法,由数学方法可以知道
arcos(cos)算出来的是弧度,那么cos可以通过三角函数算出,因为三边已知。

下面给出代码

#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
#define pai acos(-1.0)
int main()
{
   
    int T,k=1;
    cin>>T;
    while(T--)
    {
   
        double R1,R2,R3,a,b,c,S,cos1,cos2,cos3;
        cin>>R1>>R2>>R3;
        a=R1+R3;
        b=R1+R2;
        c=R2+R3;
        cos1=(a*a+b*b-c*c)/(2*a*b);
        cos2=(c*c+b*b-
  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 5
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

_春与修罗

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值