当前位置:网站首页>Philosopher's walk gym divide and conquer + fractal
Philosopher's walk gym divide and conquer + fractal
2022-06-23 01:24:00 【Lupin123123】
Topic link 
Knowing the relationship between a structure and its substructure , Can “ Quarter search ” That coordinates .( I think this process is very similar to binary search )
#include<bits/stdc++.h>
#define FAST ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define INF 0x3f3f3f3f
typedef long long ll;
const int maxn = 1e5+5;
using namespace std;
int n,m;
int ans_x, ans_y;
int nxt_dir(int dir, int nxt, int p)
{
if (dir==1)
{
if (nxt==1) return 2;
else if (nxt==2) {
ans_y+=p; return 1;}
else if (nxt==3) {
ans_x+=p; ans_y+=p; return 1;}
else if (nxt==4) {
ans_x+=p; return 3;}
}
else if (dir==2)
{
if (nxt==1) return 1;
else if (nxt==2) {
ans_x+=p; return 2;}
else if (nxt==3) {
ans_x+=p; ans_y+=p; return 2;}
else {
ans_y+=p;return 4;}
}
else if (dir==3)
{
if (nxt==1) {
ans_x+=p;ans_y+=p; return 4;}
else if (nxt==2) {
ans_y+=p; return 3;}
else if (nxt==3) return 3;
else {
ans_x+=p; return 1;}
}
else
{
if (nxt==1) {
ans_x+=p; ans_y+=p; return 3;}
else if (nxt==2) {
ans_x+=p; return 4;}
else if (nxt==3) return 4;
else {
ans_y+=p; return 2;}
}
}
void dfs(int len, int tot, int cur, int dir)
{
int tmp=tot/4;
if (cur<=tmp)
{
int n_dir=nxt_dir(dir,1,len/2);
if (tmp==1) return;
dfs(len/2,tmp,cur,n_dir);
}
else if (cur<=2*tmp)
{
int n_dir=nxt_dir(dir,2,len/2);
if (tmp==1) return;
dfs(len/2,tmp,cur-tmp,n_dir);
}
else if (cur<=3*tmp)
{
int n_dir=nxt_dir(dir,3,len/2);
if (tmp==1) return;
dfs(len/2,tmp,cur-2*tmp,n_dir);
}
else
{
int n_dir=nxt_dir(dir,4,len/2);
if (tmp==1) return;
dfs(len/2,tmp,cur-3*tmp,n_dir);
}
}
int main()
{
FAST;
while(cin>>n>>m)
{
ans_x=ans_y=0;
int now=n*n;
dfs(n,now,m,1);
++ans_x, ++ans_y;
cout<<ans_x<<' '<<ans_y<<endl;
}
return 0;
}
There's a simpler way , Divide and conquer + Coordinate transformation
Just draw a picture of the coordinate transformation .
#include<bits/stdc++.h>
#define FAST ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define INF 0x3f3f3f3f
typedef long long ll;
const int maxn = 1e5+5;
using namespace std;
int n,m;
struct node
{
int x,y;
node (int xx, int yy){
x=xx, y=yy;
}
};
node work(int n_n, int m_m)
{
if (n_n==1) return node(0,0);
int tmp=n_n*n_n/4;
int pos=(m_m-1)/tmp; //m_m Need to get 1
int nxt=m_m%tmp;
if (nxt==0) nxt=tmp; // Special judgement m_m%tmp The situation of
node res=work(n_n/2,nxt);
if (pos==0) return node(res.y,res.x);
else if (pos==1) return node(res.x,res.y+n_n/2);
else if (pos==2) return node(res.x+n_n/2,res.y+n_n/2);
else if (pos==3) return node(n_n-res.y-1,n_n/2-res.x-1);
}
int main()
{
FAST;
while(cin>>n>>m)
{
node ans(0,0);
ans=work(n,m);
cout<<ans.x+1<<' '<<ans.y+1<<endl;
}
return 0;
}
边栏推荐
- LeetCode 206. Reverse linked list (iteration + recursion)
- Cadence spb17.4 - Chinese UI settings
- office2016+visio2016
- How to solve the problem that easycvr does not display the interface when RTMP streaming is used?
- You can also do NLP (classification)
- 最安全的现货白银的心理分析
- How to refine permissions to buttons?
- SQL programming task02 job - basic query and sorting
- Yyds dry inventory solution sword finger offer: print the binary tree into multiple lines
- 層次選擇器
猜你喜欢

Development status of full color LED display

How to solve the problem that easycvr does not display the interface when RTMP streaming is used?

SQL programming task05 job -sql advanced processing

New progress in the construction of meituan's Flink based real-time data warehouse platform

Explain the startup process of opengauss multithreading architecture in detail

最安全的现货白银的心理分析

Ros2 summer school 2022 transfer-

Analysis on the wallet system architecture of Baidu trading platform

Huawei cloud recruits partners in the field of industrial intelligence to provide strong support + commercial realization

LeetCode 206. 反转链表(迭代+递归)
随机推荐
[hdu] P7079 Pty loves lines
Swiftui swift tutorial 14 useful array operators
Installing MySQL for Linux
Add expiration time for localstorage
MySQL-Seconds_ behind_ Master accuracy error
62. 不同路径
B tree and b+ tree
The devil cold rice # 099 the devil said to travel to the West; The nature of the boss; Answer the midlife crisis again; Specialty selection
Similar to attention NLP
BGP federal comprehensive experiment
Flink synchronizes MySQL data to es
cadence SPB17.4 - allegro - 优化指定单条电气线折线连接角度 - 折线转圆弧
Xiaobai operates win10 to expand Disk C (allocate disk D memory to Disk C) and the test is valid for many times
[launch] redis Series 2: data persistence to improve availability
Phantomjs Usage Summary
What financial product does the new bond belong to?
cadence SPB17.4 - allegro - 優化指定單條電氣線折線連接角度 - 折線轉圓弧
層次選擇器
OOP multiple storage (class template)
SAP ui5 application development tutorial 102 - detailed explanation of the print function of SAP ui5 applications