• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • YouClaw
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

Warm up 3 [F] It Is Cold

你为何这么叼!

[F] It Is Cold

 

Dr. Ziad Najem is known as the godfather of the ACPC. When the regional contest was held in Alexandria, Egypt, the weather was very cold. What surprised Dr. Ziad was that in the contest hall the fans were turned on! Dr. Ziad immediately needed to know, for each team, the speed in which the air reached that team.  
Each team has N fans placed on a straight line to its right. Each fan i has a speed Si and direction Ci. Directions are either towards the team "T" or away from the team "A".  
If two fans face the same direction, their speeds add up in the same direction. E.g.  Fan 1 Fan 2 Result Direction T T T Speed 2 4 2+4 = 6 
If two fans face each other, their speeds cancel out. E.g.  Fan 1 Fan 2 Result Direction A T T Speed 2 4 4-2 = 2


Input Specification
The first line of input contains an integer T, the number of teams. For each team, you will be given an integer N, the number of fans. Two lines follow; the first line contains N space separated integers Si, the speed of the air produced by fan i (0<= i < N). The second line contains N characters that describe the direction of the fans Ci (as described above). 
T <= 100 0 < N <= 1000 0 <= Si <= 1000000000 


Output Specification
There should be T lines, containing a single integer S each that represents the speed in which the air reaches the team. S is zero if no air reaches the team.

 

Sample Input
3

2

1 2

T T

2

3 5

A T

2

3 5

T A 


Sample Output
3

2

3 

 

 1 #include <cstdio>
 2 #include <vector>
 3 #include <cstring>
 4 #include <queue>
 5 #include <algorithm>
 6 using namespace std;
 7 #define maxn 10005
 8 #define mod 1000000007
 9 #define ll long long
10 int n,m;
11 ll dp[maxn];
12 ll b[maxn];
13 char a[maxn][10];
14 int main(){
15     int t;
16     scanf("%d",&t);
17     while(t--){
18         ll s=0;
19         scanf("%d",&n);
20         for(int i=0;i<n;i++)scanf("%I64d",&b[i]);
21         for(int i=0;i<n;i++)scanf("%s",&a[i]);
22         for(int i=n-1;i>=0;i--){
23             if(a[i][0]=='T')s+=b[i];
24             else s-=b[i];
25             if(s<0)s=0;
26         }
27         printf("%I64d\n",s);
28     }
29     return 0;
30 }
View Code 2013-10-07 22:23:13

 

posted @ 2013-10-07 22:21  HaibaraAi  阅读(116)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3