牛客国庆集训day6 B Board (模拟标记思维或找规律或分块???)
链接:https://www.nowcoder.com/acm/contest/206/B
来源:牛客网
题目描述
开始时,数组中每一个元素都是0。
恬恬会做某些操作。在一次操作中,她可以将某一行的所有元素同时加上一个值,也可以将某一列的所有元素同时加上一个值。
在几次操作后,一个元素被隐藏了。你能帮助她回忆隐藏的数是几吗?
输入描述:
- 第一行一个整数n(1≤ n≤ 1000)。
接下来n行每行n个整数表示数组a。
第(i+1)行的第j个元素表示a
ij
- (a
ij
- =-1或0≤ a
ij
- ≤ 10000)。-1表示隐藏的元素。
输出描述:
- 仅一个整数表示答案。
输入例子:
- 3
- 1 2 1
- 0 -1 0
- 0 1 0
输出例子:
- 1
-->
输出
- 1
- #include <iostream>
- #include <stdio.h>
- #include <math.h>
- #include <string.h>
- #include <stdlib.h>
- #include <string>
- #include <vector>
- #include <set>
- #include <map>
- #include <queue>
- #include <algorithm>
- #include <sstream>
- #include <stack>
- using namespace std;
- #define rep(i,a,n) for (int i=a;i<n;i++)
- #define per(i,a,n) for (int i=n-1;i>=a;i--)
- #define pb push_back
- #define mp make_pair
- #define all(x) (x).begin(),(x).end()
- #define fi first
- #define se second
- #define SZ(x) ((int)(x).size())
- #define FO freopen("in.txt", "r", stdin);
- #define debug(x) cout << "&&" << x << "&&" << endl;
- #define lowbit(x) (x&-x)
- #define mem(a,b) memset(a, b, sizeof(a));
- typedef vector<int> VI;
- typedef long long ll;
- typedef pair<int,int> PII;
- const ll mod=;
- const int inf = 0x3f3f3f3f;
- ll powmod(ll a,ll b) {ll res=;a%=mod;for(;b;b>>=){if(b&)res=res*a%mod;a=a*a%mod;}return res;}
- ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
- //head
- const int maxn=;
- int n,a[maxn][maxn];
- int main() {
- scanf("%d",&n);
- rep(i,,n) {
- rep(j,,n) {
- scanf("%d",&a[i][j]);
- if(a[i][j]==-) {
- a[i][j]=inf;//-1位置设为inf
- }
- }
- }
- rep(i,,n) {//找每一行的最小值
- int minn=inf;
- rep(j,,n) {
- if(a[i][j]<minn)
- minn=a[i][j];
- }
- if(minn!=) rep(j,,n) a[i][j]-=minn;//最小值不为0 减
- }
- rep(i,,n) {//找每一列的最小值
- int minn=inf;
- rep(j,,n) {
- if(a[j][i]<minn)
- minn=a[j][i];
- }
- if(minn!=) rep(j,,n) a[j][i]-=minn;//最小值不为0 减
- }
- //最后肯定是-1的位置还有数(>0) 其他位置为0
- int ans=;
- rep(i,,n) {
- rep(j,,n) {
- if(a[i][j]>)
- ans=inf-a[i][j];//差值即原数
- }
- }
- printf("%d",ans);
- }
还有这样的解法,但是不知道为什么?纯找规律?
- #include<bits/stdc++.h>
- using namespace std;
- int a[][];
- int main(){
- int n,i,j,x,y;
- //freopen("in.txt","r",stdin);
- scanf("%d",&n);
- for(i=;i<=n;i++)
- for(j=;j<=n;j++)
- {
- scanf("%d",&a[i][j]);
- if(a[i][j]==-) x=i,y=j;
- }
- int fx,fy;
- if(x==n) fx=x-; else fx=x+;
- if(y==n) fy=y-; else fy=y+;
- printf("%d\n",a[x][fy]+a[fx][y]-a[fx][fy]);
- return ;
- }
还有一种思想,大佬说是分块??有一点点明白,就是分成n块,每行每列加一个数,那么n块都加上了,也就是说,这n块加的数是相同的。 (i+j)%n分块
- #include<cstdio>
- #include<algorithm>
- using namespace std;
- int ans[],N;
- int main()
- {
- scanf("%d",&N);
- int x,t;
- for(int i=;i<N;i++)
- for(int j=;j<N;j++)
- {
- scanf("%d",&x);
- if(x!=-)
- ans[(i+j)%N]+=x;
- else t=(i+j)%N;//-1的块
- }
- printf("%d\n",ans[(t+)%N]-ans[t]);//其他块 - (-1的块)
- return ;
- }
牛客国庆集训day6 B Board (模拟标记思维或找规律或分块???)的更多相关文章
- 牛客国庆集训派对Day6 A Birthday 费用流
牛客国庆集训派对Day6 A Birthday:https://www.nowcoder.com/acm/contest/206/A 题意: 恬恬的生日临近了.宇扬给她准备了一个蛋糕. 正如往常一样, ...
- 2019牛客国庆集训派对day5
2019牛客国庆集训派对day5 I.Strange Prime 题意 \(P=1e10+19\),求\(\sum x[i] mod P = 0\)的方案数,其中\(0 \leq x[i] < ...
- 牛客国庆集训day5 G 贵族用户 (模拟)
链接:https://www.nowcoder.com/acm/contest/205/G来源:牛客网 题目描述 终于活成了自己讨厌的样子. 充钱能让你变得更强. 在暖婊这个游戏里面,如果你充了x元钱 ...
- 牛客国庆集训派对Day_4~6
Day_4 A.深度学习 题目描述 小 A 最近在研究深度学习,他自己搭建了一个很牛逼的神经网络,现在他手头一共有 n 组训练数据,一开始他会给自己的神经网络设置一个 batch size,假设为 B ...
- 牛客国庆集训派对Day1 L-New Game!(最短路)
链接:https://www.nowcoder.com/acm/contest/201/L 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 1048576K,其他语言20 ...
- 牛客国庆集训派对Day4 J-寻找复读机
链接:https://www.nowcoder.com/acm/contest/204/J 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 1048576K,其他语言20 ...
- 牛客国庆集训派对Day4 I-连通块计数(思维,组合数学)
链接:https://www.nowcoder.com/acm/contest/204/I 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 1048576K,其他语言20 ...
- 牛客国庆集训派对Day1-C:Utawarerumono(数学)
链接:https://www.nowcoder.com/acm/contest/201/C 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 1048576K,其他语言20 ...
- 牛客国庆集训派对Day2 Solution
A 矩阵乘法 思路: 1° 牛客机器太快了,暴力能过. #include <bits/stdc++.h> using namespace std; #define N 5000 in ...
随机推荐
- appium_python 怎样实现参数化自动生成用例
1.对于一种对同一个页面同一点 要用不同数据测试形成多条测试用例,如果复制的话 会让代码很冗长,并且并不好维护,现在用封装的方法把 不变的代码 和 变化的参数 分别封装,形成动态 生成测试用例 ,主要 ...
- 1106SQLserver基础--变量、运算符的使用,if...else,while语句
数据库---变量(对数据库中的数据没有任何影响) 作用:临时存储数据的作用,起一个衔接的作用,为了方便理解存储过程. 例:Declare @hello varchar(20) Set @hello=’ ...
- C# 正规表达式
在C#中怎么用正则表达式限制文本框内不能输入数字?只能输入数字:"^[0-9]*$".只能输入n位的数字:"^\d{n}$".只能输入至少n位的数字:" ...
- eclipse安卓模拟器Failed to install on device 'emulator-5554': timeout处理方案
我们在用模拟器调试的时候,经常会出现Failed to install on device 'emulator-5554': timeout这个错误.其实就是有些虚拟器在部署的时候时间过于长.系统就认 ...
- python之Dict和set类型
Dict就是一种key:value的表格: >>> d = { 'Adam':95, 'Lisa':85, 'Bart':59, 'Paul':75 } >>> p ...
- MyBatis总结四:配置文件xml详解
XML 映射配置文件 MyBatis 的配置文件包含了影响 MyBatis 行为甚深的设置(settings)和属性(properties)信息.文档的顶层结构如下: configuration 配置 ...
- PHP算法
一,实现快速排序 <?php function quickSort($arr) { $len=count($arr) ; if($len<=1) { return $arr; } $key ...
- Ajax01 什么是ajax、获取ajax对象、ajax对象的属性和方法、编程步骤、缓存问题、乱码问题
目录 1 什么是ajax 2 获取ajax对象 3 ajax对象的属性和方法 4 使用ajax的编程步骤 5 缓存问题 6 乱码问题 1 什么是ajax ajax是一种用来改善用户体验的技术,其本质是 ...
- win10获取超级管理员权限脚本实现
建立一个TXT文件,把下面的脚本贴到里面,然后把后缀改成reg格式,双击添加到注册表就可以了, win10_1703版本亲测可用.... Windows Registry Editor Version ...
- 高性能MySQL笔记-第5章Indexing for High Performance-005聚集索引
一.聚集索引介绍 1.什么是聚集索引? InnoDB’s clustered indexes actually store a B-Tree index and the rows together i ...