zoukankan      html  css  js  c++  java
  • 18清明假期汇总

    • CF_div2ABC

    A - Flag

      判断输入矩阵是否满足 每行元素相同,相邻行之间元素不同

    #include <iostream>
    
    using namespace std;
    
    int main(){
        int n,m;
        char num[105][105];
        int ok;
        cin>>n>>m;
        for(int i=0;i<n;i++)
            for(int j=0;j<m;j++)
                cin>>num[i][j];
                
        ok=1;                              
        for(int j=0;j<m-1;j++){               
            if(num[0][j]!=num[0][j+1]) ok=0;
        }                                     
        for(int i=1;i<n;i++){
            if(ok==0) break;
            if(num[i][0]==num[i-1][0]){ok=0;break;}
            for(int j=1;j<m;j++){
                if(num[i][j]==num[i-1][j]||num[i][j]!=num[i][j-1]){
                    ok=0;
                    break;
                }
            }
        }                                       
        if(ok==1) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }                 
    Flag

    B - Burglar and Matches

      给定背包容量、大小相同的火柴盒数量及每个火柴盒中火柴数量,求在不拆开火柴盒的情况下最多能拿到的火柴数量

    #include <iostream>
    #include <algorithm>
    using namespace std;
    
    struct node{
        int a,b;
    }c[25];
    bool cmp(struct node x,struct node y){
        return x.b>y.b;
    }
    long long n;    
    int m;
    int main(){
        cin>>n>>m;
        for(int i=0;i<m;i++){
            cin>>c[i].a>>c[i].b;
        }    
        sort(c,c+m,cmp);
        
        long long num,ans;
        num=0;ans=0;
        for(int i=0;i<m;i++){      
            if(num+c[i].a<=n){
                ans=ans+c[i].b*c[i].a;
                num=num+c[i].a;
            }
            else{
                ans=ans+c[i].b*(n-num);
                break;
            }
        }
        cout<<ans<<endl;
        return 0;
    }
    Burglar and Matches

    C - Monitor

      调整长宽,s.t.长宽符合要求比例且面积最大

      注:输入数据中的要求比例不一定是互素的,要加一个初步处理

    #include <iostream>
    #include <cmath>
    
    using namespace std;
    
    int gcd(int u,int v){
        return v?gcd(v,u%v):u;
    } 
    int main(){
        long long a,b,x,y;
        cin>>a>>b>>x>>y;
        long long t,ax,by;
        t=gcd(x,y);
        x=x/t;
        y=y/t;
        
        ax=a/x;
        by=b/y;
        if(ax&&by){
            t=min(ax,by);
            cout<<t*x<<" "<<t*y<<endl;
        }
        else cout<<0<<" "<<0<<endl;
    }
    Monitor

    D - Triangle

      给定三角形三个角的坐标(均为int)判断该三角形是否是直角三角形(RIGHT),或者将一个点的位置移动一个单位长度后是否为直角三角形(ALMOST),两者都不满足(NEITHER)

    #include <iostream>
    #include <cmath>
    #include <algorithm>
    
    using namespace std;
    
    int dx[]={1,-1,0,0},dy[]={0,0,-1,1};
    int ok=0;
    struct node{
        int x,y;
    }point[5];
    
    int triangle(node a1,node a2,node a3){
        int d[3];         
        node a[3];          
        a[0]=a1;a[1]=a2;a[2]=a3;
        int j=1;
        for(int i=0;i<3;i++){ 
            j=(j+1)%3;        
            d[i]=(a[i].x-a[j].x)*(a[i].x-a[j].x)+(a[i].y-a[j].y)*(a[i].y-a[j].y);                
        }    
        sort(d,d+3);          
        if(d[0]!=0&&d[0]+d[1]==d[2]){    
                return 1;
        }
        return 0;
    }
    
    int main(){
        cin>>point[0].x>>point[0].y
            >>point[1].x>>point[1].y
            >>point[2].x>>point[2].y;
        if(triangle(point[0],point[1],point[2])){
            cout<<"RIGHT"<<endl;
        }
        else{   
            int k,l;
            k=1;l=2;
            for(int i=0;i<3;i++){
                for(int j=0;j<4;j++){
                    node t;
                    t.x=point[i].x+dx[j];
                    t.y=point[i].y+dy[j];
                          
                    if(triangle(t,point[k],point[l])){
                        ok=1;
                        break;
                    }      
                }  
                k=(k+1)%3;           
                l=(l+1)%3;  
                if(ok==1) break;
            }
            if(ok==1) cout<<"ALMOST"<<endl;
            else cout<<"NEITHER"<<endl; 
        }
        return 0;
    } 
    Triangle

    E - Platforms

      In one one-dimensional world there are n platforms. Platform with index k (platforms are numbered from 1) is a segment with coordinates [(k - 1)m, (k - 1)m + l], and l < m. Grasshopper Bob starts to jump along the platforms from point 0, with each jump he moves exactly d units right. Find out the coordinate of the point, where Bob will fall down. The grasshopper falls down, if he finds himself not on the platform, but if he finds himself on the edge of the platform, he doesn't fall down.

      输入n,d,m,l,输出掉落位置

    #include <iostream>
    
    using namespace std;
    
    long long n,d,m,l;
     
    int main(){
        cin>>n>>d>>m>>l;
        for(long long i=0;i<n;i++){
            long long le=i*m+l;
            long long ri=(i+1)*m;
            long long t;      
            t=le-le%d+d;     
            if(t<ri){        
                cout<<t<<endl;
                break;
            }
            else if(i==n-1){   
                cout<<ri-(ri-1)%d+d-1<<endl;
            }
        }
        return 0;
    }
    Platforms
    • 清明节小礼物

    A - New Year Transportation

      n个单元格线性排列,单元格间不能直接通行,第 i 个单元格有一个单向传送门可传送至 i+ai ,问从第一个单元格是否能到达第 t 个单元格

    #include<iostream>
    
    using namespace std;
    
    int n,t,a[30005];
    int ok;
    
    int main(){
        cin>>n>>t;
        for(int i=1;i<n;i++){
            cin>>a[i];
        }
        
        ok=0;
        for(int i=1;i<=n;){
            if(i>t) break;
            if(i==t){
                ok=1;
                break;
            }
            i=i+a[i];
        }
        if(ok) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
        return 0;
    }
    New Year Transportation

    B - Strongly Connected City

      n条水平公路和m条垂直公路,每条公路均是单向的,问是某公路上的每个点是否是互通的

      注:只要外圈点构成环路,公路上每个点均能到达外圈的点并通过外圈环路到达任意点,即每个点是互通的

    #include<iostream>
    #include<cstring>
    
    using namespace std;
    
    int n,m;
    char ch[2][25];
    
    int main(){
        cin>>n>>m;
        for(int i=0;i<2;i++){
            cin>>ch[i];
        }
        int ok=0;
        if(ch[0][0]=='>'){
            if(ch[0][n-1]=='<'&&ch[1][0]=='^'&&ch[1][m-1]=='v'){
                ok=1;
            }
        }
        if(ch[1][0]=='v'){
            if(ch[1][m-1]=='^'&&ch[0][0]=='<'&&ch[0][n-1]=='>')
                ok=1;
        }
        
        if(ok) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    Strongly Connected City
  • 相关阅读:
    1130 Host XXX is not allowed to connect to this MySQL server。
    解决IntelliJ IDEA控制台输出中文乱码问题
    安装VS 201 SP1的时候,停在了“正在安装VS10Sp1KB983509”处
    ubuntu下获得root权限并修改hosts+ubuntu设置windows效果的字体--成功
    K8S官方网站 标题索引(超链接)
    DolphinScheduler2.0执行流程MasterServer
    DolphinScheduler2.0.0源码分析过程(02)
    DolphinScheduler2.0.0源码分析过程(01)
    【2021年终总结】关于我7个月不再更新文章而转行去做产品这件小事
    利用TChart做分离饼形图
  • 原文地址:https://www.cnblogs.com/anonym/p/8723485.html
Copyright © 2011-2022 走看看