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);
}