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< ...
随机推荐
- c和c++开发工具之clion和vs
个人体验结果 如果是CMake或者要跨平台的话,建议使用CLion 像我在看书写练习题的话,Clion使用cmake编译c/c++源码更简单上手使用. 如果项目不大,两者都可以.如果关联子项目或第三方 ...
- 文心千帆:PPT 制作、数字人主播一键开播等数十种应用场景惊艳到我了,下面给出简介和使用指南,快去使用起来吧
文心千帆:PPT 制作.数字人主播一键开播等数十种应用场景惊艳到我了,下面给出简介和使用指南,快去使用起来吧 文心千帆大模型平台是面向企业开发者的一站式大模型开发及服务运行平台.文心千帆不仅提供了包括 ...
- 5.11 汇编语言:仿写IF条件语句
条件语句,也称为IF-ELSE语句,是计算机编程中的一种基本控制结构.它允许程序根据条件的真假来执行不同的代码块.条件语句在处理决策和分支逻辑时非常有用.一般来说,条件语句由IF关键字.一个条件表达式 ...
- 通过URL载入ShellCode代码
将生成的shellcode放到web服务器上,本地不保存恶意代码,本地只负责加载到内存运行,这样可以很好的躲过查杀. 生成shellcode msfvenom -a x86 --platform Wi ...
- C/C++ Qt 使用JSON解析库 [修改篇]
JSON是一种轻量级的数据交换格式,它是基于ECMAScript的一个子集,使用完全独立于编程语言的文本格式来存储和表示数据,简洁清晰的的层次结构使得JSON成为理想的数据交换语言,Qt库为JSON的 ...
- python-ssh链接linux查询日志,并按日志等级在控制台分颜色输出日志
import paramiko # unicode_utils.py def to_str(bytes_or_str): """ 把byte类型转换为str :param ...
- [Java] 解析Xml配置文件
1.解析方法 import javax.xml.parsers.DocumentBuilder;import javax.xml.parsers.DocumentBuilderFactory;impo ...
- Mocha MemoryBufferQueue 设计概述
目录 前言 MemoryBufferQueue 功能概述 Buffer 模块 API 设计 MemoryBufferQueue 的设计 Partition 的设计 对并发的支持 Partition 的 ...
- Web入门:JavaScript文字动画
欢迎来的我的小院,恭喜你今天又要涨知识了! 案例内容 利用JavaScript实现文字逐步展现的动画效果. 演示 学习 <!DOCTYPE html> <html lang=&quo ...
- 国产数据库TiDB初体验:简单易用,快速上手
最近开始关注国产数据库的发展,为了能从技术人员的角度来实际体验国产中目前最流行的TiDB数据库,从今天起,在官方公布的课程开始正面了解TiDB的设计理念. 看了2小时的入门课程介绍,总体来说,还是有不 ...