zoukankan      html  css  js  c++  java
  • 牛客多校训练AFJ(签到)

    题目链接https://ac.nowcoder.com/acm/contest/881/A(单调栈)

    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<algorithm>
    #include<queue>
    #include<stack>
    #include<set>
    #include<vector>
    #include<map>
    #include<cmath>
    const int maxn=1e5+5;
    typedef long long ll;
    using namespace std;
    int L1[5*maxn],L2[5*maxn];
    int a[5*maxn],b[5*maxn];
    int main()
    {
       int n;
       while(~scanf("%d",&n))
       {
           for(int t=1;t<=n;t++)
           {
               scanf("%d",&a[t]);
        }
        for(int t=1;t<=n;t++)
        {
            scanf("%d",&b[t]);
        }
        stack<int>s1,s2; 
        for(int t=1;t<=n;t++)
        {
            if(s1.empty())
            {
                L1[t]=0;
                s1.push(t);
                continue;
            }
            else
            {
                while(!s1.empty()&&a[s1.top()]>a[t])
                {
                    s1.pop();
                }
               if(s1.empty())
               {
                L1[t]=0;
                s1.push(t);
                continue;
               }
               else
               {
                   L1[t]=s1.top();
                   s1.push(t);
                   continue;
               }    
            }
        }
        for(int t=1;t<=n;t++)
        {
            if(s2.empty())
            {
                L2[t]=0;
                s2.push(t);
                continue;
            }
            else
            {
                while(!s2.empty()&&b[s2.top()]>b[t])
                {
                    s2.pop();
                }
               if(s2.empty())
               {
                L2[t]=0;
                s2.push(t);
                continue;
               }
               else
               {
                   L2[t]=s2.top();
                   s2.push(t);
                   continue;
               }    
            }
        }
        int k=n+1;
        for(int t=1;t<=n;t++)
        {
            //cout<<L1[k]<<" "<<L2[k]<<endl;
            if(L1[t]!=L2[t]){
                k=t;
                break;
            } 
        }
        printf("%d
    ",k-1);
        
       }
       return 0;
    }

    题目链接:https://ac.nowcoder.com/acm/contest/881/F(思维)

    三角形面积的22倍

    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<algorithm>
    #include<queue>
    #include<stack>
    #include<set>
    #include<vector>
    #include<map>
    #include<cmath>
    const int maxn=1e5+5;
    typedef long long ll;
    using namespace std;
    int main()
    {  
    
       long double x0,y0,x1,y1,x2,y2;
       long double a,b,c,p,S;
       long double ans;
       while(cin>>x0>>y0>>x1>>y1>>x2>>y2)
       {
            a=sqrtl((x0-x1)*(x0-x1)+(y0-y1)*(y0-y1));
            b=sqrtl((x0-x2)*(x0-x2)+(y0-y2)*(y0-y2));
            c=sqrtl((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
            //cout<<a<<" "<<b<<" "<<c<<endl; 
            p=(a+b+c)/2;
            S=sqrtl(p*(p-a)*(p-b)*(p-c));
            S=S*22;
            ans=S;    
            printf("%.0Lf
    ",ans);
       }
    
       return 0;
    }

    海伦公式版没过 不知道原因

    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<algorithm>
    #include<queue>
    #include<stack>
    #include<set>
    #include<vector>
    #include<map>
    #include<cmath>
    const int maxn=1e5+5;
    typedef long long ll;
    using namespace std;
    int main()
    { 
     
       long double x0,y0,x1,y1,x2,y2;
       long double a,b,c,p,S;
       long double ans;
       while(cin>>x0>>y0>>x1>>y1>>x2>>y2)
       {
         a=sqrtl((x0-x1)*(x0-x1)+(y0-y1)*(y0-y1));
         b=sqrtl((x0-x2)*(x0-x2)+(y0-y2)*(y0-y2));
         c=sqrtl((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
         //cout<<a<<" "<<b<<" "<<c<<endl;
         p=(a+b+c)/2;
         S=sqrtl(p*(p-a)*(p-b)*(p-c));
         S=S*22;
         ans=S;
         printf("%.0Lf
    ",ans);
       }
     
       return 0;
    }

    题目链接:https://ac.nowcoder.com/acm/contest/881/J(大数)

    #include <stdio.h>
    #include <stdlib.h>
    #include <iostream> 
    #include <string> 
    #include <cstring> 
    #include <cstdio> 
    using namespace std; 
       
    const int maxn = 1000; 
       
    struct bign{ 
        int d[maxn], len; 
       
        void clean() { while(len > 1 && !d[len-1]) len--; } 
       
        bign()          { memset(d, 0, sizeof(d)); len = 1; } 
        bign(int num)   { *this = num; }  
        bign(char* num) { *this = num; } 
        bign operator = (const char* num){ 
            memset(d, 0, sizeof(d)); len = strlen(num); 
            for(int i = 0; i < len; i++) d[i] = num[len-1-i] - '0'; 
            clean(); 
            return *this; 
        } 
        bign operator = (int num){ 
            char s[20]; sprintf(s, "%d", num); 
            *this = s; 
            return *this; 
        } 
       
        bign operator + (const bign& b){ 
            bign c = *this; int i; 
            for (i = 0; i < b.len; i++){ 
                c.d[i] += b.d[i]; 
                if (c.d[i] > 9) c.d[i]%=10, c.d[i+1]++; 
            } 
            while (c.d[i] > 9) c.d[i++]%=10, c.d[i]++; 
            c.len = max(len, b.len); 
            if (c.d[i] && c.len <= i) c.len = i+1; 
            return c; 
        } 
        bign operator - (const bign& b){ 
            bign c = *this; int i; 
            for (i = 0; i < b.len; i++){ 
                c.d[i] -= b.d[i]; 
                if (c.d[i] < 0) c.d[i]+=10, c.d[i+1]--; 
            } 
            while (c.d[i] < 0) c.d[i++]+=10, c.d[i]--; 
            c.clean(); 
            return c; 
        } 
        bign operator * (const bign& b)const{ 
            int i, j; bign c; c.len = len + b.len;  
            for(j = 0; j < b.len; j++) for(i = 0; i < len; i++)  
                c.d[i+j] += d[i] * b.d[j]; 
            for(i = 0; i < c.len-1; i++) 
                c.d[i+1] += c.d[i]/10, c.d[i] %= 10; 
            c.clean(); 
            return c; 
        } 
        bign operator / (const bign& b){ 
            int i, j; 
            bign c = *this, a = 0; 
            for (i = len - 1; i >= 0; i--) 
            { 
                a = a*10 + d[i]; 
                for (j = 0; j < 10; j++) if (a < b*(j+1)) break; 
                c.d[i] = j; 
                a = a - b*j; 
            } 
            c.clean(); 
            return c; 
        } 
        bign operator % (const bign& b){ 
            int i, j; 
            bign a = 0; 
            for (i = len - 1; i >= 0; i--) 
            { 
                a = a*10 + d[i]; 
                for (j = 0; j < 10; j++) if (a < b*(j+1)) break; 
                a = a - b*j; 
            } 
            return a; 
        } 
        bign operator += (const bign& b){ 
            *this = *this + b; 
            return *this; 
        } 
       
        bool operator <(const bign& b) const{ 
            if(len != b.len) return len < b.len; 
            for(int i = len-1; i >= 0; i--) 
                if(d[i] != b.d[i]) return d[i] < b.d[i]; 
            return false; 
        } 
        bool operator >(const bign& b) const{return b < *this;} 
        bool operator<=(const bign& b) const{return !(b < *this);} 
        bool operator>=(const bign& b) const{return !(*this < b);} 
        bool operator!=(const bign& b) const{return b < *this || *this < b;} 
        bool operator==(const bign& b) const{return !(b < *this) && !(b > *this);} 
       
        string str() const{ 
            char s[maxn]={}; 
            for(int i = 0; i < len; i++) s[len-1-i] = d[i]+'0'; 
            return s; 
        } 
    }; 
       
    istream& operator >> (istream& in, bign& x) 
    { 
        string s; 
        in >> s; 
        x = s.c_str(); 
        return in; 
    } 
       
    ostream& operator << (ostream& out, const bign& x) 
    { 
        out << x.str(); 
        return out; 
    }
    int main()
    {
        bign x,y,a,b;
        while(cin>>x>>a>>y>>b)
        {
            if(x*b==y*a)
            {
                puts("=");
            }
            else if(x*b<y*a)
            {
                puts("<");
            }
            else
            {
                puts(">");
            }
        }
    }
  • 相关阅读:
    nginx搭建文件服务器配置文件
    VS code
    UNIX 网络编程学习
    局域网内的一些计算机可以ping通 有些ping不同
    Cfree clion windows c语言 socket 网络编程
    查找文件
    select * from 后有多个表的使用方法
    linux安装git方法
    Xshell中文乱码怎么处理?
    linux 逻辑卷管理 /dev/mapper/VolGroup-lv_root 100%调整分区大小
  • 原文地址:https://www.cnblogs.com/Staceyacm/p/11210802.html
Copyright © 2011-2022 走看看