传送门: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. 从零开始的Python学习Episode 7——文件基本操作

    文件基本操作 一.打开文件 f = open('11','r')#open('file path','mode') 创建一个文件对象 文件有多种打开模式: 1. 'r':新建一个文件对象以只读方式打开 ...

  2. .NET导出Excel之NPOI

    前段时间研究过微软的Excel导出.table输出Excel,而它们也存在一些弊端: 1.对于微软的Excel导出存在一些弊端,如:需要安装Office软件.速度问题: 2.table输出Excel在 ...

  3. Action Required: Please provide your Tax Identity Information - Amazon Seller Tax Identity Collection

    Hello ***,   Your selling privileges have been suspended because we have not received required tax i ...

  4. Scrum立会报告+燃尽图(十月二十日总第十一次)

    此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2246 项目地址:https://git.coding.net/zhang ...

  5. Python:元组操作总结

    Python的元组和列表类似,不同之处在于元组中的元素不能修改(因此元组又称为只读列表),且元组使用小括号而列表使用中括号,如下: tup1=('physics','chemistry',1997,2 ...

  6. c# Webservice技术整理

    因为平常项目中使用webservice比较少,然后就将本来不太熟悉的webservice给忘记掉了.所以再次整理如下: 百度搜索关键词 :c# webservice 1. 联接地址: http://w ...

  7. 第22章 软件安装:源码与Tarball

    开放源码的软件安装与升级简介 什么是开放源码.编译程序与可执行文件 开放源码:程序代码,写给人类看的程序语言 编译程序:将源码编译成机器能看得懂的语言 可执行文件:经过编译变成二进制程序后机器看得懂可 ...

  8. Beta阶段冲刺第二天

    提供当天站立式会议照片一张 讨论项目每个成员的昨天进展 错题集功能编写没有彻底完成. 界面改善 测试数据库连接 讨论项目每个成员的存在问题 邹其元:错题集功能需要用到数据库,现在要解决的问题是怎样把数 ...

  9. CCF——图像旋转201503-1

    问题描述 旋转是图像处理的基本操作,在这个问题中,你需要将一个图像逆时针旋转90度. 计算机中的图像表示可以用一个矩阵来表示,为了旋转一个图像,只需要将对应的矩阵旋转即可. 输入格式 输入的第一行包含 ...

  10. php 多维数组排序

    PHP中array_multisort可以用来一次对多个数组进行排序,或者根据某一维或多维对多维数组进行排序. 关联(string)键名保持不变,但数字键名会被重新索引. 输入数组被当成一个表的列并以 ...