HUNNU--湖师大--11407--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.


   有时候咧,题目都是不难滴,就是看你运气好不好,运气好的一想就到点子上,运气不好的咯,妹的纠结的半死不活都还是只能干瞪眼

  这个题吧题意大概就是从距离你由近到远输入风的强度,然后再输入风的方向,A表示背向你而去,T表示面向你而来,然后你计算最后吹向你的风的强度,风的强度可以叠加跟削减,这是重点哦!!

#include <iostream>
#include <cstdio>
using namespace std;
int main (void)
{
    int t,n,m,i,j,k,l,a[1111];
    char c;
    __int64 S,A;  //用S标记当前我收到的风的强度,A标记离我而去的强度,因为后面的吹向我的风要抵消了这个强度才能到我这里,没抵消的话不关我屁事
    cin>>t;
    while(t--&&cin>>n)
    {
        for(i=0;i<n;i++)cin>>a[i];  //把强度记录
        for(i=0,S=A=0;i<n;i++)
        {
            cin>>c;  //输入方向
            if(c=='T')  //面向我
            {
                if(A>0)  //如果还有没抵消的离我而去的风
                if(A>=a[i])A-=a[i];  //如果这个吹来的风吹不赢那个离我而去的风--!那么就削减一点点得了
                else S+=a[i]-A,A=0;  //不然就是吹来的风赢了,剩下的强度加上来,同时那个离我而去的算是抵消了,就要置零
                else S+=a[i];  //如果没有离我而去的风就直接让他吹我一脸得了
            }
            else A+=a[i];  //背向我而去的风就把强度加起来
        }
        printf("%I64d\n",S);
    }
    return 0;
}


  经典的是背向我而去的风不会影响到“已经”吹到我身上的风,所以只要记录下来给更远地方吹向我的风消遣

 

你可能感兴趣的:(it)