Codeforces Round #801 (Div. 2)
A Subrectangle Guess
代码
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
const int N = 1e6;
void solve()
{
ll mis = -1e10;
int a, b, n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
{
ll sa;
cin >> sa;
if (sa > mis)
{
mis = sa;
a = i;
b = j;
}
} int x = max(a, n - a + 1);
int y = max(b, m - b + 1);
cout << x * y << endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}
B Circle Game
题意
有若干堆石子围成一个圆,第一个选手从第一堆开始取走任意个,然后第二个选手从前一个选手取的后一堆取走任意个,先不能取的输,谁会赢?
分析
如果石子有奇数堆那么先手必胜,因为先手可以一直全部取完,这样后手取到第一堆的时候就没有石子可取了.
如果石子有偶数堆,那么先手只能取奇数堆的石子,后手只能取偶数堆的石子,所以最优策略是每次少取,也就是每次取一个.所以如果只需比较奇数堆和偶数堆的最小值即可,如果最小值相等,最小值在前的必败.
代码
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
const int N = 1e6;
void solve()
{
int n;
cin >> n;
int s[n + 1];
for (int i = 1; i <= n; i++)
cin >> s[i];
if (n % 2 == 1)
{
cout << "Mike\n";
return;
}
int s1 = 100, s2 = 100;
int m1 = 1e9 + 23, m2 = 1e9 + 23;
for (int i = 1; i <= n; i = i + 2)
if (m1 > s[i])
{
m1 = s[i];
s1 = i;
}
else if (m1 == s[i] && s1 > i)
s1 = i;
for (int i = 2; i <= n; i = i + 2)
if (m2 > s[i])
{
m2 = s[i];
s2 = i;
}
else if (m2 == s[i] && s2 > i)
s2 = i;
if (m2 > m1)
cout << "Joe\n";
else if (m2 == m1 && s2 > s1)
cout << "Joe\n";
else
cout << "Mike\n";
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}
C Zero Path
题意
给出一个权值只有 +1 和 -1 的矩阵,只能往下或者往右走,问是否能从左上走到右下使得路径之和为 0.
分析
首先如果 n+m 为偶数,那么路径和一定是奇数,所以一定走不到.
否则我们可以用两次 dp 分别求出左上走到右下路径的最大值和最小值,如果0在最大值和最小值之间说明存在这样的路径.
简易证明,因为 n+m 为奇数那么最后得到的值一定为偶数,每次微调会导致结果差2,因次只要0在最大值和最小值之间就可以通过微调得到.
比赛时证明不必要非常严谨,需要一点直觉猜测,有时候可以蒙一下.
代码
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
const int N = 1e3 + 233;
int dp1[N][N]; //最大
int dp2[N][N]; //最小
void solve()
{
int n, m;
cin >> n >> m;
int s[n + 1][m + 1]; for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
cin >> s[i][j];
if ((n + m) % 2 == 0)
{
cout << "NO\n";
return;
}
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
{
if (i == 1)
{
dp1[i][j] = s[i][j] + dp1[i][j - 1];
dp2[i][j] = s[i][j] + dp2[i][j - 1];
}
if (j == 1)
{
dp1[i][j] = s[i][j] + dp1[i - 1][j];
dp2[i][j] = s[i][j] + dp2[i - 1][j];
}
if (i != 1 && j != 1)
{
dp1[i][j] = s[i][j] + max(dp1[i][j - 1], dp1[i - 1][j]);
dp2[i][j] = s[i][j] + min(dp2[i][j - 1], dp2[i - 1][j]);
}
}
if (dp1[n][m] >= 0 && dp2[n][m] <= 0)
cout << "YES\n";
else
cout << "NO\n";
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}
Codeforces Round #801 (Div. 2)的更多相关文章
- Codeforces Round #801 (Div. 2) and EPIC Institute of Technology Round(C,D题解)
Codeforces Round #801 (Div. 2) and EPIC Institute of Technology Round C - Zero Path 在这道题目中,不可以真正地进行寻 ...
- Codeforces Round #801 (Div. 2) C(规律证明)
Codeforces Round #801 (Div. 2) C(规律证明) 题目链接: 传送门QAQ 题意: 给定一个\(n * m\)的矩阵,矩阵的每个单元的值为1或-1,问从\((1,1)\)开 ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
- Codeforces Round #262 (Div. 2) 1004
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...
随机推荐
- 基于深度学习的人脸性别识别系统(含UI界面,Python代码)
摘要:人脸性别识别是人脸识别领域的一个热门方向,本文详细介绍基于深度学习的人脸性别识别系统,在介绍算法原理的同时,给出Python的实现代码以及PyQt的UI界面.在界面中可以选择人脸图片.视频进行检 ...
- 解决:Could not resolve dependencies for project xxx: Could not find artifact xxx
引言 运行A module,找不到B module的依赖报错.A.B module都在project中. 报错信息 [INFO] Scanning for projects... [INFO] [IN ...
- DevOps、CI、CD都是什么鬼?
关注「开源Linux」,选择"设为星标" 回复「学习」,有我为您特别筛选的学习资料~ DevOps DevOps是Development和Operations的组合,是一种方法论, ...
- IT人的修炼之路
前言 计算机技术更新迭代的速度太快了,作为ITer每天除了面对工作,就要学习新技术,自己的感觉是一直在为技术疲于奔命,直到现在,也不敢放缓脚步.程序员每天必须抽出一定时间学习新技术,避免被淘汰. 1. ...
- WSL与Windows环境共享
Reference 更多cmd.exe帮助参考 cmd_helps WSL备份及windows Docker安装 WSL安装维护 在使用wsl时,总是需要执行windows的cmd,但是windows ...
- css自定义省略实例2
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- kvm 虚拟化技术 1.3之kvm克隆以及快照
1.kvm虚拟机克隆 克隆kvm虚拟机 ,克隆前需要提前关机 语法: virt-clone -o 原虚拟机 -n 新虚拟机 -f 新虚拟机镜像存放路径 选项中-o 表示 old ...
- idea maven 依赖还原不上的问题 method <init>()V not found
问题 还原项目依赖的时候报错: java.lang.RuntimeException: org.codehaus.plexus.component.repository.exception.Compo ...
- 机构:DARPA
DARPA,美国国防部高级研究计划局. 2021年3月19日,英特尔(Intel)宣布与美国国防部高级研究计划局(DARPA)达成的一项新合作,旨在推动在美制造的专用集成电路(ASIC)芯片的开发. ...
- RapidIO 逻辑层IO操作与Message操作的原理和区别
接上一篇 SRIO RapidIO (SRIO)协议介绍(一) 1 说明 查看协议手册时会发现,逻辑层的操作分成了IO和Message 2类动作,那么为什么要分成2类操作?从原理和应用角度来看 ...