0分求助!
查看原帖
0分求助!
1216740
_Misaka_Ning_楼主2024/8/6 09:54

为什么会0分。。。TAT 各位大佬走过路过帮忙看看吧orz

#include<bits/stdc++.h>
#define forr(i,a,b) for(int i=(a);i<(b);i++)
#define INIT() do{\
	ios::sync_with_stdio(0); \
	cin.tie(0);\
	cout.tie(0);\
}while(0);
#define endl '\n'
const int N = 1005;
//typedef unsigned long long ull
using namespace std;

/*
3
90 90 90
85 95 90
80 100 91

2
*/ 

int n, a[N], b[N], c[N], d[N], ans=0, i=1, j=0; // a, b, cΪ¸÷¿Æ·Ö, dΪ×Ü·Ö 

bool check(int i, int j){
	if(abs(a[i]-a[j])>5) return false;
	if(abs(b[i]-b[j])>5) return false;
	if(abs(c[i]-c[j])>5) return false;
	return true;
}

// ½»»»Êý¾Ý 
void s_swap(int i){
	int temp;
	
	temp = d[i];
	d[i] = d[i+1];
	d[i+1] = temp;
	
	temp = a[i];
	a[i] = a[i+1];
	a[i+1] = temp;
	
	temp = b[i];
	b[i] = b[i+1];
	b[i+1] = temp;
	
	temp = c[i];
	c[i] = c[i+1];
	c[i+1] = temp;
}

// ðÅÝÅÅÐò 
void s_sort(){
	forr(q,0,n){
		forr(p,0,n-1-q){
			if(d[i]>d[i+1]){
				s_swap(i);
			}
		}
	}
} 

void function1(){
	cin>>n;
	forr(i,0,n){
		cin>>a[i]>>b[i]>>c[i];
		d[i]=a[i]+b[i]+c[i];
	}
	s_sort();
	// ˫ָÕë i ÔÚǰ j ÔÚºó 
	while(i<n){
		if(abs(d[i]-d[j]<=10)){
			if(check(i, j)){
				ans++;
			}
			i++;
		}
		else{
			j++;
		}
	}
	// ½« j ±éÀúÍê 
	for(int j;j <= n; j++){
		if(abs(d[i]-d[j]<=10)){
			if(check(i, j)){
				ans++;
			}
		}
	}
	cout<<ans;
}

int main(){
	INIT();
	function1();

    return 0;
}


2024/8/6 09:54
加载中...