cccc分组赛

7-1 后天(5 分)

如果今天是星期三,后天就是星期五;如果今天是星期六,后天就是星期一。我们用数字1到7对应星期一到星期日。给定某一天,请你输出那天的“后天”是星期几。

输入格式:

输入第一行给出一个正整数D(1 D 7),代表星期里的某一天。

输出格式:

在一行中输出D天的后天是星期几。

输入样例:

3

输出样例:

5


用模运算来实现天数的循环。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <utility>
#include <queue>
using namespace std;
#define INF 100000000
typedef pair<int, int> P;
#define f first
#define s second
const double eps = 1e-8;
#define N 10000

int week[] = {1, 2, 3, 4, 5, 6, 7};

int main()
{
    int n;

    scanf("%d", &n);

    printf("%d", week[(n + 1)%7]);

    return 0;
}


7-3 到底是不是太胖了(10 分)

据说一个人的标准体重应该是其身高(单位:厘米)减去100、再乘以0.9所得到的公斤数。真实体重与标准体重误差在10%以内都是完美身材(即 | 真实体重 标准体重 | < 标准体重×10%)。已知市斤是公斤的两倍。现给定一群人的身高和实际体重,请你告诉他们是否太胖或太瘦了。

输入格式:

输入第一行给出一个正整数N 20)。随后N行,每行给出两个整数,分别是一个人的身高H(120 < H < 200;单位:厘米)和真实体重W(50 < W 300;单位:市斤),其间以空格分隔。

输出格式:

为每个人输出一行结论:如果是完美身材,输出You are wan mei!;如果太胖了,输出You are tai pang le!;否则输出You are tai shou le!

输入样例:

3
169 136
150 81
178 155

输出样例:

You are wan mei!
You are tai shou le!
You are tai pang le!
套用给你的公式就好了。注意市斤与公斤的转换。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <utility>
#include <queue>
using namespace std;
#define INF 100000000
typedef pair<int, int> P;
#define f first
#define s second
const double eps = 1e-8;
#define N 10000

int main()
{
    int n;
    double s, t, b, c;

    cin >> n;

    while(n--)
    {
        cin >> s >> t;
        t *= 0.5;
        b = (s - 100) * 0.9;
        c = abs(b - t);

        if(c < b * 0.1){
            cout << "You are wan mei!\n";
        }else if(b > t){
            cout << "You are tai shou le!\n";
        }else{
            cout << "You are tai pang le!\n";
        }
    }

    return 0;
}


7-4 大笨钟(10 分)

微博上有个自称“大笨钟V”的家伙,每天敲钟催促码农们爱惜身体早点睡觉。不过由于笨钟自己作息也不是很规律,所以敲钟并不定时。一般敲钟的点数是根据敲钟时间而定的,如果正好在某个整点敲,那么“当”数就等于那个整点数;如果过了整点,就敲下一个整点数。另外,虽然一天有24小时,钟却是只在后半天敲1~12下。例如在23:00敲钟,就是“当当当当当当当当当当当”,而到了23:01就会是“当当当当当当当当当当当当”。在午夜00:00到中午12:00期间(端点时间包括在内),笨钟是不敲的。

下面就请你写个程序,根据当前时间替大笨钟敲钟。

输入格式:

输入第一行按照hh:mm的格式给出当前时间。其中hh是小时,在00到23之间;mm是分钟,在00到59之间。

输出格式:

根据当前时间替大笨钟敲钟,即在一行中输出相应数量个Dang。如果不是敲钟期,则输出:

Only hh:mm.  Too early to Dang.

其中hh:mm是输入的时间。

输入样例1:

19:05

输出样例1:

DangDangDangDangDangDangDangDang

输入样例2:

07:05

输出样例2:

Only 07:05.  Too early to Dang.
根据时间来确定敲的次数。
h和m是小时和分钟
00:00到12:00(包含边界)是不敲。

整点是敲(h - 12)次。非整点是敲(h - 12 + 1)次。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <utility>
#include <queue>
using namespace std;
#define INF 100000000
typedef pair<int, int> P;
#define f first
#define s second
const double eps = 1e-8;
#define N 10000

int main()
{
    int h, m;

    scanf("%d:%d", &h, &m);

    if(h < 12 || (h == 12 && m == 0)){
        printf("Only %02d:%02d.  Too early to Dang.", h, m);
    }else if( h > 12 && m == 0){
        h -= 12;
        while(h--){
            printf("Dang");
        }
    }else if(h == 12 && m > 0){
        printf("Dang");
    }else {
        h -= 11;
        while(h--){
            printf("Dang");
        }
    }

    return 0;
}

7-5 三天打鱼两天晒网(15 分)

中国有句俗语叫“三天打鱼两天晒网”。假设某人从某天起,开始“三天打鱼两天晒网”,问这个人在以后的第N天中是“打鱼”还是“晒网”?

输入格式:

输入在一行中给出一个不超过1000的正整数N。

输出格式:

在一行中输出此人在第N天中是“Fishing”(即“打鱼”)还是“Drying”(即“晒网”),并且输出“in day N”。

输入样例1:

103

输出样例1:

Fishing in day 103

输入样例2:

34

输出样例2:

Drying in day 34

三天打鱼两天晒网也就是五天一循环。把总天数%5就得到在一周天里的第几天。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <utility>
#include <queue>
using namespace std;
#define INF 100000000
typedef pair<int, int> P;
#define f first
#define s second
const double eps = 1e-8;
#define N 10000

int main()
{
    int n;

    cin >> n;

    if(n % 5 <= 3 && n % 5 != 0)
        printf("Fishing in day %d\n", n);
    else
        printf("Drying in day %d\n", n);

    return 0;
}

7-6 打印菱形图案(15 分)

本题要求编写程序,打印一个高度为n的、由“*”组成的正菱形图案。

输入格式:

输入在一行中给出一个正的奇数n

输出格式:

输出由n行星号“*”组成的菱形,如样例所示。每个星号后跟一个空格。

输入样例:

7

输出样例:

      * 
    * * * 
  * * * * * 
* * * * * * * 
  * * * * * 
    * * * 
      *

n为奇数,也就是整个菱形的高度。所以上面半个三角形高是m = (n - 1)/ 2。
对于上面三角形的第i层:空格数目是剩余层数的两倍:(m - i + 1) * 2,加一是加的最中间那层;
                                          星号数目是2 * i - 1,i是层数。
下面的三角形同理。
注意每个星号后面都有空格,最后一个也有。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <utility>
#include <queue>
using namespace std;
#define INF 100000000
typedef pair<int, int> P;
#define f first
#define s second
const double eps = 1e-8;
#define N 10000

int main()
{
    int n, m;

    cin >> n;
    m = (n - 1) / 2;

    for(int i = 1; i <= m; i++){
        for(int j = 1; j <= 2 * (m - i + 1); j++)
            printf(" ");

        for(int j = 1; j <= 2 * i - 1; j++){
            printf("*%c",' ');
        }

        putchar('\n');
    }

    for(int i = 0; i < n; i++)
        printf("*%c", ' ');
    putchar('\n');

    for(int i = m; i >= 1; i--){
        for(int j = 1; j <= 2 * (m - i + 1); j++)
            printf(" ");

        for(int j = 1; j <= 2 * i - 1; j++){
            printf("*%c",' ');
        }

        putchar('\n');
    }

    return 0;
}


7-7 找出不是两个数组共有的元素(20 分)

给定两个整型数组,本题要求找出不是两者共有的元素。

输入格式:

输入分别在两行中给出两个整型数组,每行先给出正整数N20),随后是N个整数,其间以空格分隔。

输出格式:

在一行中按照数字给出的顺序输出不是两数组共有的元素,数字间以空格分隔,但行末不得有多余的空格。题目保证至少存在一个这样的数字。同一数字不重复输出。

输入样例:

10 3 -5 2 8 0 3 5 -15 9 100
11 6 4 8 2 6 -5 9 0 100 8 1

输出样例:

3 5 -15 6 4 1

现在我觉得用set去重然后find好像挺好的。但是emmmm没想起来。

因为数据量很小,为了判断两个数组中单独出现的数字次数,我声明了一个pair数组,first是元素,second是元素出现次数。
先过一遍数组一,把出现过得元素次数设置为1.然后过第二个集合,同样的操作。只是第二个集合为了去重要再开个数组记录一下。
总之这题代码有点丑。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <utility>
#include <queue>
using namespace std;
#define INF 100000000
typedef long long ll;
typedef pair<ll, int> P;
#define f first
#define s second
const double eps = 1e-8;
#define N 10000

P num[450];
int m = 0;
ll ans[450], k = 0;
int used[450], l = 0;

int main()
{
    ll n, t;

    for(int i = 0; i < 41; i++){
        num[i].s = 0;
    }

    cin >> n;
    while(n--)
    {
        cin >> t;
        bool flag = false;
        for(int i = 0; i < m; i++){
            if(num[i].f == t){
                flag = true;
                break;
            }
        }
        if(flag)
            continue;
         num[m].f = t;
         num[m++].s = 1;
    }

    cin >> n;
    while(n--)
    {
        cin >> t;

        bool fl = false;

        for(int i = 0; i < l; i++)
            if(used[i] == t){
                fl = true;
                break;
            }
        if(fl)
            continue;

        used[l++] = t;
        bool flag = false;
        for(int i = 0; i < m; i++){
            if(num[i].f == t){
                num[i].s++;
                flag = true;
                break;
            }
        }
        if(flag)
            continue;
         num[m].f = t;
         num[m++].s = 1;
    }

    for(int i = 0; i < m; i++){
        if(num[i].s == 1){
            ans[k++] = num[i].f;
        }
    }

    for(int i = 0; i < k; i++){
        printf("%lld%c", ans[i], i == k - 1?'\n':' ');
    }

    return 0;
}

7-8 螺旋方阵(20 分)

所谓“螺旋方阵”,是指对任意给定的N,将1到N×N的数字从左上角第1个格子开始,按顺时针螺旋方向顺序填入N×N的方阵里。本题要求构造这样的螺旋方阵。

输入格式:

输入在一行中给出一个正整数N<10)。

输出格式:

输出N×N的螺旋方阵。每行N个数字,每个数字占3位。

输入样例:

5

输出样例:

  1  2  3  4  5
 16 17 18 19  6
 15 24 25 20  7
 14 23 22 21  8
 13 12 11 10  9

右下左上、右下左上,,,就是四个方向取模循环。
一开始把方向向量按顺序存好,然后循环下标。

为了方便,给最后结果的那个数字框框外面预处理一下,方便第一次循环转弯。
也就是:
       -1 -1 -1.。。。。
-1 1  2  3  4  5 -1
-1 16 17 18 19  6 -1
-1 15 24 25 20  7 -1
-1 14 23 22 21  8 -1
-1 13 12 11 10  9 -1
      -1 -1 -1 -1 -1 。。。
一开始放在(1, 0)这个坐标上。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <utility>
#include <queue>
using namespace std;
#define INF 100000000
typedef pair<int, int> P;
#define f first
#define s second
const double eps = 1e-8;
#define N 12
///方向向量,右下左上的顺序
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int maze[N][N];
int n;

int main()
{
    cin >> n;
    int x, y, num = 1;
///预处理一下边界
    for(int i = 0; i <= n + 1; i++)
        maze[0][i] = maze[n + 1][i] = -1;
    for(int i = 0; i <= n + 1; i++)
        maze[i][0] = maze[i][n + 1] = -1;

    x = 1, y = 0;
    for(int i = 0; ; i++){
        i %= 4;///取模来实现方向循环

        ///一直走,直到遇到数字转弯。
        while(maze[x + dx[i]][y + dy[i]] == 0){
            x += dx[i];
            y += dy[i];

            maze[x][y] = num++;
        }
        if(num == n * n + 1)
            break;
    }

    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++){
            printf("%3d", maze[i][j]);
            if(j == n)
                putchar('\n');
        }

    return 0;
}







评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值