首页 > 其他分享 >C. Game on Permutation

C. Game on Permutation

时间:2024-05-05 19:23:53浏览次数:13  
标签:int lst cin ++ Game Permutation include ptr

链接:https://codeforces.com/problemset/problem/1860/C
洛谷链接:https://www.luogu.com.cn/problem/CF1860C
相关知识点复习:LIS最长上升子序列
链接:https://blog.csdn.net/lxt_Lucia/article/details/81206439
关键:

这题的思路在于找到LIS长度为2的点,
比如1 3 2 5 4那么显然3,2是,4,5不是,虽然3是,但不影响2是,所以我们可以看出判断是不是的通用办法:把lis插入的位置判断:如果是在第二个位置插入就ans++。
代码:

#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<sstream>
#include<string>
#include<string.h>
#include<iomanip>
#include<stdlib.h>
#include<map>
#include<queue>
#include<cmath>
#include<limits.h>
#include<climits>
#include<fstream>
#include<stack>
#include<set>
typedef long long ll;
using namespace std;
const int N = 3e5 + 10;
int lst[N];
int a[N];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int t; cin >> t;
	while (t--)
	{
		memset(a, 0, sizeof(a));
		int n; cin >> n; int ptr = 0;
		for (int i = 0; i < n; i++)cin >> lst[i];
		a[ptr] = lst[0];
		int ans = 0;
		for (int i = 1; i < n; i++)
		{
			if (lst[i] > a[ptr])//特判
			{
				ptr++;
				a[ptr] = lst[i];
				if(ptr==1)ans++;//here!
			}
			else
			{
				int l = 0, r = ptr;
				while (l < r)
				{
					int mid = l + (r - l) / 2;
					if (a[mid] > lst[i])r = mid;
					else l = mid + 1;
				}
				if (l == 1)ans++;//here:采用的是0开头
				a[l] = lst[i];
			}
		}
		cout << ans << '\n';
		
	}
	return 0;
}

刚开始读错题了,可恶!

标签:int,lst,cin,++,Game,Permutation,include,ptr
From: https://www.cnblogs.com/zzzsacmblog/p/18173753

相关文章

  • Codeforces 452F Permutation
    对于\(a,b,\frac{a+b}{2}\)肯定是需要固定下一些变量来考虑的。考虑固定下\(c=\frac{a+b}{2}\),考虑\(a,b\)。那么这样的\(a,b\)肯定满足\(a-c=b-c,a\not=b\),那么以\(c\)为中心,\(a,b\)就是对称的。用\(s_i=0,1\)来表示\(i\)是在\(c\)的......
  • hgame2023 vm
    vm逆向hgame2023vm简单翻阅一下发现,sub_140001000里面是vm_init,sub_1400010B0是主要的vm部分查看vm_init部分,发现只知道cpu结构的大小以及初始值和24-32字节的结构,前24字节的结构未知,暂时还无法构建cpu的结构,需要更多的信息。分析下面两图的函数可以得知,opcode总共有8个,byt......
  • ACK One x OpenKruiseGame 全球游戏服多地域一致性交付最佳实践
    作者:刘秋阳、蔡靖前言在当今全球一体化的经济环境下,数字娱乐产业正日益成为文化和商业交流的有力代表。在此背景下大量游戏厂商尝试游戏出海并取得了令人瞩目的成绩,许多游戏以全球同服架构吸引着世界各地广泛的玩家群体。游戏全球化部署不仅扩大了单个产品的市场规模,而且提高了......
  • CF1956F Nene and the Passing Game 题解
    题目链接点击打开链接题目解法首先答案为连边之后连通块的个数把限制中的\(i,j\)分开,则\(i,j\)能传球当且仅当\(i+l_i\lej-l_j\)且\(j-r_j\lei+r_i\)这是一个二维偏序的形式先考虑怎么暴力做,考虑将\((i+l_i,0),\;(i-l_i,1)\)排序,然后按顺序加入如果碰到操作\(......
  • permutations and combinations in js All In One
    permutationsandcombinationsinjsAllInOnejs中的排列组合概念排列组合demos/*permutations&combinations排列&组合https://leetcode.com/problems/3sum/给定一个数字数组,找出有三个元素为一组构成的所有不重复的子数字数组!*///constarr=[1,2,......
  • Games 101: 旋转矩阵
    旋转矩阵本文主要介绍了旋转矩阵的推导,分为两种方式:旋转坐标旋转坐标轴以下坐标系都是右手坐标系旋转坐标已知坐标点\(A(x_a,y_a)\),旋转\(\theta\)角后变为坐标点\(B(x_b,y_b)\),求解旋转矩阵.\[{\large\begin{align*}\begin{split}x_a&=r_a\cdotcos(\alpha)=......
  • 库函数next_permutation()
    洛谷上有一道题叫做全排列问题,是一道搜索题,正常情况大家会用深搜dfs的方法解这道题,代码如下:#include<bits/stdc++.h>intn,a[10],pp=1;boolb[10];usingnamespacestd;intprint(){for(inti=1;i<=n;i++){ printf("%5d",a[i]); }printf("\n");}intsea......
  • E. Klever Permutation
    链接:https://codeforces.com/problemset/problem/1927/E思路:观察,可知每隔k个数据就是+1/-1,且间隔而分,思路如下:然后按顺序打表就行代码:#include<iostream>#include<vector>#include<algorithm>#include<math.h>#include<sstream>#include<string>#includ......
  • My Rhythm Game Journey
    我不是一个很老牌或者很强的音游人,入坑最早也就2022.2,但是我还是想在这里,记录一下我的进步史。ADanceofFireandIce(ADOFAI)(2022.2)最早是在B站上看到一些相关视频,然后就花了20来块买了下来(对于我而言当时还是很少paytoplay的),随便玩了玩,现在游戏时长刚刚200h。......
  • Games101:绕任意轴旋转
    Overview对于任意坐标\(S_1=(S_x,S_y,S_z)^T\),绕任意轴线\(\vec{n}=(n_x,n_y,n_z)^T\)旋转\(\alpha\)度,推导变换矩阵\(R(\vec{n},\alpha)\),使得变换后的坐标\(S_2=R(\vec{n},\alpha)\cdotS_1\)本文使用向量运算,推导该变换矩阵。注意:轴线经过坐标系原点基本公式以列向量表......