hdu 6140
来源:互联网 发布:客户管理系统源码 编辑:程序博客网 时间:2024/06/01 09:27
题目链接:点击打开链接
题解思路:没看到题目到底干嘛。以为是任意一个位置,没想到是固定从第一个位置开始,那么一开始的区间就是[-1,1],那么如果接下来a[i]是正的且满足r>=a[i]则r+=a[i],a[i]是负的且满足-l>=a[i],则 l-=a[i],如果可正可否也是这样的道理。
代码:
#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <queue>#include <set>#include <map>#include <string>#include <math.h>using namespace std;const int mx = 1e3+10,mod = 1e9+7,S = 1e6;typedef long long ll;int n,m,a[mx];char c[mx];int main(){ int t; scanf("%d",&t); while(t--){ scanf("%d%d",&n,&m); int l = -1,r = 1; for(int i=1;i<=n;i++) scanf("%d",a+i); for(int i=1;i<=n;i++) cin>>c[i]; for(int i=2;i<=n;i++){ if(c[i]=='N'){ if(a[i]<=min(-l,r)) l = l-a[i], r = r+a[i]; else if(a[i]<=r) r += a[i]; else l -= a[i]; }else if(c[i]=='L'){ if(a[i]<=r) r += a[i]; }else{ if(a[i]<=-l) l -= a[i]; } } if(l<=m&&r>=m) puts("yes"); else puts("no"); } return 0;}
阅读全文
0 0
- hdu 6140
- hdu 6140 bitset+背包
- HDU 6140 Hybrid Crystals
- hdu 6140 Hybrid Crystals
- hdu-6140Hybrid Crystals
- HDU 6140 Hybrid Crystals
- HDU-6140 Killer Names
- HDU 6140 Hybrid Crystals
- hdu 6140 阅读理解
- HDU 6140 Hybrid Crystals
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- Android NDK: From Elementary to Expert Episode 23
- 记念一下
- 2017.8.17IO流 的案列
- 【后台】菜单管理界面菜单项增加自定义字段
- Struts2 方法动态调用,验证表签,xml配置Action
- hdu 6140
- 51 nod 1435 位数阶乘
- 剑指Offer_面试题33_把数组排成最小的数
- Android Binder机制浅析(一)
- 8.17--练习赛B题--River Hopscotch(二分)
- ARM学习笔记三
- IO流
- Python3爬虫代理服务器与cookie的使用
- 几种web服务器端推送技术的简单介绍