题解 应急棍

传送门

找规律题,但需要高精小数
其实可以转化成高精整数,等以后复习高精的时候再说吧

Code:
#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define N 100010
#define ll long long
#define ld long double
#define fir first
#define sec second
#define make make_pair
#define int128 __int128
// #define int long long

int128 l;
ll n, c;

#if 0
namespace force{
	pair<ld, ld> sta[N];
	int top;
	void solve() {
		for (int k=1; k<=n; ++k) {
			ld maxn=-1; pair<ld, ld> maxi;
			for (ld i=0; i<=l; i+=0.1)
				for (ld j=0; j<=l; j+=0.1) {
					ld minn=INF;
					for (int h=1; h<=top; ++h) minn=min(minn, sqrt((sta[h].fir-i)*(sta[h].fir-i)+(sta[h].sec-j)*(sta[h].sec-j)));
					if (minn > maxn) maxi=make(i, j);
				}
			sta[++top]=maxi;
		}
		printf("%Lf %Lf\n", sta[top].fir, sta[top].sec);
	}
}

namespace task1{
	ll pw4[N], pw2[N], tab[N];
	void init() {
		pw2[0]=pw4[0]=1; tab[0]=4;
		for (int i=1; i<40; ++i) pw4[i]=pw4[i-1]*4, pw2[i]=pw2[i-1]*2;
		for (int i=1; i<40; ++i) tab[i]=pw4[i-1]+pw2[2*i-1]+pw2[i];
		// cout<<"tab: "; for (int i=1; i<40; ++i) cout<<tab[i]<<' '; cout<<endl;
	}
	void solve() {
		if (n<=4) {
			if (n==1) printf("%.120Lf %.120Lf\n", 0.0l, 0.0l);
			else if (n==2) printf("%.120Lf %.120Lf\n", l, l);
			else if (n==3) printf("%.120Lf %.120Lf\n", 0.0l, l);
			else if (n==4) printf("%.120Lf %.120Lf\n", l, 0.0l);
			return ;
		}
		int k;
		for (k=0; n>tab[k]; n-=tab[k++]) ;
		// cout<<"k: "<<k<<endl;
		if (n<=pw4[k-1]) {
			ld x, y;
			x=l/pw2[k-1]*((n-1)/pw2[k-1])+l/pw2[k];
			y=l/pw2[k-1]*((n-1)%pw2[k-1])+l/pw2[k];
			printf("%.120Lf %.120Lf\n", x, y);
		}
		else {
			n-=pw4[k-1];
			// cout<<"n: "<<n<<' '<<k<<endl;
			ll step=pw2[k-1]<<1|1, s=(n-1)/step+1;
			n-=step*(s-1);
			// cout<<"s: "<<s<<' '<<n<<endl;
			// assert(n);
			ld x, y;
			if (n<=pw2[k-1]) {
				x=l/pw2[k-1]*(s-1);
				y=l/pw2[k-1]*(n-1)+l/pw2[k];
			}
			else {
				// cout<<"no"<<endl;
				n-=pw2[k-1];
				x=l/pw2[k-1]*(s-1)+l/pw2[k];
				y=l/pw2[k-1]*(n-1);
			}
			printf("%.120Lf %.120Lf\n", x, y);
		}
	}
}
#endif

namespace task{
	int128 pw4[N], pw2[N], tab[N];
	char sta[N];
	int top;
	const int base=20;
	int128 read() {
		int128 ans=0; int len=base; char t=getchar();
		while (!isdigit(t)) t=getchar();
		while (isdigit(t)) ans=(ans<<3)+(ans<<1)+(t^48), t=getchar();
		if (t=='.') {
			t=getchar();
			while (isdigit(t)) ans=(ans<<3)+(ans<<1)+(t^48), t=getchar(), --len;
		}
		while (len) ans=(ans<<3)+(ans<<1), --len;
		return ans;
	}
	void print(int128 t) {
		top=0;
		for (int i=1; i<=base; ++i) sta[++top]='0'+t%10, t/=10;
		sta[++top]='.';
		do {sta[++top]='0'+t%10; t/=10;} while (t);
		while (top) printf("%c", sta[top--]);
	}
	void init() {
		pw2[0]=pw4[0]=1; tab[0]=4;
		for (int i=1; i<40; ++i) pw4[i]=pw4[i-1]*4, pw2[i]=pw2[i-1]*2;
		for (int i=1; i<40; ++i) tab[i]=pw4[i-1]+pw2[2*i-1]+pw2[i];
		// cout<<"tab: "; for (int i=1; i<40; ++i) cout<<tab[i]<<' '; cout<<endl;
	}
	void solve() {
		if (n<=4) {
			if (n==1) printf("%.120Lf %.120Lf\n", 0.0l, 0.0l);
			else if (n==2) {print(l); printf(" "); print(l); printf("\n");}
			else if (n==3) {print(0); printf(" "); print(l); printf("\n");}
			else if (n==4) {print(l); printf(" "); print(0); printf("\n");}
			return ;
		}
		int k;
		for (k=0; n>tab[k]; n-=tab[k++]) ;
		// cout<<"k: "<<k<<endl;
		if (n<=pw4[k-1]) {
			int128 x, y;
			x=l/pw2[k-1]*((n-1)/pw2[k-1])+l/pw2[k];
			y=l/pw2[k-1]*((n-1)%pw2[k-1])+l/pw2[k];
			// printf("%.120Lf %.120Lf\n", x, y);
			print(x); printf(" "); print(y); printf("\n");
		}
		else {
			n-=pw4[k-1];
			// cout<<"n: "<<n<<' '<<k<<endl;
			ll step=pw2[k-1]<<1|1, s=(n-1)/step+1;
			n-=step*(s-1);
			// cout<<"s: "<<s<<' '<<n<<endl;
			// assert(n);
			int128 x, y;
			if (n<=pw2[k-1]) {
				x=l/pw2[k-1]*(s-1);
				y=l/pw2[k-1]*(n-1)+l/pw2[k];
			}
			else {
				// cout<<"no"<<endl;
				n-=pw2[k-1];
				x=l/pw2[k-1]*(s-1)+l/pw2[k];
				y=l/pw2[k-1]*(n-1);
			}
			// printf("%.120Lf %.120Lf\n", x, y);
			print(x); printf(" "); print(y); printf("\n");
		}
	}
}

signed main()
{
	freopen("a.in", "r", stdin);
	freopen("a.out", "w", stdout);

	int T;
	scanf("%Lf%d", &c, &T); l=task::read();
	task::init();
	while (T--) {
		scanf("%lld", &n);
		// force::solve();
		task::solve();
	}

	return 0;
}
posted @ 2021-09-22 20:01  Administrator-09  阅读(3)  评论(0编辑  收藏  举报