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 ...
随机推荐
- Flex 的 多种对齐属性
1. html 结构 <div id="container"> <div class="item item-1"> <h3> ...
- Java基础语法Day_04
第11节 开发工具-IDEA day04_01_集成开发环境IDE的概述 day04_02_IntelliJ-IDEA的安装 day04_03_IDEA的项目结构 day04_04_IDEA的Hell ...
- XCTF练习题---MISC---3-11
XCTF练习题---MISC---3-11 flag:FLAG{LSB_i5_SO_EASY} 解题思路: 1.观察题目,下载附件 2.下载后是一张图片,根据习惯直接Stegsolve打开查看 3.通 ...
- 【面试普通人VS高手系列】volatile关键字有什么用?它的实现原理是什么?
一个工作了6年的Java程序员,在阿里二面,被问到"volatile"关键字. 然后,就没有然后了- 同样,另外一个去美团面试的工作4年的小伙伴,也被"volatile关 ...
- 安装与基本配置DHCP服务器
一,安装DHCP服务器角色 1,打开[开始]→[管理工具]→[服务器管理器]→"仪表板"选项的[添加角色和功能],持续单机[下一步]按钮, 直至出现下图所示的"选择服务器 ...
- 简单易懂的 Go 泛型使用和实现原理介绍
原文:A gentle introduction to generics in Go by Dominik Braun 万俊峰Kevin:我看了觉得文章非常简单易懂,就征求了作者同意,翻译出来给大家分 ...
- Spring配置及依赖注入
入门 <dependency> <groupId>org.springframework</groupId> <artifactId>spring-we ...
- 数仓选型必列入考虑的OLAP列式数据库ClickHouse(上)
概述 定义 ClickHouse官网地址 https://clickhouse.com/ 最新版本22.4.5.9 ClickHouse官网文档地址 https://clickhouse.com/do ...
- Git 不识别文件名字母大小写变化
问题 今天为一个项目撰写持续构建计划,撰写 Jenkinsfile 之后进行构建时报错: [2022-05-23 16:54:21] unable to prepare context: unable ...
- Typora详细教程以及下载
发现一篇非常不错的 Typora 教程,分享给大家. 原文链接:https://www.cnblogs.com/hyacinthLJP/p/16123932.html 作者:MElephant T ...