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

强大的printf,scanf ,用cin,cout居然TLE..用printf,scanf 2800ms飘过去了(附代码)

Posted by zjy9107 at 2010-05-17 21:59:05 on Problem 3349
#include<iostream>
using namespace std;

struct snow{
	int arm[6];
}a[100000];

int int_cmp(const void * a,const void *b)
{
	return *((int *)a)-*((int *)b);
}

int b_cmp(const void * a,const void * b)
{
	snow* s1=(snow*)a;
	snow* s2=(snow*)b;
	for(int i=0;i<5;i++){
		if(s1->arm[i]!=s2->arm[i])
			return s1->arm[i]-s2->arm[i];
	}
	return s1->arm[5]-s2->arm[5];
}

int bb_cmp(const void * a,const void * b)
{
	int* s1=(int*)a;
	snow* s2=(snow*)b;
	for(int i=0;i<5;i++){
		if(s1[i]!=s2->arm[i])
			return s1[i]-s2->arm[i];
	}
	return s1[5]-s2->arm[5];
}	

int main()
{
	int n,i,j;
	cin>>n;
	for(i=0;i<n;i++)
		for(j=0;j<6;j++)
			scanf("%d",&a[i].arm[j]);
	for(i=0;i<n;i++)
		qsort(a[i].arm,6,sizeof(int),int_cmp);
	qsort(a,n,sizeof(snow),b_cmp);
	bool flag=false;
	for(i=0;i<n;i++){
		snow* p;
		int *tmp=a[i].arm;
		p=(snow*)bsearch(tmp,a+i+1,n-i-1,sizeof(snow),bb_cmp);
		if(p){
			flag=true;
			break;
		}
	}
	if(flag)
		printf("Twin snowflakes found.\n");
	else 
		printf("No two snowflakes are alike.\n");
	system("pause");
}


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