CSU 多校训练第二场 J Pinemi Puzzles
传送门: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的更多相关文章
- 18牛客多校训练第二场 J farm
题意:一个n×m的农田, 每个小格子都有一种作物, 现在喷t次农药,每次农药覆盖一个矩形, 该矩形里面与农药类型不同的植物都会死掉, 求最后植物的死亡数是多少. 题解:二维树状数组. 每次喷农药的时候 ...
- 牛客网多校训练第一场 J - Different Integers(树状数组 + 问题转换)
链接: https://www.nowcoder.com/acm/contest/139/J 题意: 给出n个整数的序列a(1≤ai≤n)和q个询问(1≤n,q≤1e5),每个询问包含两个整数L和R( ...
- 2015多校训练第二场 hdu5305
把这题想复杂了,一直在考虑怎么快速的判断将选的边和已选的边无冲突,后来经人提醒发现这根本没必要,反正数据也不大开两个数组爆搜就OK了,搜索之前要先排除两种没必要搜的情况,这很容易想到,爆搜的时候注意几 ...
- 牛客网多校训练第二场D Kth Minimum Clique
链接:https://ac.nowcoder.com/acm/contest/882/D来源:牛客网 Given a vertex-weighted graph with N vertices, fi ...
- 2019HDU多校训练第二场 Longest Subarray
题意:给你一个串,问满足以下条件的子串中最长的是多长:对于每个数字,要么在这个子串没出现过,要么出现次数超过k次. 思路:对于这类问题,常常转化为数据结构的询问问题.我们考虑枚举右端点,对于当前右端点 ...
- 2020牛客暑期多校训练营 第二场 J Just Shuffle 置换 群论
LINK:Just Shuffle 比较怂群论 因为没怎么学过 置换也是刚理解. 这道题是 已知一个置换\(A\)求一个置换P 两个置换的关键为\(P^k=A\) 且k是一个大质数. 做法是李指导教我 ...
- 可持久化线段树的学习(区间第k大和查询历史版本的数据)(杭电多校赛第二场1011)
以前我们学习了线段树可以知道,线段树的每一个节点都储存的是一段区间,所以线段树可以做简单的区间查询,更改等简单的操作. 而后面再做有些题目,就可能会碰到一种回退的操作.这里的回退是指回到未做各种操作之 ...
- 牛客多校第3场 J 思维+树状数组+二分
牛客多校第3场 J 思维+树状数组+二分 传送门:https://ac.nowcoder.com/acm/contest/883/J 题意: 给你q个询问,和一个队列容量f 询问有两种操作: 0.访问 ...
- 2018牛客暑期ACM多校训练营第二场(有坑未填)
第二场终于等来学弟 开始(被队友带飞)的开心(被虐)多校之旅 A run A题是一个递推(dp?)+前缀和 因为看数据量比较大 就直接上前缀和了 一个比较简单的递推 没有太多难点 签到题 需要注意 ...
随机推荐
- Python基础入门(迭代器和生成器)
1 Python迭代器 迭代器是一个可以记住遍历的位置的对象. 迭代器对象从集合的第一个元素开始访问,直到所有的元素被访问完结束. 迭代器只能往前不会后退. 迭代器有两个基本的方法:iter() 和 ...
- 杂谈微服务架构下SSO&OpenAPI访问的方案。
本篇杂谈下微服务架构下WEB应用的浏览器与OpenAPI访问架构与方案.读者可对比传统架构下应用的此话话题的区别.或者有其它方案的欢迎交流
- Linux内核学习笔记(2)-- 父进程和子进程及它们的访问方法
Linux系统中,进程之间有一个明显的继承关系,所有进程都是 PID 为1的 init 进程的后代.内核在系统启动的最后阶段启动 init 进程.该进程读取系统的初始化脚本(initscript)并执 ...
- 算法笔记(c++)--01背包问题
算法笔记(c++)--经典01背包问题 算法解释起来太抽象了.也不是很好理解,最好的办法就是一步步写出来. 背包问题的核心在于m[i][j]=max(m[i-1][j],m[i-1][j-w[i]]+ ...
- Linux虚拟机centos系统安装
linux 其他知识目录 安装完后如果虚拟机网络不通请参考:虚拟机网络不通故障解决 1.centos6.9安装 后面安装出了点问题,ip没有并且eth0网卡找不到,不过重新配置ifcfg-eth0后重 ...
- Thunder——互评beta版本
基于NABCD和spec评论作品 Hello World!:http://www.cnblogs.com/vector121/p/7922989.html 欢迎来怼:http://www.cnblog ...
- .net web 应用程序C#
简介 开发环境:VS2015 ASP.NET:可以开发出几乎所有运行在Windows上的应用程序:.NET是一种架构,一种新的API:引入程序集代替DLL: ADO.NET:一组.NET组件提供对数据 ...
- c# HttpListener拒绝访问
直接记录解决步骤: 程序代码: HttpListener httpListener = new HttpListener(); httpListener.Prefixes.Add("http ...
- CoordinatdBolt原理分析
参考链接:http://xumingming.sinaapp.com/811/twitter-storm-code-analysis-coordinated-bolt/ CoordinatedBolt ...
- ubuntu 手动apache记录
1.下载apache tar -xvzf httpd.xx 解压 2.下载安装pcre Download PCRE from PCRE.org 解压,进入文件夹中 ./configure --pre ...