2 solutions

  • 0
    @ 2024-4-1 11:25:06

    #include

    using namespace std;

    int a[1005][5]; // a[i,1]语文 a[i,2]数学 a[i,3]英语 int n,m; int x,y;

    bool check(int i,int j){ //判断i和j同学是不是旗鼓相当 int p=0,q=0; for (int k=1;k<=3;k++){ if ( abs(a[i][k]-a[j][k])>5) return false; p += a[i][k], q+=a[j][k]; }

    if ( abs(p-q)<=10	)	return true;
    else					return false;
    

    }

    int main(){ cin >> n; for (int i=1;i<=n;i++) for (int j=1;j<=3;j++) //i行j列 cin >> a[i][j];

    int ans = 0;
    for (int i=1;i<=n;i++)
    	for (int j=i+1;j<=n;j++)
    		if (check(i,j))	ans++;	
    cout << ans;
    

    }

    • 0
      @ 2024-4-1 11:19:29

      #include

      using namespace std;

      int a[1005][5]; // a[i,1]语文 a[i,2]数学 a[i,3]英语 int n,m; int x,y;

      bool check(int i,int j){ //判断i和j同学是不是旗鼓相当 int p=0,q=0; for (int k=1;k<=3;k++){ if ( abs(a[i][k]-a[j][k])>5) return false; p += a[i][k], q+=a[j][k]; }

      if ( abs(p-q)<=10	)	return true;
      else					return false;
      

      }

      int main(){ cin >> n; for (int i=1;i<=n;i++) for (int j=1;j<=3;j++) //i行j列 cin >> a[i][j];

      int ans = 0;
      for (int i=1;i<=n;i++)
      	for (int j=i+1;j<=n;j++)
      		if (check(i,j))	ans++;	
      cout << ans;
      

      }

      • 1

      Information

      ID
      4693
      Time
      1000ms
      Memory
      125MiB
      Difficulty
      1
      Tags
      (None)
      # Submissions
      100
      Accepted
      46
      Uploaded By