Codeforces Round #343 (Div. 2) Problem A & B

Problem A——Far Relative’s Birthday Cake

题意:找出一个矩阵里同行有多少对C,同列有多少对C。
代码如下:

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

char sav[105][105];

int main()
{
//freopen("data.txt","r",stdin);
    int n;
    scanf("%d",&n);
    int ans = 0;
    for(int i = 0; i< n; ++i){
        scanf("%s",&sav[i]);
        int cnt = 0;
        for(int j = 0 ;j<n;++j){
            if(sav[i][j] == 'C')cnt++;
        }
        ans += cnt*(cnt-1) / 2;
    }
    for(int i = 0; i < n; ++i){
        int cnt = 0;
        for(int j = 0; j < n; ++j){
            if(sav[j][i] =='C')cnt++;
        }
        ans += cnt * (cnt-1) /2;
    }
    printf("%d\n",ans);
}

Problem B
题意:一年中有男人和女人要选一个时间去一个地方,每个人一年仅有一段时间空闲。一辆车能且只能载一个男人和一个女人。问什么时候去最好
代码如下:

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

struct People{
    char gender;
    int start;
    int end;
};

People people[5005];

bool judge(int i,People a)
{
    return i<= a.end && i >= a.start;
}

int main()
{
//freopen("data.txt","r",stdin);
    int n;
    scanf("%d",&n);
    getchar();
    for(int i = 0; i < n; ++ i ){
        scanf("%c%d%d",&people[i].gender,&people[i].start,&people[i].end);
        getchar();
    }
    int ans = 0;
    for(int i = 1; i <=366; ++i){
        int tmpM = 0;
        int tmpF = 0;
        for(int j = 0; j < n; ++j){
            if(judge(i,people[j])){
                if(people[j].gender == 'M')tmpM++;
                else tmpF++;
            }
        }
        ans = max(ans,min(tmpM,tmpF));
    }
    printf("%d\n",ans*2);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值