题集链接

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;
}

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;
}

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)的更多相关文章

  1. 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 在这道题目中,不可以真正地进行寻 ...

  2. Codeforces Round #801 (Div. 2) C(规律证明)

    Codeforces Round #801 (Div. 2) C(规律证明) 题目链接: 传送门QAQ 题意: 给定一个\(n * m\)的矩阵,矩阵的每个单元的值为1或-1,问从\((1,1)\)开 ...

  3. 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 ...

  4. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  5. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  6. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  7. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. 算法篇(1) KMP JS实现最优查找子串

    var strStr = function (haystack, needle) { let i=0, j = 0; let length = haystack.length; let next = ...

  2. [AcWing 822] 走方格

    点击查看代码 #include<iostream> using namespace std; int n, m, ans = 0; void dfs(int x, int y) { if ...

  3. Libco Hook 机制浅析

    Libco Hook 机制浅析 之前的文章里我们提到过 Libco 有一套 Hook 机制,可以通过协程的让出(yield)原语将系统的阻塞系统调用改造为非阻塞的,这篇文章我们将深入解析 Hook 机 ...

  4. 2003031121-浦娟-python数据分析第三周作业-第一次作业

    项目 内容 课程班级博客链接 https://edu.cnblogs.com/campus/pexy/20sj 作业链接 https://edu.cnblogs.com/campus/pexy/20s ...

  5. 基于casbin的RBAC权限实践

    五一假期疫情封在家也没事做,就想来优化一下一个前端容器小项目 之前的TODOlist里面有一项是权限这块时隔2年了还一直没有动手 迟迟没搞主要还是我太懒了,哈哈 其实我一直想要找一个轻量级的权限通用方 ...

  6. 详解:什么是VXLAN?

    点击上方"开源Linux",选择"设为星标"回复"学习"获取独家整理的学习资料! 本文介绍了什么是VXLAN,以及VXLAN的基本概念和工作 ...

  7. GitHub 桌面版 v3.0 新特性「GitHub 热点速览」

    新版本一般意味着更强的功能特性,比如 GitHub Desktop v3.0.虽然未发布新版本,但本周收录的 7 个开源项目颇有"新版"味.比如,破解(恢复)密码能力 Max 的 ...

  8. 深入了解tomcat中servlet的创建方式实现

    Tomcat如何创建Servlet? A.先到缓存中寻找有没有这个对象(Servlet是单实例的,只会创建一次) 如果没有: 1.通过反射去创建相应的对象(执行构造方法) 2.tomcat会把对象存放 ...

  9. 关闭BottomSheetDialogFragment从后台返回后的动画

    问题 显示BottomSheetDialogFragment后.将当前应用放于后台,切换到其他APP,然后再返回当前应用.此时会看到BottomSheetDialogFragment从下而上的动画再次 ...

  10. scrapy框架第二天

    1.scrapy数据分析 2.scrapy持久化存储 3.全站数据爬取 4.请求传参  +   五大核心组件 - 创建scrapy工程 scrapy startproject ProName - 切换 ...