欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

HDU多校4 - 6813 Last Problem(构造)

发布时间:2024/4/11 编程问答 43 豆豆
生活随笔 收集整理的这篇文章主要介绍了 HDU多校4 - 6813 Last Problem(构造) 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

题目链接:点击查看

题目大意:给出一个无限大的二维平面,需要在平面内进行染色,每次可以选择一个点 ( x , y ) 将其染色为 n 的前提是,相邻四个格子必须分别已经染了 n - 1 , n - 2 , n - 3 , n - 4 四种颜色,染色可以覆盖,构造出一种合理的染色方案,使得可以在平面上出现颜色 n 

题目分析:参考博客:https://www.cnblogs.com/graytido/p/13406750.html

本来看题解觉得好难的一道构造题,搜到了上面大佬的博客,构造题嘛,就别问那么多为什么了,能想出来就能 AC

自上而下构造如此三角形:

换句话说,对于某个时刻,若想让 ( x , y ) 变为 n ,则需要满足:

然后 dfs 搜就好了

代码:
 

#include<iostream> #include<cstdio> #include<string> #include<ctime> #include<cmath> #include<cstring> #include<algorithm> #include<stack> #include<climits> #include<queue> #include<map> #include<set> #include<sstream> #include<cassert> #include<bitset> using namespace std;typedef long long LL;typedef unsigned long long ull;const int inf=0x3f3f3f3f;const int N=2e3+100;const int b[5][2]={0,0,0,-1,-1,0,1,0,0,1};int maze[N][N];int cnt=0;void dfs(int x,int y,int val) {if(val<=0)return;for(int i=1;i<=4;i++){int xx=x+b[i][0],yy=y+b[i][1];if(maze[xx][yy]!=val-i)dfs(xx,yy,val-i);}maze[x][y]=val;printf("%d %d %d\n",x,y,val); }int main() { #ifndef ONLINE_JUDGE // freopen("data.in.txt","r",stdin); // freopen("data.out.txt","w",stdout); #endif // ios::sync_with_stdio(false);int n;scanf("%d",&n);dfs(1000,1000,n);return 0; }

 

超强干货来袭 云风专访:近40年码龄,通宵达旦的技术人生

总结

以上是生活随笔为你收集整理的HDU多校4 - 6813 Last Problem(构造)的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。