题集链接

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. 《手写Mybatis》第5章:数据源的解析、创建和使用

    作者:小傅哥 博客:https://bugstack.cn 沉淀.分享.成长,让自己和他人都能有所收获! 一.前言 管你吃几碗粉,有流量就行! 现在我们每天所接收的信息量越来越多,但很多的个人却没有多 ...

  2. Android C/C++层hook和java层hook原理以及比较

    作者:Denny Qiao(乔喜铭),云智慧/架构师. 云智慧集团成立于2009年,是全栈智能业务运维解决方案服务商.经过多年自主研发,公司形成了从IT运维.电力运维到IoT运维的产业布局,覆盖ITO ...

  3. CA周记 - 带你进⼊ OpenAI 的世界

    2021年11月的 Microsoft Ignite , 微软带来了全新的 Azure OpenAI Service,通过新的 Azure 认知服务能够访问 OpenAI 强大的 GPT-3 模型 . ...

  4. 在C#中使用 SendMessage 实现操作外部其他程序上的控件教程

    一.C#代码实现 本案例使用的是c# winform .NET Framework 4.7.2 首先我们声明一个寻找窗体的函数 [DllImport("User32.dll", E ...

  5. [AcWing 29] 删除链表中重复的节点

    点击查看代码 /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * L ...

  6. SpringBoot程序预装载数据

    简介 在项目实际的开发过程中,有时候会遇到需要在应用程序启动完毕对外提供服务之前预先将部分数据装载到缓存的需求.本文就总结了常见的数据预装载方式及其实践. 适用场景 预装载应用级别数据到缓存:如字典数 ...

  7. selenium模块使用详解、打码平台使用、xpath使用、使用selenium爬取京东商品信息、scrapy框架介绍与安装

    今日内容概要 selenium的使用 打码平台使用 xpath使用 爬取京东商品信息 scrapy 介绍和安装 内容详细 1.selenium模块的使用 # 之前咱们学requests,可以发送htt ...

  8. 理解ASP.NET Core - 发送Http请求(HttpClient)

    注:本文隶属于<理解ASP.NET Core>系列文章,请查看置顶博客或点击此处查看全文目录 前言 在.NET中,我们有很多发送Http请求的手段,如HttpWebRequest.WebC ...

  9. linux篇-修改mysql数据库密码

    总是忘记,每次都要查文档,背背背 方法1: 用SET PASSWORD命令 首先登录MySQL. 格式:mysql> set password for 用户名@localhost = passw ...

  10. 148_赠送300家门店260亿销售额的零售企业Power BI实战示例数据

    焦棚子的文章目录 一背景 2022年即将到来之际,笔者准备在Power BI中做一个实战专题,作为实战专题最基础的就是demo数据,于是我们赠送大家一个300家门店,260亿+销售额,360万行+的零 ...