codeforces 753-div3 D(现在只会做水题了呜呜呜)
2021/11/3 23:11:00
本文主要是介绍codeforces 753-div3 D(现在只会做水题了呜呜呜),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
题目
题意: 给定n个数,每个数具有B或者R属性之一。B表示该数可以执行任意次-1,R表示该数可以执行任意次+1。判断这n个数能否凑出一个permutation。
思路: 我直接线段树维护,发现没过样例,确实越来越菜了。
冷静分析,可以把b和r属性的数分别维护,进行排序。
之后按照数值now从小到大,如果b中的数值 < now,而他只能下降,根据鸽巢原理,不能凑出。
如果r中的数值 > now,而他只能上升,根据鸽巢原理,也不能凑出。
看代码就会了。
代码:
// Problem: D. Blue-Red Permutation // Contest: Codeforces - Codeforces Round #753 (Div. 3) // URL: https://codeforces.com/contest/1607/problem/D // Memory Limit: 256 MB // Time Limit: 1000 ms // // Powered by CP Editor (https://cpeditor.org) #include<iostream> #include<cstdio> #include<algorithm> #include<complex> #include<cstring> #include<cmath> #include<vector> #include<map> #include<unordered_map> #include<list> #include<set> #include<queue> #include<stack> #define OldTomato ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr) #define fir(i,a,b) for(int i=a;i<=b;++i) #define mem(a,x) memset(a,x,sizeof(a)) #define p_ priority_queue // round() 四舍五入 ceil() 向上取整 floor() 向下取整 // lower_bound(a.begin(),a.end(),tmp,greater<ll>()) 第一个小于等于的 // #define int long long //QAQ using namespace std; typedef complex<double> CP; typedef pair<int,int> PII; typedef long long ll; // typedef __int128 it; const double pi = acos(-1.0); const int INF = 0x3f3f3f3f; const ll inf = 1e18; const int N = 2e5+10; const int M = 1e6+10; const int mod = 1e9+7; const double eps = 1e-6; inline int lowbit(int x){ return x&(-x);} template<typename T>void write(T x) { if(x<0) { putchar('-'); x=-x; } if(x>9) { write(x/10); } putchar(x%10+'0'); } template<typename T> void read(T &x) { x = 0;char ch = getchar();ll f = 1; while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();} while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f; } int n,m,k,T; int a[N]; void solve() { // read(n); cin>>n; vector<int> a(n); vector<int> b; vector<int> r; for(int i=0;i<n;++i) { cin>>a[i]; } for(int i=0;i<n;++i) { char ch; cin>>ch; if(ch == 'B') b.push_back(a[i]); else r.push_back(a[i]); } bool flag = true; sort(b.begin(),b.end()); //只能下降,取他们为小的数 sort(r.begin(),r.end()); //只能上升 int now = 1; for(int i=0;i<b.size();++i) { if(b[i] < now) { flag = false; } else now++; } for(int i=0;i<r.size();++i) { if(r[i] > now) { flag = false; } else now ++ ; } if(now == n+1) puts("YES"); else puts("NO"); } signed main(void) { // T = 1; OldTomato; cin>>T; // read(T); while(T--) { solve(); } return 0; }
这篇关于codeforces 753-div3 D(现在只会做水题了呜呜呜)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-07-07Dify + TiDB Vector,快速构建你的AI Agent
- 2024-07-06有没有什么开源的py项目可以对图像进行分类-icode9专业技术文章分享
- 2024-07-05feign默认connecttimeout和readtimeout是多少-icode9专业技术文章分享
- 2024-07-05idea控制台,日志太多,导致部分想看得日志被刷走 搜不到-icode9专业技术文章分享
- 2024-07-05The server selected protocol version Tls10 is not accepted by client preferences [TLs12]-icode9专业技术文章分享
- 2024-07-05怎么清理项目缓存-icode9专业技术文章分享
- 2024-07-04安装 Eyoucms详细图文教程-icode9专业技术文章分享
- 2024-07-04ueditor 复制文章时,图片的链接是一个下载图片地址,该如何处理?-icode9专业技术文章分享
- 2024-07-04怎样判断host有没有对wordpress有缓存呢-icode9专业技术文章分享
- 2024-07-04具有编译功能的系统make后,无法ssh连接-icode9专业技术文章分享