hdu6140 bitset
来源:互联网 发布:深圳旅游知乎 编辑:程序博客网 时间:2024/06/03 12:07
Problem H
给出数列
数据范围:
Solution
利用
#include<iostream>
#include<cstdio>
#include<bitset>
using namespace std;
const int MaxN=1005;
const int MaxM=1000005;
int T, n, k, a[MaxN];char b[MaxN];
bitset<MaxM> Right, Left;void solve(){ int rmax = 0, lmax = 0; for(int i=1;i<=n;i++) switch(b[i]) { case 'N': rmax+=a[i]; lmax+=a[i]; break; case 'D': lmax+=a[i]; break; case 'L': rmax+=a[i]; } if( (k>0 && rmax<k) || (k<0 && lmax<-k) ) puts("no"); else { for(int i=1;i<=n;i++) { switch(b[i]) { case 'N': Right |= (Right<<a[i]); Left |= (Left <<a[i]); break; case 'D': Left |= (Left <<a[i]); break; case 'L': Right |= (Right<<a[i]); } } if(k==0 || (k>0 && Right.test(k)) || (k<0 && Left.test(-k)) ) puts("yes"); else { bool flag = false; for(int i=k+1;i<=1E6;i++) { if(k>0) { if(Right.test(i) && Left.test(i-k)) { flag = true; break; } } else { if(Left.test(i) && Right.test(i+k)) { flag = true; break; } } } if(flag) puts("yes"); else puts("no"); } }}int main(){ scanf("%d",&T); while(T--) { cin>>n;cin>>k; Left.reset(); Right.reset(); Left.set(0); Right.set(0); for(int i=1;i<=n;i++) cin>>a[i]; for(int i=1;i<=n;i++) scanf(" %c", &b[i]); solve(); }}
阅读全文
0 0
- hdu6140 bitset
- hdu6140
- hdu6140-暴力
- hdu6140(思维)
- HDU6140-Hybrid Crystals
- Hybrid Crystals(hdu6140)
- bitset
- bitset
- BitSet
- bitset
- bitset
- BitSet
- bitset
- bitset
- bitset
- bitset
- bitset
- BitSet
- c++ 递归版本遍历二叉树
- CS231n Convolutional Neural Networks for Visual Recognition
- HighCharts(2)坐标轴5部分
- Javascript and DOM
- 分代垃圾收集器
- hdu6140 bitset
- js各种排序汇总
- ubuntu 12.04 安装编译L2.6.35_1.1.0_130130 基于 i.mx28
- sudo: javac:找不到命令
- js、jQuery获得父节点、子节点、兄弟节点的整理
- MFC中定义全局变量【待续】
- 双边滤波器原理及其matlab实现
- dedecms如何自定义分页样式
- 分组密码算法工作模式(block cipher operation mode)