Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:求测试数据,自己做了几组测试数据和题目中的都测试过了,但是还是WAIn Reply To:求测试数据,自己做了几组测试数据和题目中的都测试过了,但是还是WA Posted by:wangchao at 2007-05-01 19:03:23 附代码: #include <stdio.h> #include <string.h> #define MIN(x, y) ((x) < (y)) ? (x) : (y) #define MAX(x, y) ((x) > (y)) ? (x) : (y) #define GT(x, y) ((x) > (y)) ? 1 : 0 int L, line[128][4]; unsigned char used[128][128], conn[128][128], bad[128]; int try_cross(int t1, int t2) { double v1 ,v2 ,v3, v4; if(GT(MIN(line[t1][0], line[t1][2]), MAX(line[t2][0], line[t2][2])) || GT(MIN(line[t1][1], line[t1][3]), MAX(line[t2][1], line[t2][3])) || GT(MIN(line[t2][0], line[t2][2]), MAX(line[t1][0], line[t1][2])) || GT(MIN(line[t2][1], line[t2][3]), MAX(line[t1][1], line[t1][3]))) return(0); v1 = ((double)line[t1][2] - line[t1][0]) * (line[t2][3] - line[t1][1]) - (line[t1][3] - line[t1][1]) * (line[t2][2] - line[t1][0]); v2 = ((double)line[t1][2] - line[t1][0]) * (line[t2][1] - line[t1][1]) - (line[t1][3] - line[t1][1]) * (line[t2][0] - line[t1][0]); if(v1 * v2 > 0) return(0); v3 = ((double)line[t2][2] - line[t2][0]) * (line[t1][3] - line[t2][1]) - (line[t2][3] - line[t2][1]) * (line[t1][2] - line[t2][0]); v4 = ((double)line[t2][2] - line[t2][0]) * (line[t1][1] - line[t2][1]) - (line[t2][3] - line[t2][1]) * (line[t1][0] - line[t2][0]); if(v3 * v4 > 0) return(0); conn[t1][t2] = 1; conn[t2][t1] = 1; return 1; } int try_conn(int t1, int t2) { int i; if(conn[t1][t2] == 1 || try_cross(t1, t2)) return(1); if(bad[t1]) return(0); for(i = 1, bad[t1] = 1; i <= L; i++) { if(i == t1 || i == t2 || bad[i]) continue; if(used[t1][i] == 0 && try_cross(i, t1)) { bad[t1] = 0; used[t1][i] = 1; used[i][t1] = 1; if(conn[i][t2] == 1 || try_conn(i, t2)) { conn[i][t2] = 1; conn[t2][i] = 1; return(1); } used[t1][i] = 0; used[i][t1] = 0; } } return(0); } int main() { int i, t1, t2; while(scanf("%d", &L)) { if(L < 1) break; for(i = 1; i <= L && scanf("%d %d %d %d", &line[i][0], &line[i][1], &line[i][2], &line[i][3]); i++); memset(conn, 0, sizeof(conn)); memset(bad, 0, sizeof(bad)); while(scanf("%d %d", &t1, &t2)) { if(t1 < 1) break; memset(used, 0, sizeof(used)); if(t1 == t2 || try_conn(t1, t2)) printf("CONNECTED\n"); else printf("NOT CONNECTED\n"); } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator