Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

水题也要水得有水平,来个内联汇编的版本(C++)

Posted by Pcz at 2012-11-01 13:35:57 on Problem 1287
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;


int connect[51],N;

struct Node
{
	int x,y,dis;
};

bool operator<(const Node & a,const Node & b)
{
	return a.dis<b.dis;
}

bool operator>(const Node & a,const Node & b)
{
	return a.dis>b.dis;
}

Node data[5000];


int find(int x)
{
	__asm
	{
		mov ebx,x;
		mov ecx,connect[ebx*type int];
		cmp ecx,0;
		je END1;
		cmp ecx,x;
		je END;
		push connect[ebx*type int];
		call find;
		mov connect[ebx*type int],eax;
		add esp,4;
		jmp END;
END1:
		mov ecx,x;
		mov connect[ebx*type int],ecx;
		jmp END;
END:
		mov eax,connect[ebx*type int];
	}
}


int main()
{
	int P,R,xx,yy,sum;
	while(scanf("%d",&P)!=EOF)
	{
		if(!P){break;}
		scanf("%d",&R);
		for(int i=0;i<R;i++){scanf("%d%d%d",&data[i].x,&data[i].y,&data[i].dis);}
		memset(connect,0,sizeof(connect));
		sort(data,data+R);
		__asm
		{
			mov sum,0;
			cmp R,0;
			je END2;
			mov ecx,R;
			dec ecx;
			mov ebx,type Node;
xunhuan:
			cmp P,0;
			je END2;
			mov eax,R;
			dec eax;
			sub eax,ecx;
			mul ebx;
			lea edx,data;
			add eax,edx;
			push ecx;
			push [eax]Node.dis;
			push [eax]Node.x;
			push [eax]Node.y;
			call find;
			mov yy,eax;
			pop edx;
			call find;
			mov xx,eax;
			pop edx;
			mov edx,yy;
			cmp eax,edx;
			pop ecx;
			je END;
			mov connect[edx*type int],eax;
			add sum,ecx;
			dec P;
END:
			pop ecx;
			loop xunhuan;
END2:
		}
		printf("%d\n",sum);
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator