21 Educational Codeforces Round 136 (Rated for Div. 2)Knowledge Cards(树状数组、set、+思维、数字华容道)
最开始猜了个结论错了,猜的是必须要有\(m+n-1\)个方格空着,这样才能保证任意一张牌能从起点到终点。
其实并不是,参考数字华容道,实际上是只要除了终点和起点,以及自身这个方格。我们只需要留出一个空格就可以使任意方格移动到任意位置。
我们只需要统计一下,一个数前面比他小的数有多少个,然后取个最大值,就是最大的要使这个牌按顺序到达终点,其它牌不能到达终点的情况,这时应该时满足\(m * n-4>=mx\)所有的就都可以满足。
#include <bits/stdc++.h>
#define int long long
#define rep(i, a, b) for(int i = (a); i <= (b); ++i)
#define fep(i, a, b) for(int i = (a); i >= (b); --i)
#define _for(i, a, b) for(int i=(a); i<(b); ++i)
#define pii pair<int, int>
#define pdd pair<double,double>
#define ll long long
#define db double
#define endl '\n'
#define fs first
#define sc second
#define pb push_back
#define vi vector<int>
using namespace std;
const int maxn = 1e6 + 10;
int a[maxn],tr[maxn],n,m,k;
int lowbit(int x){
return x&-x;
}
void add(int x, int d){
for(int i=x;i<=k;i+=lowbit(i)){
tr[i]+=d;
}
}
int ask(int x){
int res=0;
for(int i=x;i;i-=lowbit(i)){
res+=tr[i];
}
return res;
}
void solve() {
cin>>n>>m>>k;
rep(i,1,k){
tr[i]=0;
}
rep(i,1,k){
cin>>a[i];
}
int res=0;
rep(i,1,k){
res=max(res,ask(a[i]));
add(a[i],1);
}
if(n*m-4>=res){
cout<<"YA\n";
}else{
cout<<"TIDAK\n";
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// freopen("C:\\Users\\24283\\CLionProjects\\untitled2\\1.in", "r", stdin);
int _;
cin >> _;
while (_--)
solve();
return 0;
}
``
21 Educational Codeforces Round 136 (Rated for Div. 2)Knowledge Cards(树状数组、set、+思维、数字华容道)的更多相关文章
- Educational Codeforces Round 80 (Rated for Div. 2)E(树状数组,模拟,思维)
#define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ],mx[],a[],pos[],sum ...
- Educational Codeforces Round 63 (Rated for Div. 2) B. Game with Telephone Numbers 博弈思维+模拟+贪心思维
题意:博弈题面 给出一个数字序列 (>=11) 有两个人任意删除数字 直到 数字只剩下11位 如果删除后的数字串开头是8那么就是第一个赢 否则就是第二个人赢 第一个人先手 数字序列一定是奇 ...
- Educational Codeforces Round 61 (Rated for Div. 2) G(线段树,单调栈)
#include<bits/stdc++.h>using namespace std;int st[1000007];int top;int s[1000007],t[1000007];i ...
- Educational Codeforces Round 62 (Rated for Div. 2)E(染色DP,构造,思维,组合数学)
#include<bits/stdc++.h>using namespace std;const long long mod=998244353;long long f[200007][2 ...
- Educational Codeforces Round 61 (Rated for Div. 2)D(二分,模拟,思维)
#include<bits/stdc++.h>using namespace std;typedef long long ll;int n,k;ll a[200007],b[200007] ...
- Educational Codeforces Round 33 (Rated for Div. 2) B. Beautiful Divisors【进制思维/打表】
B. Beautiful Divisors time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Educational Codeforces Round 71 (Rated for Div. 2)-E. XOR Guessing-交互题
Educational Codeforces Round 71 (Rated for Div. 2)-E. XOR Guessing-交互题 [Problem Description] 总共两次询 ...
- Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship
Problem Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...
- Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)
Problem Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...
- Educational Codeforces Round 43 (Rated for Div. 2)
Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...
随机推荐
- Fabric-ca server端与client端交互
本文介绍Fabric-ca server端和client端的交互过程. 在server端执行Start()命令时,会调用registerHandlers()函数,其作用就是注册处理客户端请求的程序: ...
- 在bat中切换盘符
在bat代码中如何在不同的盘符中切换?直接输入盘符的名字,前面不要加cd,示例 cd %~dp0 d: cd D:\Python37 e: cd E:\Code\KSFramework c: cd C ...
- springboot项目导入外部jar包的bean的几种方式
背景 公司封装了基础包和日志包,将公共的配置抽取出来,供所有项目使用,因此就需要考虑,怎么引入外部jar包的Bean实例: 思考 因为公司的jar包就是普通的jar,不支持springboot的自动配 ...
- 爱了爱了!推荐一个Github 70k+点赞的Java学习指南!
大家好,我是 Guide 哥!今天给大家推荐一个非常不错的 Java 教程类开源项目-JavaGuide ,Github 地址: https://github.com/Snailclimb/JavaG ...
- 神经网络优化篇:将 Batch Norm 拟合进神经网络(Fitting Batch Norm into a neural network)
将 Batch Norm 拟合进神经网络 假设有一个这样的神经网络,之前说过,可以认为每个单元负责计算两件事.第一,它先计算z,然后应用其到激活函数中再计算a,所以可以认为,每个圆圈代表着两步的计算过 ...
- Kubernetes:kube-scheduler 源码分析
0. 前言 [译] kubernetes:kube-scheduler 调度器代码结构概述 介绍了 kube-scheduler 的代码结构.本文围绕代码结构,从源码角度出发,分析 kube-sche ...
- Collectors.toMap的暗坑与避免方式
使用Java的stream中的Collectors可以很方便地做容器间的转换,可以少写很多代码.但是其中有暗含的坑需要注意和避免,本文探讨Collectors.toMap(JDK8版本). Colle ...
- 记录一则exachk进程占用大量CPU资源
有Exadata客户在进行exachk巡检之后反馈,发现系统中,exachk进程占用了大量CPU资源. 了解之前的变更,只是巡检之前升级了AHF,然后进行标准的exachk巡检. 现象: 目前机器整体 ...
- 小知识:MySQL配置文件优先级
今天在RHEL7上,严格按之前的安装规范文档,部署MySQL环境时,发现通过服务的方式启动MySQL失败: 关键错误是: log-error set to '/var/log/mariadb/mari ...
- 长沙IT技术圈百万年薪大佬?是否存在?
引子 不知不觉,IT技术圈开始流传起"百万年薪"的故事,有人问我,长沙有百万大佬么?其实我也不知道. 一 背景 长沙自古以来就是文风鼎盛之地,在今天也同样如此. 目前长沙有211. ...