hdoj 2022 海选女主角

思路:

结构体排序 sort函数,

代码:

// 3.15 08:40-09:00
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 101;

int m, n;
struct Node {
	int x, y, s;
	int data; // 绝对值
}a[maxn];

bool cmp(Node a, Node b) {
	if (a.data != b.data)
		return a.data > b.data;
	else if (a.x != b.x)
		return a.x < b.x;
	else
		return a.y < b.y;
}

int main() {
	while (scanf("%d%d", &m, &n) != EOF) {
		int num = 0;
		for (int i = 1; i <= m; i++) {
			for (int j = 1; j <= n; j++) {
				int val;
				scanf("%d", &val);
				a[num].x = i;
				a[num].y = j;
				a[num].s = val;
				if (val < 0)
					a[num].data = -val;
				else
					a[num].data = val;
				num++;
			}
		}
		sort(a, a + num, cmp);
		printf("%d %d %d\n", a->x, a->y, a->s);
	}
	return 0;
}

样例可以过,但是submit到oj里面就是WA不知为啥?

上一篇:HDOJ 1421搬寝室


下一篇:JS AJAX --- PHP和ASP实例