zoukankan      html  css  js  c++  java
  • “科大讯飞杯”第18届上海大学程序设计联赛春季赛暨高校网络友谊赛

    A  组队比赛

    签到

    #include<bits/stdc++.h>
    using namespace std;
    const int inf=0x3f3f3f3f;
    const int N=1e5+15;
    typedef long long ll;
    int main(){
        int a,b,c,d;
        scanf("%d %d %d %d",&a,&b,&c,&d);
        int ans=1e7;
        // ic+d)
        ans=min(ans,(int)fabs(a+b-c-d));
        ans=min(ans,(int)fabs(a+c-b-d));
        ans=min(ans,(int)fabs(a+d-b-c));
        printf("%d
    ",ans);
    
    
    
        // system("pause");
        return 0;
    }
    View Code

    B 每日一报

    签到,但要注意等于情况

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef double db;
    const db eps=0.1;
    const int N=1e3+5;
    struct node{int a,b;db c;};
    bool cmp(node ta,node tb){
        if(ta.a!=tb.a)return ta.a>tb.a;
        else if(ta.c!=tb.c)return ta.c>tb.c;
        else return ta.b<tb.b;
    }
    vector<node>v;
    int main(){
        int n;
        scanf("%d",&n);
        for(int i=1;i<=n;i++){
        node tmp;
        scanf("%d %d %lf",&tmp.a,&tmp.b,&tmp.c);
        if(tmp.c>38.0)v.push_back(tmp);
        }
        sort(v.begin(),v.end(),cmp);
        int m=v.size();
        printf("%d
    ",m);
        for(int i=0;i<m;i++){
            printf("%d %d %.1lf
    ",v[i].a,v[i].b,v[i].c);
        }
    
        // system("pause");
        return 0;
    }
    View Code

    C 最长非公共子序列

    签到

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef double db;
    const db eps=0.1;
    const int N=1e3+5;
    int main(){
        string s1,s2;
        cin>>s1>>s2;
        int len1=s1.size(),len2=s2.size();
        if(s1==s2){
        puts("-1");
        
        }
        else if(len1!=len2){
            printf("%d
    ",max(len1,len2));
        }
        else if(len1==len2){
            printf("%d
    ",len2);
        }
    
        // system("pause");
        return 0;
    }
    View Code

    D  最大字符集

    吐血,居然没想到n=2时,0  11是满足条件的。

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int inf=0x3f3f3f3f;
    const int N=3e2+50;
    int main(){
      
        int n;
        scanf("%d",&n);
        if(n==1){puts("1");puts("1");return 0;}
        if(n==2){puts("2");puts("0");puts("11");return 0;}   
        printf("%d
    ",n-1);
        for(int i=2;i<=n;i++){
        printf("1");
        for(int j=1;j<=i-2;j++)printf("0");
        printf("1");
        printf("
    ");
        }
      
        // system("pause");
        return 0;
    }
    View Code

    E:美味的序列

    签到

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int inf=0x3f3f3f3f;
    const int N=1e5+15;
    ll a[N];
    int main(){
        int n;
        scanf("%d",&n);
        for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
        sort(a+1,a+1+n,greater<long long>() );
        ll ans=0;
        ll   c=0;
        for(int i=1;i<=n;i++){
            a[i]-=c;
            ans+=a[i];
            c++;
        }
        printf("%lld
    ",ans);
    
        // system("pause");
        return 0;
    }
    View Code

    F:日期小助手

    求一个日期是星期几就行了

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef double db;
    const db eps=0.1;
    const int N=1e3+5;
    string s[50];
    int CaculateWeekDay(int y,int m,int d) {//计算当前日期是星期几
        if (m==1||m==2) {
            m+=12;
            --y;
        }
        return (d+2*m+3*(m+1)/5+y+y/4-y/100+y/400+1)% 7;
    }
    void init(){
        for(int i=1;i<=31;i++)s[i]="th";
        s[1]=s[21]=s[31]="st";
        s[2]=s[22]="nd";
        s[3]=s[23]="rd";
        
    }
    int main(){
        init();
        int t;
        scanf("%d",&t);
        while(t--){
        int ty,tm,td;
        scanf("%d %d %d",&ty,&tm,&td);
        int date=CaculateWeekDay(ty,5,1);
        int day=1,flag=0;
        while(1){
            if(date==0)flag++;
            if(flag==2)break;
            day++;
            date++;date%=7;
        }
    
        if(tm*100+td<day+500){
            printf("Mother's Day: May %d%s, %d
    ",day,s[day].c_str(),ty);
            continue;    
        }
        day=1;flag=0;
        date=CaculateWeekDay(ty,6,1);
        while(1){
            if(date==0)flag++;
            if(flag==3)break;
            day++;
            date++;date%=7;
        }
        if(tm*100+td<day+600){
            printf("Father's Day: June %d%s, %d
    ",day,s[day].c_str(),ty);
            continue;    
        }
    
        day=1;flag=0;
        date=CaculateWeekDay(ty+1,5,1);
        while(1){
            if(date==0)flag++;
            if(flag==2)break;
            day++;
            date++;date%=7;
        }
        // if(ty*100+td<day+500){
            printf("Mother's Day: May %d%s, %d
    ",day,s[day].c_str(),ty+1);
            continue;    
        // }
       
    
        }        
        // system("pause");
        return 0;
    }
    View Code
  • 相关阅读:
    Java ,python面向对象的继承及其区别
    谈谈我理解的敏捷开发
    Centos7 升级python3,解决升级后不兼容问题
    Django + Uwsgi + Nginx 的生产环境部署
    理解Python协程:从yield/send到yield from再到async/await
    【转】Python 数据库连接池
    为何GET只发一次TCP连接,POST发两次TCP连接
    Python简单密码加密程序,加盐(salt)md5
    spring学习(三) ———— spring事务操作
    spring学习(二) ———— AOP之AspectJ框架的使用
  • 原文地址:https://www.cnblogs.com/littlerita/p/12727588.html
Copyright © 2011-2022 走看看