社区讨论

思路问题求助!

P14361[CSP-S 2025] 社团招新参与者 1已保存回复 1

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
1 条
当前快照
1 份
快照标识符
@mhiy4bg3
此快照首次捕获于
2025/11/03 17:36
4 个月前
此快照最后确认于
2025/11/03 17:36
4 个月前
查看原帖
CPP
#include <bits/stdc++.h>

#define rep(i, a, b) for(int i = a; i <= b; i ++)
#define reb(i, a, b) for(int i = a; i >= b; i --)
#define debug(x) cerr << #x << " = " << x << '\n' ;
#define ddd cout << "Done.";
#define mkp make_pair
#define fi first
#define se second

using namespace std ;

using ll = long long  ;
const int N = 1e6 ; 
int n ;
struct node {
	int x,  y ; 
}; 
node a[N][5] ;

int cmp(node &a, node &b) {
	if (a.x == b.x) return a.y > b.y ; 
	return a.x > b.x ; 
}
int t[10], c[N] ;
void solve() { int ans = 0 ; memset(t, 0, 10) ; 
	cin >> n ; 
	rep(i, 1, n) {
		rep(j, 1, 3) cin >> a[i][j].x ,a[i][j].y = j ; 
		sort(a[i] + 1, a[i] + 3 + 1, cmp) ;  c[i] = a[i][1].x - a[i][2].x ;  t[a[i][1].y]++ ;
		ans += a[i][1].x ;  
	} 
	sort(c + 1, c + n + 1) ;
	rep(i, 1, 3) {
		if (t[i] > n / 2) { 
			rep(j, 1, t[i] - n / 2) {
				ans -= c[j] ; 
			}
		}
	}
	cout << ans << '\n'; 
		
}

int main() {
//	ios::sync_with_stdio(0); cin.tie(0) ;
//	freopen("in.in", "r", stdin) ;
	int T ;  cin >> T ; 
	while (T --) {
		solve() ; 
	}

	return 0 ;
}


跟题解区的思路好像差不多,通过了小样例,但是大样例输出答案总是比正确答案多1000左右

回复

1 条回复,欢迎继续交流。

正在加载回复...