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?)+前缀和 因为看数据量比较大 就直接上前缀和了 一个比较简单的递推 没有太多难点 签到题 需要注意 ...
随机推荐
- Hyperledger Fabric中的Identity
Hyperledger Fabric中的Identity 什么是Identity 区块链网络中存在如下的角色:peers, orderers, client application, administ ...
- Cross origin requests are only supported for protocol schemes: http, data, chrome,chrome-extension的问题
Cross origin requests are only supported for protocol schemes: http, data, chrome,chrome-extension的问 ...
- 用了这么多年的MCU,你知道哪些MCU原厂最牛?
单片机诞生于1971年,经历了SCM.MCU.SoC三大阶段.单片机由以前的1位.4位.8位.16位,发展到现在的32位甚至64位. 90年代后随着消费电子产品大发展,单片机技术得到了巨大提高,相继诞 ...
- phpquery 学习笔记
phpQuery是一个基于PHP的服务端开源项目,它可以让PHP开发人员轻松处理DOM文档内容,比如获取某新闻网站的头条信息.更有意思的是,它采用了jQuery的思想,你可以像使用jQuery一样处理 ...
- Alpha阶段第2周/共2周 Scrum立会报告+燃尽图 02
此次作业要求参见 [https://edu.cnblogs.com/campus/nenu/2018fall/homework/2285] Scrum master:祁玉 一.小组介绍 组长:王一可 ...
- 王者荣耀交流协会 - 第6次Scrum会议
Scrum master :刘耀泽 补充:由于上次的scrum会议博客没有按时交上去,因此在这里给出上次scrum会议的链接: http://www.cnblogs.com/rensijia/p/76 ...
- 【每日scrum】NO.9
(1)这是我们冲刺的最后一天,晚上我们的团队进行了收尾工作:第一阶段的任务基本完成,软件主要实现了校园景点照片以及对应的介绍,查询最短路径,查询涉及相关景点的查询,查询全部路径,基本界面的设计,导航功 ...
- CSS中px和em属性的特点与区别
详解px和em的特点和区别象素px是我们在定义CSS中经常用到的尺寸大小单位,而em在国外网站中经常被使用,px和em之间究竟有什么区别和特点呢?◆px像素(Pixel),相对长度单位.像素px是相对 ...
- lintcode-205-区间最小数
205-区间最小数 给定一个整数数组(下标由 0 到 n-1,其中 n 表示数组的规模),以及一个查询列表.每一个查询列表有两个整数 [start, end]. 对于每个查询,计算出数组中从下标 st ...
- HashMap和HashTable源码分析
HashMap HashMap是一个实现了Map接口的Hash表.提供所有Map的操作,并且允许null key和null value.HashMap几乎等同于HashTable,只不过HashMap ...