1.前言:感觉很久没有全机房形式的做过一次CF了...居然星期六他们打了一场4人局?...Orz我校神犇OICyan成功AK。最近正需要调整一下状态,于是就跟着刷了这次的CF,感觉智商被碾压,想题速度和打题速度果然很捉鸡...所以打一场还是有些收获吧。

 

2.Problem A

  题目大意:给你一个n*n的棋盘,某些棋盘上放了棋子,问:在同行或同列的棋子有多少对。(n<=100)

  水题。假设某行有x个,那么就有C(x,2)对。然后每行每列统计有多少个就行了,复杂度O(n^2)。

#include<cstdio>
#include<cstring>

using namespace std;

int n,ans;
int cnt_H[110],cnt_L[110];
char ch[110][110];

int main(){
//    freopen("A.in","r",stdin);
    
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%s",ch[i]+1);
    
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++) if(ch[i][j]=='C') cnt_H[i]++;
        for(int j=1;j<=n;j++) if(ch[j][i]=='C') cnt_L[i]++;
    }
    
    for(int i=1;i<=n;i++){
        ans+=(cnt_H[i]*(cnt_H[i]-1))>>1;
        ans+=(cnt_L[i]*(cnt_L[i]-1))>>1;
    }
    
    printf("%d",ans);
    return 0;
}
View Code

相关文章:

  • 2021-10-24
  • 2022-02-17
  • 2021-08-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-05
  • 2021-08-12
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-22
  • 2022-12-23
  • 2021-07-14
  • 2022-03-05
相关资源
相似解决方案