传送门:http://acm.csu.edu.cn:20080/csuoj/problemset/problem?pid=2279

题意:

代码:

#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
/**
*        ┏┓    ┏┓
*        ┏┛┗━━━━━━━┛┗━━━┓
*        ┃       ┃  
*        ┃   ━    ┃
*        ┃ >   < ┃
*        ┃       ┃
*        ┃... ⌒ ...  ┃
*        ┃       ┃
*        ┗━┓   ┏━┛
*          ┃   ┃ Code is far away from bug with the animal protecting          
*          ┃   ┃ 神兽保佑,代码无bug
*          ┃   ┃           
*          ┃   ┃       
*          ┃   ┃
*          ┃   ┃           
*          ┃   ┗━━━┓
*          ┃       ┣┓
*          ┃       ┏┛
*          ┗┓┓┏━┳┓┏┛
*           ┃┫┫ ┃┫┫
*           ┗┻┛ ┗┻┛
*/ typedef long long LL;
typedef pair<LL, LL> pLL;
typedef pair<LL, int> pLi;
typedef pair<int, LL> pil;;
typedef pair<int, int> pii;
typedef unsigned long long uLL;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define bug printf("*********\n")
#define FIN freopen("input.txt","r",stdin);
#define FON freopen("output.txt","w+",stdout);
#define IO ios::sync_with_stdio(false),cin.tie(0)
#define debug1(x) cout<<"["<<#x<<" "<<(x)<<"]\n"
#define debug2(x,y) cout<<"["<<#x<<" "<<(x)<<" "<<#y<<" "<<(y)<<"]\n"
#define debug3(x,y,z) cout<<"["<<#x<<" "<<(x)<<" "<<#y<<" "<<(y)<<" "<<#z<<" "<<z<<"]\n"
LL read() {
int x = , f = ; char ch = getchar();
while(ch < '' || ch > '') {
if(ch == '-')f = -;
ch = getchar();
}
while(ch >= '' && ch <= '') {
x = x * + ch - '';
ch = getchar();
}
return x * f;
}
const double eps = 1e-;
const int mod = 1e9 + ;
const int maxn = 3e5 + ;
const int INF = 0x3f3f3f3f;
const LL INFLL = 0x3f3f3f3f3f3f3f3f;
int mp[][], ans[][]; int dx[] = {, , -, , , , -, -};
int dy[] = {, , , -, , -, , -}; int sum[][];
int sumr[];
int sumc[];
int get_cnt(int x, int y) {
int cnt = ;
for(int i = ; i < ; i++) {
int nx = x + dx[i];
int ny = y + dy[i];
if(nx > && nx <= && ny > && ny <= && mp[nx][ny] == -) {
cnt += ans[nx][ny];
}
}
return cnt;
}
void add(int x, int y, int num) {
for(int i = ; i < ; i++) {
int nx = x + dx[i];
int ny = y + dy[i];
if(nx > && nx <= && ny > && ny <= && mp[nx][ny] != -) {
sum[nx][ny] += num;
}
}
} // bool check(int x, int y) {
// if(mp[x - 1][y - 1] != -1) {
// int cnt = get_cnt(x - 1, y - 1);
// if(cnt != mp[x - 1][y - 1]) return false;
// }
// }
bool check(int x, int y) {
if(x != && y != ) {
if(mp[x - ][y - ] != - && sum[x - ][y - ] != mp[x - ][y - ]) {
return false;
}
}
if(x == && y != ) {
if(mp[x][y - ] != - && sum[x][y - ] != mp[x][y - ]) {
return false;
}
}
if(y == && x != ) {
if(mp[x - ][y] != - && sum[x - ][y] != mp[x - ][y]) {
return false;
}
}
return true;
}
bool check_sum(int x, int y) { int num = ;
for(int i = x + ; i <= ; i++) {
if(mp[i][y] == -) {
num++;
}
}
if(num * + sumc[y] < || num + sumc[y] > ) {
return false;
} num = ;
for(int i = y + ; i <= ; i++) {
if(mp[x][i] == -) {
num++;
}
}
if(num * + sumr[x] < || num + sumr[x] > ) {
return false;
}
if(!check(x, y)) {
return false;
}
return true;
}
bool dfs(int x, int y) {
if(x > ) return true;
int tx = x, ty = y;
ty++;
if(ty > ) {
ty = ;
tx++;
}
if(mp[x][y] != -) {
if(check(x, y) && dfs(tx, ty)) {
return true;
} else {
return false;
}
}
for(int num = ; num <= ; num++) {
//debug1(num); ans[x][y] = num;
sumr[x] += num;
sumc[y] += num;
add(x, y, num);
if(check_sum(x, y) && dfs(tx, ty)) {
return true;
}
sumr[x] -= num;
sumc[y] -= num;
add(x, y, -num);
}
return false; } int main() {
#ifndef ONLINE_JUDGE
FIN
#endif
int T;
scanf("%d", &T);
while(T--) {
memset(mp, , sizeof(mp));
memset(sum, , sizeof(sum));
memset(ans, , sizeof(ans));
memset(sumc, , sizeof(sumc));
memset(sumr, , sizeof(sumr));
int cas;
scanf("%d", &cas);
for(int i = ; i <= ; i++) {
int cnt = ;
for(int j = ; j <= ; j++) {
scanf("%d", &mp[i][j]);
if(mp[i][j] == -) cnt++;
else ans[i][j] = mp[i][j];
}
} dfs(, );
printf("%d\n", cas);
for(int i = ; i <= ; i++) {
for(int j = ; j <= ; j++) {
printf("%d%c", ans[i][j], j == ? '\n' : ' ');
}
}
}
return ;
}
/**********************************************************************
Problem: 2279
User: buerdepepeqi
Language: C++
Result: AC
Time:16 ms
Memory:2024 kb
**********************************************************************/

CSU 多校训练第二场 J Pinemi Puzzles的更多相关文章

  1. 18牛客多校训练第二场 J farm

    题意:一个n×m的农田, 每个小格子都有一种作物, 现在喷t次农药,每次农药覆盖一个矩形, 该矩形里面与农药类型不同的植物都会死掉, 求最后植物的死亡数是多少. 题解:二维树状数组. 每次喷农药的时候 ...

  2. 牛客网多校训练第一场 J - Different Integers(树状数组 + 问题转换)

    链接: https://www.nowcoder.com/acm/contest/139/J 题意: 给出n个整数的序列a(1≤ai≤n)和q个询问(1≤n,q≤1e5),每个询问包含两个整数L和R( ...

  3. 2015多校训练第二场 hdu5305

    把这题想复杂了,一直在考虑怎么快速的判断将选的边和已选的边无冲突,后来经人提醒发现这根本没必要,反正数据也不大开两个数组爆搜就OK了,搜索之前要先排除两种没必要搜的情况,这很容易想到,爆搜的时候注意几 ...

  4. 牛客网多校训练第二场D Kth Minimum Clique

    链接:https://ac.nowcoder.com/acm/contest/882/D来源:牛客网 Given a vertex-weighted graph with N vertices, fi ...

  5. 2019HDU多校训练第二场 Longest Subarray

    题意:给你一个串,问满足以下条件的子串中最长的是多长:对于每个数字,要么在这个子串没出现过,要么出现次数超过k次. 思路:对于这类问题,常常转化为数据结构的询问问题.我们考虑枚举右端点,对于当前右端点 ...

  6. 2020牛客暑期多校训练营 第二场 J Just Shuffle 置换 群论

    LINK:Just Shuffle 比较怂群论 因为没怎么学过 置换也是刚理解. 这道题是 已知一个置换\(A\)求一个置换P 两个置换的关键为\(P^k=A\) 且k是一个大质数. 做法是李指导教我 ...

  7. 可持久化线段树的学习(区间第k大和查询历史版本的数据)(杭电多校赛第二场1011)

    以前我们学习了线段树可以知道,线段树的每一个节点都储存的是一段区间,所以线段树可以做简单的区间查询,更改等简单的操作. 而后面再做有些题目,就可能会碰到一种回退的操作.这里的回退是指回到未做各种操作之 ...

  8. 牛客多校第3场 J 思维+树状数组+二分

    牛客多校第3场 J 思维+树状数组+二分 传送门:https://ac.nowcoder.com/acm/contest/883/J 题意: 给你q个询问,和一个队列容量f 询问有两种操作: 0.访问 ...

  9. 2018牛客暑期ACM多校训练营第二场(有坑未填)

    第二场终于等来学弟 开始(被队友带飞)的开心(被虐)多校之旅 A   run A题是一个递推(dp?)+前缀和 因为看数据量比较大 就直接上前缀和了 一个比较简单的递推 没有太多难点 签到题 需要注意 ...

随机推荐

  1. ip route ifconfig 基本命令

    1.route命令 route –n route add –net 192.168.2.0/24 dev eth0 route add –net 192.168.2.0 netmask 255.255 ...

  2. Linux环境下Java应用性能分析定位-CPU使用篇

    1     CPU热点分析定位背景 CPU资源还是很昂贵的,为了深刻感受到这种昂贵,间下图当前CPU的资源售价: 所以对于程序猿们来说,需要让程序合理高效的使用CPU资源.利用有限的CPU资源来解决完 ...

  3. Python基础灬函数(定义,参数)

    函数 函数定义 # 定义一个计算绝对值的函数 def cal_abs(x): if x >= 0: return x else: return -x # 调用函数 print('-1的绝对值是: ...

  4. 在GPT格式的硬盘上,使用EFI启动的方式,安装Win7 64位系统

    Win7 sp1 原装系统,用UltraISO(软碟通) 把U 盘制成Win7 安装的启动U盘 将bootmgfw.efi和shell.efi 加到已制好启动U盘的根目录,并在efi/boot/路径下 ...

  5. HTML页面模板代码

    作者声明:本博客中所写的文章,都是博主自学过程的笔记,参考了很多的学习资料,学习资料和笔记会注明出处,所有的内容都以交流学习为主.有不正确的地方,欢迎批评指正 HTML页面模板代码 常用的页面模板 & ...

  6. gulp配置文件(gulpfile.js)

    需要安装的插件 "gulp": "^3.9.1","gulp-clean": "^0.3.2","gulp-c ...

  7. Traffic Steering for Service Function Chaining

    Introduction 目前通过vlan标签来把流量引向对应的sfc 以前的sfc静态(SFs相邻组成SFC),有了sdn之后具有动态性.(SFs不需要彼此相邻.将流量动态地导向所需的SFs.) 流 ...

  8. Hibernate(九)

    三套查询之SQL查询 Native Sql Query原生的sql查询.要求写sql语句.SQLQuery 是 Query的子类 1.查询所有的学生 //1.查询所有的学生 @Test public ...

  9. beta阶段评语

    首先我说一下自己心中的排序 1.俄罗斯方块 2 连连看 3 考试管理系统 4 食物链教学软件 5 约跑App 6 礼物挑选小工具 我的理由: 新峰的俄罗斯的方块,虽然当初的亮点没做出来,但是整体流程完 ...

  10. Building microservices with ASP.NET Core (without MVC)(转)

    There are several reasons why it makes sense to build super-lightweight HTTP services (or, despite a ...