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;
}
HDU多校4 - 6813 Last Problem(构造)相关推荐
- 牛客多校4 - Harder Gcd Problem(构造+贪心)
题目链接:点击查看 题目大意:给出一个 n ,表示 1 ~ n 的 n 个数字,现在要求选出尽可能多的两两匹配,使得每组匹配的 gcd 都大于 1,输出最多能有多少组匹配,以及方案 题目分析: 这样的 ...
- HDU 多校 6400 Parentheses Matrix(构造)
HDU 多校 6400 Parentheses Matrix(构造) // Problem: D. Parentheses Matrix // Contest: Codeforces - 2018 C ...
- 权值线段树小结(hdu多校,普通平衡树,郁闷的出纳员)
之前刷了一点主席树的题目,但是没有系统的做过权值线段树的题目.主席树是多根权值线段树的综合.权值线段树可以解决在总区间里求第k大的问题.在普通的线段树里,我们每一个节点维护的是权值大小.但是在权值线段 ...
- 2018 HDU多校第四场赛后补题
2018 HDU多校第四场赛后补题 自己学校出的毒瘤场..吃枣药丸 hdu中的题号是6332 - 6343. K. Expression in Memories 题意: 判断一个简化版的算术表达式是否 ...
- hdu 2058 解题报告 - The sum problem
hdu 2058 解题报告 - The sum problem 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=2058 等差求和公式: Sn=(a1+aN ...
- hdu 1757 A Simple Math Problem 构造矩阵
题意:函数f(x), 若 x < 10 f(x) = x. 若 x >= 10 f(x) = a0 * f(x-1) + a1 * f(x-2) + a2 * f(x-3) + -- + ...
- HDU 5055 Bob and math problem(构造)
无法输出的情况稍微难处理 其他的只要贪心构造一下就好了 #include<iostream> #include<cstdio> #include<set> #inc ...
- hdu 3509 Buge's Fibonacci Number Problem(矩阵乘法+二项式)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=3509 Buge's Fibonacci Number Problem Time Limit: 10000/ ...
- HDU多校4 - 6989 Didn‘t I Say to Make My Abilities Average in the Next Life?!(单调栈)
题目链接:点击查看 题目大意:给出一个长度为 nnn 的序列,再给出 mmm 次询问,每次询问给出一个区间 [l,r][l,r][l,r],要求输出区间 [l,r][l,r][l,r] 内 " ...
最新文章
- 设计模式 之美 -- 单例模式
- linux7内核优化,centos7 系统内核、网络等优化(适用高并发)
- TCP与UDP区别小结
- es6的Proxy(代理)
- OA办公系统的核心-工作流
- 个人的小项目mysql_mgr_test开放了
- jquery改变css,改变style
- iOS中AVFoundation的简单使用—音乐的播放
- IOS之优秀PCH头文件定义
- c语言判断是否是回文字符串
- 计算机考研英语有听力吗,考研英语有听力吗
- sql server代理无法启动_谁说前端不需要懂Nginx反向代理与负载均衡
- 三维点云学习(4)3-Model Fitting Least Square
- AcWing 847. 图中点的层次(BFS模板)
- 物理内存管理之zone详解
- 在Linux下安装GmSSL
- 移动前端开发的一些简单分类!
- 苹果账号调查事件始末,Apple审核流程或有变
- 松翰单片机--SN8F5702学习笔记(六)TIMER2
- IDEA本地插件下载及安装