zoukankan      html  css  js  c++  java
  • 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 ",S);
        }
        return 0;
    }


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

  • 相关阅读:
    [更新设计]跨平台物联网通讯框架ServerSuperIO 2.0 ,功能、BUG、细节说明,以及升级思考过程!
    有幸参加“集团2016年工业事业部发展规划会议”,向网友汇报!!!
    Centos7之ssh连接keepalive
    AES加密算法
    MySQL之only_full_group_by
    AES加解密文件流
    Mongo基本配置
    前端js处理接口返回的压缩包(亲测可用)
    Ubuntu20.4静态ip和dhcp配置
    Java数组类型协变性、泛型类型的不变性
  • 原文地址:https://www.cnblogs.com/suncoolcat/p/3358207.html
Copyright © 2011-2022 走看看