2021-01-14

问题 A: 平均值I

时间限制: 1 Sec  内存限制: 128 MB
提交 状态

题目描述

豆豆从小对数字很敏感,小学里就显露出超常的能力,老师为了防止他太过骄傲,给了他一个可怕的难题:求一串给定整数某一段的平均值,保留3位小数。每个整数都是小于231的。老师做梦也没想到豆豆全都回答出来了,原来豆豆有一个擅长编程的朋友你。
 

输入

第一行一个整数N(1<=N<=100000),表示一串整数的个数;
第二行用空格隔开的N个非负整数;
第三行一个整数M(1<=M<=100000),表示M次询问;
接下来M行,每行两个整数i和j(1<=i,j<=N),表示询问第i个到第j个整数的平均值,不保证i<j。

输出

M行,每行一个小数,表示平均值,要求小数点后面保留3位输出。

样例输入 Copy

5 
0 25 0 23 2 
1 
1 5

样例输出 Copy

10.000

提示

数据保证N个整数和小于263

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <algorithm>
#include <iostream>

using namespace std;

long long a[100005] = {0};

int main()
{
    ios::sync_with_stdio(false),cin.tie(NULL);
    int n;
    cin>>n;

    long long temp;
    for(int i = 1; i <= n; i++)
    {
        cin>>temp;
        a[i] = a[i - 1] + temp;
    }

    int m;
    cin>>m;
    for(int i = 1; i <= m; i++)
    {
        int s,e;
        cin>>s>>e;
        if(s > e) swap(s, e);

        long long ans = a[e] - a[s - 1];

        double vis = (ans * 1.0)/(e - s + 1);

        printf("%.3lf\n",vis);
    }

    return 0;
}

 

问题 C: 找画笔

时间限制: 1 Sec  内存限制: 128 MB
提交 状态

题目描述

Cherrydjt对数字的执着,让他在理科领域游刃有余,但他近乎疯狂的投入也使父母有些担心,为了让孩子能够全面发展,决定拓宽他的学习领域,正好家旁边有个绘画培训中心就给Cherrydjt报了名,学习绘画的第一天就让Cherrydjt产生了浓厚的兴趣,还主动要求买了很多很多的画笔,画笔有多种颜色,Cherrydjt有一个习惯就是同种颜色的画笔就买两支,一支备用,就这样总共攒了N支画笔(N是偶数且1<N<10^6)。 可是数字的敏感无孔不入,Cherrydjt脑里蹦出了一个奇怪的问题:如果蒙上眼任意拿走一支画笔,分析剩下的N-1支画笔找出拿走了哪种颜色,你能回答他吗?

输入

第一行一个整数表示剩下的画笔个数就是题目描述中的N-1
第二行N-1个用空格隔开的正整数Ai(1<=Ai<231),表示剩下的画笔的颜色编号

注意:数据保证有一个画笔的颜色编号出现了一次,其余的都出现了两次
 

输出

一行一个整数P,表示拿走的画笔的颜色编号。

样例输入 Copy

9 
1 1 9 11 5 3 11 5 9

样例输出 Copy

3

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <algorithm>
#include <iostream>

using namespace std;

int main()
{
    ios::sync_with_stdio(false),cin.tie(NULL);
    int n;
    cin>>n;

    long long ans = 0;
    for(int i = 1; i <= n; i++)
    {
        long long temp;
        cin>>temp;
        ans = ans ^ temp;
    }
    cout<<ans<<endl;

    return 0;
}

 

问题 E: 打印图形V

时间限制: 1 Sec  内存限制: 128 MB
提交 状态

题目描述

由键盘输入任意一个自然数N,输出如下图规律的图形。

输入

只有一个整数N,为图形的行数(其中2<=N<=26)

输出

输出指定格式的图形。

样例输入 Copy

4

样例输出 Copy

   D
  DCD
 DCBCD
DCBABCD
 DCBCD
  DCD
   D

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <algorithm>
#include <iostream>

using namespace std;

int main()
{
    ios::sync_with_stdio(false),cin.tie(NULL);
    int n;
    cin>>n;

    for(int i = 1; i <= n - 1; i++)
    {
        int k = n - i;
        while(k--) cout<<' ';

        for(int j = n-1; j >= n-i; j--)
        {
            char c = 'A' + j;
            cout<<c;
        }

        for(int j = n-i+1; j <= n-1; j++)
        {
            char c = 'A' + j;
            cout<<c;
        }
        cout<<endl;
    }

    for(int j = n-1; j >= 0; j--)
    {
        char c = 'A' + j;
        cout<<c;
    }
    for(int j = 1; j <= n-1; j++)
    {
        char c = 'A' + j;
        cout<<c;
    }
    cout<<endl;

    for(int i = n-1; i >= 1; i--)
    {
        int k = n - i;
        while(k--) cout<<' ';

        for(int j = n-1; j >= n-i; j--)
        {
            char c = 'A' + j;
            cout<<c;
        }

        for(int j = n - i + 1; j <= n-1; j++)
        {
            char c = 'A' + j;
            cout<<c;
        }
        cout<<endl;
    }

    return 0;
}

 

问题 F: 数列计算IV

时间限制: 1 Sec  内存限制: 128 MB
提交 状态

题目描述

有一个分数序列是:1/2,2/3,3/5,5/8,8/13,13/21.. ...,请同学们认真观察好分子和分母的规律。现要求:指定项数为任意的N项,请输出前N项。

输入

只有一行,包含1个整数N(其中2≤N≤20)为这个分数序列的项数。

输出

请输出这个分数序列的分数形式(请注意显示形式突出序列变化的规律,所以不用化简)。

样例输入 Copy

6

样例输出 Copy

1/2 2/3 3/5 5/8 8/13 13/21

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <algorithm>
#include <iostream>

using namespace std;

int main()
{
    ios::sync_with_stdio(false),cin.tie(NULL);

    int a[25] = {0};
    int b[25] = {0};
    a[1] = 1; b[1] = 2;
    a[2] = 2; b[2] = 3;
    for(int i = 3; i <= 20; i++)
    {
        a[i] = a[i - 1] + a[i - 2];
        b[i] = b[i - 1] + b[i - 2];
    }
    
    int n;
    cin>>n;
    for(int i = 1; i <= n; i++)
    {
        cout<<a[i]<<'/'<<b[i];
        
        if(i == n)
            cout<<endl;
        else
            cout<<' ';
    }

    return 0;
}

 

问题 G: 完全平方数II

时间限制: 1 Sec  内存限制: 128 MB
提交 状态

题目描述

一个数如果是另一个整数的完全平方,那么我们就称这个数为完全平方数。如25,36,49,……121,144,225,361,400,441,484,……961等。现要求在三位整数中找出具有这样一些特点的数:
(1)它们是完全平方数;
(2)三位数字中有两位数字相同。
例如144、225、400、676等。
求出任意自然数M ~N之间所有满足上述条件的数,并统计这样的数的个数。

 

输入

只有一行,包含两个用空格隔开的任意自然数M和N(其中100<=M<N<=999)。

输出

共有若干行:前若干行每行一个整数是任意自然数M~N之间所有满足条件的平方数;最后一行是统计这些平方数的个数。若没有满足条件的完全平方数,直接输0。

样例输入 Copy

100 300

样例输出 Copy

100
121
144
225
4

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <algorithm>
#include <iostream>

using namespace std;

bool f1(int x)
{
    for(int i = 10; i <= 31; i++)
    {
        if(x == i * i) return true;
    }
    return false;
}

bool f2(int x)
{
    int a = x / 100;
    int b = (x % 100) / 10;
    int c = x % 10;

    if((a == b) || (a == c) || (b == c)) return true;

    return false;
}

int main()
{
    ios::sync_with_stdio(false),cin.tie(NULL);
    int n,m;
    cin>>n>>m;

    int ans = 0;
    for(int i = n; i <= m; i++)
    {
        if(f1(i) && f2(i))
        {
            cout<<i<<endl;
            ans++;
        }
    }
    cout<<ans<<endl;

    return 0;
}

 

问题 H: 海淀字符串III

时间限制: 1 Sec  内存限制: 128 MB
提交 状态

题目描述

从键盘输入一个长度不大于20的字符串,现要求:将字符串中的小写字母都改成相应的大写字母,其他字符依照原有顺序不变。

输入

只有一行,包含1个任意的字符串(其长度1<=L<=20)

输出

只有一行,即为:把小写字母改成相应的大写字母,其他字符依照原有顺序不变的字符串。

样例输入 Copy

ABCD123.eeffDD

样例输出 Copy

ABCD123.EEFFDD

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <algorithm>
#include <iostream>

using namespace std;

int main()
{
    ios::sync_with_stdio(false),cin.tie(NULL);
    
    string s;
    cin>>s;

    int ls = s.size();

    for(int i = 0; i <= ls - 1; i++)
    {
        if(s[i] >= 'a' && s[i] <= 'z')
        {
            s[i] = s[i] - 'a' + 'A';
        }
    }

    cout<<s<<endl;
    return 0;
}

 

问题 J: 海淀素数

时间限制: 1 Sec  内存限制: 128 MB
提交 状态

题目描述

在三位自然数中有这样一些特点的数:
(1)它们是素数;
(2)它们中满足:任意两个素数的和小于1000,同时又是17的倍数。
如:227和283,229和281,233和277等等。
求出任意自然数M ~N之间所有满足上述条件的素数对,并统计素数对的个数。

 

输入

只有一行,包含两个用空格隔开的任意自然数M和N(其中100<=M<N<=999)。

 

输出

共有若干行:
前若干行每行为一对满足条件的素数对(数据之间空1格);
最后一行是统计这些素数对的个数。如果没有则只输出0即可。

 

样例输入 Copy

200 300

样例输出 Copy

227 283
229 281
233 277
239 271
241 269
251 293
263 281
7

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <algorithm>
#include <iostream>

using namespace std;

bool a[1005] = {0};

int main()
{
    ios::sync_with_stdio(false),cin.tie(NULL);

    for(int i = 2; i <= 1000; i++)
    {
        if(!a[i])
        {
            for(int j = 2 * i; j <= 1000; j += i)
            {
                a[j] = 1;
            }
        }
    }

    int n,m;
    cin>>n>>m;
    int vis = 0;
    int b[1005] = {0};
    for(int i = n; i <= m; i++)
    {
        if(!a[i])
        {
            vis++;
            b[vis] = i;
        }
    }

    bool vvis[1005][1005] = {0};
    int ans = 0;
    for(int i = 1; i <= vis; i++)
    {
        for(int j = 1; j <= vis; j++)
        {
            if(!vvis[j][i] && !vvis[i][j] && i != j && (b[i] + b[j]) < 1000 && (b[i] + b[j]) % 17 == 0)
            {
                vvis[i][j] = 1;
                vvis[j][i] = 1;
                cout<<b[i]<<' '<<b[j]<<endl;
                ans++;
            }
        }
    }

    cout<<ans<<endl;

    return 0;
}

 

问题 K: 乐乐的图形

时间限制: 1 Sec  内存限制: 128 MB
提交 状态

题目描述

乐乐最近玩起了字符游戏,规则是这样的:读入四行字符串,其中的字母都是大写的,乐乐想打印一个柱状图显示每个大写字母的频率。你能帮助她吗?

输入

共有4行:每行为一串字符,不超过72个字符。 

输出

与样例的格式保持严格的一致。

样例输入 Copy

THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG.
THIS IS AN EXAMPLE TO TEST FOR YOUR
HISTOGRAM PROGRAM.
HELLO!

样例输出 Copy

                            *
                            *
        *                   *
        *                   *     *   *
        *                   *     *   *
*       *     *             *     *   *
*       *     * *     * *   *     * * *
*       *   * * *     * *   * *   * * * *
*     * * * * * *     * * * * *   * * * *     * *
* * * * * * * * * * * * * * * * * * * * * * * * * *
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

提示

1.输出的相邻字符间有一个空格。
2.最后一行的26个大写字母每次必须输出。
3.大写字母A所在的第一列前没有空格。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <algorithm>
#include <iostream>

using namespace std;

int main()
{
    ios::sync_with_stdio(false),cin.tie(NULL);
    int a[30] = {0};
    char s[100];
    
    int p = 4;
    while(p--)
    {
        gets(s);

        int sl = strlen(s);

        for(int i = 0; i <= sl - 1; i++)
        {
            if(s[i] >= 'A' && s[i] <= 'Z')
            {
                int u = s[i] - 'A' + 1;
                a[u]++;
            }
        }
    }

    int mx = 0;
    for(int i = 1; i <= 26; i++)
    {
        if(a[i] > mx)
        {
            mx = a[i];
        }
    }

    for(int i = mx; i >= 1; i--)
    {
        for(int j = 1; j <= 26; j++)
        {
            if(a[j] >= i)
                cout<<'*';
            else
                cout<<' ';

            if(j != 26)
                cout<<' ';
            else
                cout<<endl;
        }
    }

    char c;
    for(int i = 0; i <= 25; i++)
    {
        c = 'A' + i;
        cout<<c;

        if(i != 25)
            cout<<' ';
        else
            cout<<endl;
    }

    return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值