杭电计算机学院大学生程序设计竞赛(2017新生赛)

106 篇文章 0 订阅

考研


#include <iostream>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;

int main()
{
    int T;
    for(scanf("%d",&T);T--;){
        int a,b,c,d;
        scanf("%d %d %d %d",&a,&b,&c,&d);
        if(a<85||d<85||b<55||c<55||a+b+c+d<305){
            printf("C\n");
        }else{
            if(a+b+c+d>=370){
                printf("A\n");
            }else{
                printf("B\n");
            }
        }
    }
    return 0;
}


身份证验证


#include <iostream>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;
char s[55];
int num[18]= {0,7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
int to[11]= {1,0,'X'-'0',9,8,7,6,5,4,3,2};
void check()
{
    int sum=0;
    for(int i=1; i<=17; i++)
    {
        sum+=num[i]*(s[i]-'0');
    }
    int a=s[18]-'0';
    sum=sum%11;
    if(to[sum]==s[18]-'0')
    {
        printf("Accepted\n");
    }
    else
    {
        printf("Sorry\n");
    }


}
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        int year,month,day;
        scanf("%d-%d-%d",&year,&month,&day);
        for(int i=1; i<=n; i++)
        {
            scanf("%s",s+1);
            int y,m,d;
            y=(s[7]-'0')*1000+(s[8]-'0')*100+(s[9]-'0')*10+s[10]-'0';
            m=(s[11]-'0')*10+s[12]-'0';
            d=(s[13]-'0')*10+s[14]-'0';
            int fy=y+18;
            if(year>fy)
            {
                check();
            }
            else if(fy==year)
            {
                if(month>m)
                {
                    check();
                }
                else if(month==m)
                {
                    if(day>=d)
                    {
                        check();
                    }
                    else
                    {
                        printf("Sorry\n");
                    }
                }
                else
                {
                    printf("Sorry\n");
                }
            }
            else
            {
                printf("Sorry\n");
            }
        }

   }
    return 0;
}



下起楼来我最快

只能走或者坐电梯,别想的太复杂。


#include <iostream>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;
#define LL long long
int main()
{
    LL n,m;
    while(~scanf("%lld %lld",&n,&m)){
        LL t1,t2,t3,t4;
        scanf("%lld %lld %lld %lld",&t1,&t2,&t3,&t4);
        LL ans1=0;
        ans1=fabs(n-m)*t1+t2+t2+t3+fabs(n-1)*t1;
        LL ans2=fabs(n-1)*t4;
        printf("%lld\n",min(ans1,ans2));
    }
    return 0;
}



正品的概率

简单的概率题


#include <iostream>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;
#define LL long long
const int maxn = 1e6+33;
LL gcd(LL a,LL b)
{
    if(b==0) return a;
    return gcd(b,a%b);
}
int main()
{
    LL n,m,k;
    while(~scanf("%lld %lld %lld",&m,&n,&k)){
        LL a=1;
        for(int i=1;i<=k;i++) a<<=1;
        LL fm=a*n+m;
        LL fz=m;
        LL now = gcd(fm,fz);
        while(now!=1){
            fm=fm/now;
            fz=fz/now;

            now=gcd(fm,fz);
        }
        printf("%lld/%lld\n",fz,fm);
    }
    return 0;
}


整数的Alvin值

找规律题。


#include <iostream>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;
#define LL long long
const int maxn = 333;
const LL mod = 1e9+7;
LL a[maxn];
LL num[maxn];
int main()
{
    num[1]=1;
    for(int i=2;i<=120;i++){
        num[i]=num[i-1]*2%mod;
    }
    LL n;
    while(~scanf("%lld",&n)){
        for(int i=1;i<=n+1;i++){
            scanf("%lld",&a[i]);
        }
        LL ans=0;
        for(int i=1;i<=n;i++)
            (ans+=mod+a[i]*num[n]%mod)%mod;
        (ans+=mod+a[n+1])%mod;
        printf("%lld\n",ans%mod);
    }

    return 0;
}


稿件整理

求逆序对数+判断一下。


#include <iostream>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <stack>
#include <stdio.h>
using namespace std;
#define LL long long
const int maxn = 100000+33;
int num[maxn+44];
struct node
{
    int a,b;
    int num;
}a[maxn];
int n;
int lowbit(int x)
{
    return x&(-x);
}
void add(int x)
{
    for(int i=x;i<=n;i+=lowbit(i))
        num[i]++;

}
int query(int x)
{
    int ans=0;
    for(int i=x;i>=1;i-=lowbit(i)) ans+=num[i];
    return ans;
}
int main()
{
    while(~scanf("%d",&n)){
        int cnt=0;
        memset(num,0,sizeof num);
        for(int i=1;i<=n/2;i++){
            ++cnt;
            scanf("%d %d",&a[cnt].a,&a[cnt].b);
            a[cnt].num=min(a[cnt].a,a[cnt].b);
        }
        LL ans=0;
        for(int i=1;i<=cnt;i++){
            add(a[i].num);
            ans+=1LL*query(n)-1LL*query(a[i].num);
            if(a[i].b<a[i].a) ans++;
        }
        printf("%lld\n",ans);
    }



    return 0;
}


找方块

乱搜+单调栈。


#include <iostream>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <stack>
#include <stdio.h>
using namespace std;
#define LL long long
const int maxn = 111+33;
int mp[maxn][maxn];
int ans,n;
struct node
{
    int len;
    int h;
    node(int l,int hh):
        len(l),h(hh){}
};
void dfs(int x,int y)
{
    if((n-x+1)*(n-y+1)<=ans) return;
    stack<node> q;
    int pre=-1;
    int hh;
    for(int i=x;i<=n;i++){
        if(pre!=-1){
            if(pre^mp[i][y]!=1) break;
        }
        hh=i;
        int now=mp[i][y];
        pre=now;
        int len=1;
        for(int j=y+1;j<=n;j++){
            if(now^mp[i][j]==1){
                now=mp[i][j];
                len++;
            }else{
                break;
            }
        }
        node b(len,i);
        while(!q.empty()&&q.top().len>len){
            node a=q.top();
            q.pop();
            b.h=a.h;
            ans=max(ans,(i-a.h)*a.len);
        }
        q.push(b);

    }
    while(!q.empty()){
            node a=q.top();
            q.pop();
            ans=max(ans,(hh-a.h+1)*a.len);
        }

}
int main()
{
    int T;
    scanf("%d",&T);
    while(T--){
        scanf("%d",&n);
        ans=1;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                scanf("%d",&mp[i][j]);
            }
        }
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                dfs(i,j);
            }
        }
        printf("%d\n",ans);

    }


    return 0;
}


友好整数


状压


#include <iostream>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <stack>
#include <stdio.h>
using namespace std;
#define LL long long
const int maxn = 111+33;
int num[2000];
char s[123];
int main()
{
    int n;
    while(~scanf("%d",&n)){
       memset(num,0,sizeof num);
        for(int i=1;i<=n;i++){
            int now=0;
            scanf("%s",s);
            int l=strlen(s);
            for(int i=0;i<l;i++){
                now=now|(1<<(s[i]-'0'));
            }
            num[now]++;
        }
        LL ans=0;
        for(int i=1;i<=1023;i++){
            for(int j=i;j<=1023;j++){
                int pre=ans;
                if(num[i]==0||num[j]==0) continue;
                if(i==j){
                    int m=num[i];
                    ans+=1LL*(m)*(m-1)/2;
                }
                else if((i&j)>0){
                    int m=num[i]+num[j];
                    ans+=1LL*num[i]*num[j];
                }

            }
        }
        printf("%lld\n",ans);
    }

    return 0;
}


最大收益

排序。


#include <iostream>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;
#define LL long long
const int maxn = 100000+44;
LL a[maxn];
LL b[maxn];
bool cmd(LL aa,LL bb)
{
    return aa>bb;
}
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1; i<=n; i++) scanf("%lld",&a[i]);
    for(int i=1; i<=m; i++) scanf("%lld",&b[i]);
    sort(a+1,a+1+n,cmd);
    sort(b+1,b+1+m,cmd);
    int num=min(n,m);
    LL ans=0;
    for(int i=1; i<=num; i++)
    {
        ans+=(1LL*a[i]*1LL*b[i]);
    }
    printf("%d %lld\n",num,ans);

    return 0;
}



说实话大二去参加别人的新生赛,心情是很复杂的。

但是竟然ak了也是没想到

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值