- 论坛徽章:
- 0
|
- #include <stdio.h>
- #include <stdlib.h>
- #define GETY(a, b) ((double)((a[3] - a[1]) * (b - a[0]) / (a[2] - a[0])) + a[1])
- #define MAX(a, b) ((a) > (b)) ? (a) : (b)
- #define MIN(a, b) ((a) < (b)) ? (a) : (b)
- int LINE2[32 * 1024][4];
- double LINE3[512 * 1024][7];
- int cmp(const void *a, const void *b) {
- double x, y;
- x = ((double *)a)[0];
- y = ((double *)b)[0];
- if( x > y ) return 1;
- if( x < y ) return -1;
- x = ((double *)a)[4];
- y = ((double *)b)[4];
- if( x > y ) return 1;
- if( x < y ) return -1;
- x = ((double *)a)[1];
- y = ((double *)b)[1];
- if( x > y ) return 1;
- if( x < y ) return -1;
- return 0;
- }
- int main() {
- int C, L1, L2, L3, i, j, f, d, t;
- fscanf(stdin, "%d", &C);
- while(C--) {
- fscanf(stdin, "%d %d", &L1, &L2);
- for(i = 0, L3 = 0; i < L2; i++) {
- fscanf(stdin, "%d %d %d %d", &LINE2[i][0], &LINE2[i][1], &LINE2[i][2], &LINE2[i][3]);
- if(LINE2[i][0] > LINE2[i][2]) {
- t = LINE2[i][0];
- LINE2[i][0] = LINE2[i][2];
- LINE2[i][2] = t;
- t = LINE2[i][1];
- LINE2[i][1] = LINE2[i][3];
- LINE2[i][3] = t;
- }
- for(j = LINE2[i][0], f = 0; ; j++) {
- LINE3[L3][0] = (double)j;
- LINE3[L3][1] = GETY(LINE2[i], j);
- LINE3[L3][2] = (double)(j + 1);
- LINE3[L3][3] = GETY(LINE2[i], (j + 1));
- LINE3[L3][4] = MIN(LINE3[L3][1], LINE3[L3][3]);
- LINE3[L3][5] = MAX(LINE3[L3][1], LINE3[L3][3]);
- LINE3[L3][6] = (double)L3;
- //printf("[%d]:[(%f,%f);(%f,%f)]\n", L3, LINE3[L3][0], LINE3[L3][1], LINE3[L3][2], LINE3[L3][3]);
- L3++;
- if(LINE2[i][2] == j + 1)
- break;
- }
- }
- qsort(LINE3, L3, sizeof(LINE3[0]), cmp);
- for(i = 1, d = 0; i < L3 - 1; i++) {
- for(j = i + 1; j < L3; j++) {
- printf("[%d:%d]#[(%f,%f);(%f,%f)]#[(%f,%f);(%f,%f)][%f]", i, j, LINE3[i][0], LINE3[i][1], LINE3[i][2], LINE3[i][3], LINE3[j][0], LINE3[j][1], LINE3[j][2], LINE3[j][3], LINE3[j][6]);
- if((LINE3[i][5] <= LINE3[j][4])
- || (LINE3[i][0] < LINE3[j][0])) {
- printf(" break\n");
- break;
- }
- if((LINE3[i][1] > LINE3[j][1] && LINE3[i][3] < LINE3[j][3])
- || (LINE3[i][1] < LINE3[j][1] && LINE3[i][3] > LINE3[j][3])) {
- printf(" cross\n");
- d++;
- }
- else {
- printf(" none\n");
- }
- }
- }
- printf("%d\n", d);
- }
- }
复制代码
数据的数据量非常大,重定向到文件里面。
在32766行,出现了异常数据,不知道哪里来的。
- [32765:32766]#[(0.000000,32765.000000);(1.000000,32765.000000)]#[(0.000000,32766.000000);(1.000000,32766.000000)][491505.000000] break
- [32766:32767]#[(0.000000,32766.000000);(1.000000,32766.000000)]#[(0.000000,0.000000);(0.000000,0.000000)][0.000000] break
- [32767:32768]#[(0.000000,0.000000);(0.000000,0.000000)]#[(0.000000,0.000000);(0.000000,0.000000)][0.000000] break
复制代码
[ 本帖最后由 lovelyarry 于 2007-4-9 19:32 编辑 ] |
-
-
a.rar
8.19 KB, 下载次数: 17
测试数据
|