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

AC Code~~~~C++

Posted by lx99410 at 2014-09-19 23:05:11 on Problem 3889
#include<stdio.h>
#include<map>
#include<cmath>
using namespace std;
const int dx[]={1,2,2,1};
const int dy[]={1,1,2,2};
inline double sqr(int a){
	double s=a*a;
	return s;
}
struct Fra{
	int o,a,b;
	pair <int,int> solve(int order,int num){
		if(order==1)return make_pair(dx[num-1],dy[num-1]);
		double div=1<<(2*(order-1));
		for(int i=0;i<4;i++){
			if(num<=(i+1)*div){
				if(i==0){
					pair <int,int> tmp=solve(order-1,div-(num-1));
					double ax=((1<<(order-1))+1)*1.0/2.0,ay=ax;
					double cy=-(tmp.first-ax),cx=ay-tmp.second;
					return make_pair(ax+cx,ay-cy);
				}
				if(i==1){
					pair <int,int> tmp=solve(order-1,num-i*div);
					return make_pair(tmp.first+(1<<(order-1)),tmp.second);
				}
				if(i==2){
					pair <int,int> tmp=solve(order-1,num-i*div);
					return make_pair(tmp.first+(1<<(order-1)),tmp.second+(1<<(order-1)));
				}
				if(i==3){
					pair <int,int> tmp=solve(order-1,div-(num-3*div-1));
					double ax=((1<<(order-1))+1)/2.0,ay=ax;
					double cy=tmp.first-ax,cx=tmp.second-ay;
					return make_pair(ax+cx,ay-cy+(1<<(order-1)));
				}
			}
		}
	}
	void init(){
		scanf("%d%d%d",&o,&a,&b);
	}
	void work(){
		pair <int,int> pa=solve(o,a);
		pair <int,int> pb=solve(o,b);
		double result=sqrt(sqr(pa.first-pb.first)+sqr(pa.second-pb.second))*10.0;
		printf("%.0lf\n",result);
	}
}sol;
int main(){
	int T;
	scanf("%d",&T);
	while(T--){
		sol.init();
		sol.work();
	}
	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