zoukankan      html  css  js  c++  java
  • hdu 6140

    题意:给出n,k,n个数,有对应的N,L,D,初始值为0,问是否可以选择一些数,使其等于k,N为该数可加可减,L为加,D为减,第一个值是确定的

    思路:我们最开始得到-1,0,1,即[-1,1]这区间任意数可达到,对于[a,b]这区间,如果加上一个正数,那么[a,b+正数]这区间任意一个数也可以得到,负数同理

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 typedef long long ll;
     4 
     5 struct node{
     6     int x;
     7     char s[2];
     8 }a[1003];
     9 
    10 int main(){
    11     int t;
    12     cin>>t;
    13     while(t--){
    14         int n,k;
    15         scanf("%d%d",&n,&k);
    16         for(int i=1;i<=n;i++) scanf("%d",&a[i].x);
    17         for(int i=1;i<=n;i++) scanf("%s",a[i].s);
    18         int l=0,r=0;
    19         for(int i=1;i<=n;i++){
    20             char c=a[i].s[0];
    21             if(c=='N'){
    22                 l-=a[i].x;
    23                 r+=a[i].x;
    24             }
    25             else if(c=='L') {
    26                 r+=a[i].x;
    27             }
    28             else l-=a[i].x;
    29         }
    30         if(k<=r&&k>=l) cout<<"yes"<<endl;
    31         else cout<<"no"<<endl;
    32     }
    33 }
  • 相关阅读:
    文件异步上传-ajaxFileUpload
    C# 结构体
    c# nullable类型有什么用
    跨平台理论杂记
    C#类型转换
    C# is as
    C# 类
    CLR的执行模型
    C# 与 LUA 的经验对比
    C#中的Decimal类型
  • 原文地址:https://www.cnblogs.com/hhxj/p/7388918.html
Copyright © 2011-2022 走看看