zoukankan      html  css  js  c++  java
  • 哈尔滨工程大学ACM预热赛 补题

    链接:https://ac.nowcoder.com/acm/contest/554/A
    来源:牛客网

    小虎刚刚上了幼儿园,老师让他做一个家庭作业:首先画3个格子,第二行有2个格子,第三行有1个格子。
    每行的格子从左到右可以放棋子,但要求除第一行外,每行放的棋子数不能超过上一行的棋子。玩了一会儿
    ,小虎问大哥大虎:这个作业有很多种摆放法,我想都找到,但我不知道有多少中方案,你能帮助我么?
    大虎是学校信息学集训队的,立刻想到用计算机来解决这个问题,并很快有了解答:13。第二天他把问题拿到了学校,
    并说如果第一行有N个格子,第二行有N-1个格子,…,第N行有1个格子,怎么办?现在请你一块来帮助他解决这个难题。
    数据范围
    30%数据:1≤N≤12
    50%数据:1≤N≤30
    100%数据:1≤N≤100

    输入描述:

    仅一行,一个正整数N。

    输出描述:

    一行,方案总数。
    示例1

    输入

    复制
    2

    输出

    复制
    4

    说明

    样例1说明N=2时,有如下4中摆放棋子法(*表示棋子,_表示空格):
    方案法 1 2 3 4
    摆放法 *_ ** *_ **
    摆放法 _ _ * *
    示例2

    输入

    复制
    3

    输出

    复制
    13
    很显然的题目,写出转移方程f[i][1]=i,f[i][j]=f[i][j-1]+f[i-1][j];
    但long long 也只能写到n=30;
    要用大数加法
    #include<iostream>
    #include<algorithm>
    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<string>
    #include<cmath>
    #include<queue>
    #include<set>
    #include<stack>
    #include<map>
    #include<new>
    #include<ctime>
    #include<vector>
    #define MT(a,b) memset(a,b,sizeof(a));
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    const double pai=acos(-1.0);
    const double E=2.718281828459;
    const int INF=0x3f3f3f3f;
     
    string dp[101][101];
    string add(string a,string b)
    {
        int lena = a.size(),lenb = b.size();
        int cnt = 0;
        int len = max(lena,lenb);
        string now = "";
        for(int i=0; i<len; i++)
        {
            if(i<lena && i<lenb)
            {
                cnt += a[i] -'0' + b[i] - '0';
                now += cnt%10 + '0';
                cnt = cnt/10;
            }
            else if(i<lena)
            {
                cnt += a[i] - '0';
                now += cnt%10 + '0';
                cnt = cnt/10;
            }
            else if(i<lenb)
            {
                cnt += b[i] - '0';
                now += cnt%10 + '0';
                cnt = cnt/10;
            }
        }
        if(cnt)
            now += cnt + '0';
        return now;
    }
     
    int main()
    {
        int n;
        scanf("%d",&n);
        dp[1][0]="0";
        for(int i=1;i<=n;i++)
            dp[1][i]="1";
        for(int i=2;i<=n;i++)
        {
            for(int j=0;j<=n-i+1;j++)///这一行
            {
                dp[i][j]="0";
                for(int k=j;k<=n-i+2;k++)
                    dp[i][j]=add(dp[i][j],dp[i-1][k]);
            }
        }
        string ans=add(dp[n][0],dp[n][1]);
        string a=string(ans.rbegin(),ans.rend());
        cout<<a<<endl;
    }

     大数当然用python啦

    #py_1
    a = []
    for i in range(121):
        a.append(0)
    a[0]=1
    a[1]=1
    for i in range(121):
        if i==0 or i==1:
            continue
        a[i] = 0
        for j in range(i):
            a[i] += a[j]*a[i-j]
    n = int(input())
    print(a[n+2]-1)

    链接:https://ac.nowcoder.com/acm/contest/554/B
    来源:牛客网

    题目描述

    坑坑马上就要毕业了,但是在毕业之前需要完成毕业设计才能顺利毕业,可是坑坑的毕设题目很难,
    是有关图像处理的,涉及到矩阵方面的知识,对数学要求很高。坑坑在研究毕设的时候遇到了一个难题
    ,需要通过今天的比赛发现好的解题方法,希望大家可以帮忙。需要解决的问题是这样的,有一个矩阵A,
    它是3*3的方阵,现在需要编程实现计算矩阵|A*|(矩阵A对应的伴随阵的行列式的值),矩阵中的每个元素值都在0~255之间。

    输入描述:

    输入数据为T组数据(1<=T<=10)。
    每组数据有三行,每行三个数字,表示矩阵A中的元素值(0<=元素值<=255)。

    输出描述:

    对于每组数据,输出一个数字,表示矩阵A对应的伴随阵的行列式的值。
    示例1

    输入

    复制
    2
    1 0 0
    0 1 0
    0 0 1
    0 0 1
    0 1 0
    1 0 0

    输出

    复制
    1
    1
    直接用神奇的公式(谁让我还没有学过现代
    #include<cstdio>
     
    int a[11];
     
    int main(){
        int t;
        scanf("%d",&t);
        while(t--){
            for(int i=1;i<=9;++i){
                scanf("%d",&a[i]);
            }
            long long ans=a[1]*a[5]*a[9]-a[3]*a[5]*a[7]+
    a[2]*a[6]*a[7]-a[2]*a[4]*a[9]+a[4]*a[8]*a[3]-a[6]*a[8]*a[1]; printf("%lld ",ans*ans); } return 0; }

    链接:https://ac.nowcoder.com/acm/contest/554/C
    来源:牛客网

    题目描述

    国王有一块神奇土地
    第一天可以产a吨粮食,第二天会变成前一天的a倍,以此类推。
    n天后大臣准备把这些粮食尽可能多的平均分给b个城池
    为了方便,每个城池分到的粮食都是整吨整吨哒!
    剩下的粮食国王准备贪污
    国王能贪到多少吨粮食呢?

    输入描述:

    输入的第一行为一个数字T(T<=100),表示数据输入的组数。
    之后每行3个数字,分别表示 a, n, b(1<=a,n<= 1000,000,000;1<=b<=1000 )。

    输出描述:

    对于每组数据输出对应结果
    示例1

    输入

    复制
    1
    2 2 3

    输出

    复制
    1
    直接用快速幂就可以了
    题目的实际目的就是求a^n%b;
    #include<iostream>
    using namespace std;
    int quick(int a,int b,int c){
        int ans=1;
        while(b){
            if(b&1) ans=(ans*a)%c;
            a=(a*a)%c;
            b>>=1;
        }
        return ans;
    }
    int main(){
        int t;
        int a,n,b;
        cin>>t;
        for(int i=1;i<=t;i++){
            cin>>a>>n>>b;
            a=a%b;
            cout<<quick(a,n,b)<<endl;
        }
        return 0;
    } 

    链接:https://ac.nowcoder.com/acm/contest/554/D
    来源:牛客网

    wkroach明天终于要去和那个女孩见面了,这天晚上在梦中他变成了一名骑士,然而wkroach毕竟是理工男,
    他变成的是棋盘上骑士,在梦醒之前他有N步移动的机会,wkroach想知道他总共可能有多少种走法呢。
    这是一个8*8的棋盘,wkroach有一个初始位置,每次移动不能超出棋盘并且必须遵循骑士行走的规则也
    就和中国象棋的“马”类似但是不存在“蹩马腿”,如果你二者的规则都不知道那就看下一题吧)

    输入描述:

    第一行输入一个正整数T代表测试样例数目
    每组样例有三个正整数N R C(0<n<1000000000,0<R<9,0<C<9)代表此样例步数N及wkroach的初始点(R,C)。

    输出描述:

    对于每组测试数据,输出一个整数,表示总走法数。
    示例1

    输入

    复制
    2
    2 1 1
    1000000000 1 1

    输出

    复制
    12
    71386775
    太难聊,不会,先抄一下大佬的代码
    #include<iostream>
    #include<cstring>
    using namespace std;
    typedef long long LL;
     
    const LL MOD=1e9+7;
    const int MAX_S=65;
    const int f[][2]={1,2, 1,-2, -1,2, -1,-2, 2,1, 2,-1, -2,1, -2,-1};
    struct Matrix{
        LL a[MAX_S][MAX_S];
        Matrix (){
            memset(a,0,sizeof(a));
        }
        Matrix operator*(const Matrix &A){
            Matrix B=Matrix();
            for(int k=0;k<MAX_S;++k)
                for(int i=0;i<MAX_S;++i)
                    for(int j=0;j<MAX_S;++j)
                        B.a[i][j]=(B.a[i][j]+a[i][k]*A.a[k][j])%MOD;
            return B;
        }
    };
    int n,T;
    Matrix e;
     
    void Fast_power(Matrix &res,int n);
    int main()
    {
        e=Matrix();
        int t=0,x,y;
        for(int i=0;i<8;++i)
            for(int j=0;j<8;++t,++j)
                for(int k=0;k<8;++k)
                {
                    x=i+f[k][0];    y=j+f[k][1];
                    if(x>=0&&x<8&&y>=0&&y<8)    e.a[t][x*8+y]=1;
                }
        cin>>T;
        while(T--){
            cin>>n>>x>>y;
            Matrix res=Matrix();
            t=(x-1)*8+y-1;
            for(int i=0;i<MAX_S;++i)
                res.a[t][i]=e.a[t][i];
            Fast_power(res,n-1);
            LL ans=0;
            for(int i=0;i<MAX_S;++i)
                for(int j=0;j<MAX_S;++j)
                    ans=(ans+res.a[i][j])%MOD;
            cout<<ans<<endl;
        }
         
        return 0;
    }
     
    void Fast_power(Matrix &res,int n)
    {
        Matrix A=e;
        while(n){
            if(n&1) res=res*A;
            A=A*A;
            n>>=1;
        }
    }

    链接:https://ac.nowcoder.com/acm/contest/554/E
    来源:牛客网

    Mother's Day is a celebration honoring the mother of the family, as well as motherhood, maternal bonds, and the influence of mothers in society, which is celebrated on various days in many parts of the world, but mostly, the date is on the second Sunday in May. 
        Like Mother's Day, there are also several celebrations have no fixed date, but are set in the form of "the Bth(st/nd) weekday C of the Ath(st/nd) month in a year", for example, as above, Mother's Day is on the second Sunday in May of a year, but also can be described as "the 2nd weekday 7 of the 5st month in a year"(A=5, B=2, C=7). 
        Now, to help remember these special days, HVT wants you to calculate all the exact date of such celebrations in the past and future hundreds of years, which means that you are given 4 numbers: A(1 ≤ A ≤ 12), B(B ≥ 1), C(1 ≤ C ≤ 7, 1=Monday,2=Tuesday,...,7=Sunday) and y(represents the year, 1850 ≤ y ≤ 2050), and you should write code to calculate the exact date of "the Bth(st/nd) weekday C of the Ath(st/nd) month in a year y".
        For your convenience, we will noice you that: January 1st, 1850 is a Tuesday.

    输入描述:

    The input contains multiple lines of test data, each line has 4 numbers: A B C and y.

    输出描述:

    For each input, you should output a exact date in the format of "yyyy/mm/dd"(When the number of digits is insufficient, 0 should be added to the front);
    if the Bth(st/nd) weekday C of the Ath(st/nd) month in a year y does not exist(for example, there will never be a 7th Monday in any months of any year), you should output "none" (without quotes).
    示例1

    输入

    复制
    4 2 7 2018
    4 1 7 2018
    2 5 4 2018
    2 4 3 2018

    输出

    复制
    2018/04/08
    2018/04/01
    none
    2018/02/28

    思路:

    根据基姆拉尔森计算公式直接求出要求的月的第一天然后模拟即可。

    #include <bits/stdc++.h>
    using namespace std;
    int a,b,c,y;
    int main()
    {
        while(scanf("%d%d%d%d",&a,&b,&c,&y)!=EOF)
        {
            int td,tm,ty;
            td=1,tm=a,ty=y;
            if(tm==1||tm==2) {
                    tm+=12;
                    ty-=1;
            }
            int w=(td+2*tm+3*(tm+1)/5+ty+ty/4-ty/100+ty/400)%7;
            int day[15]={0,31,28,31,30,31,30,31,31,30,31,30,31};
            if((y%4==0&&y%100)||(y%400==0)) day[2]++;
            int st=w;
            int d=1,num=0;
            while(st!=c-1)
            {
                st=(st+1)%7;
                d++;
            }
            while(num<b-1&&d<=day[a])
            {
                 num++;
                 d+=7;
            }
            if(num==b-1&&d<=day[a])
            {
                printf("%d/%02d/%02d
    ",y,a,d);
            }
            else
            {
                printf("none
    ");
            }
        }
        return 0;
    }

    链接:https://ac.nowcoder.com/acm/contest/554/H
    来源:牛客网

    题目描述

    杨主席这段时间由于要找实习,所以非常焦躁。因为公司的面试都非常的难,杨主席不知道从哪入手。于是他就找了他的学长坑坑询问情况,坑坑告诉他要注重算法的学习,于是就给杨主席出了一个题目看看他算法学的怎么样,这道题是这样的:有N个人排成一排,从1到N按顺序依次编号,现在要执行N次操作,第一次操作让所有的人都蹲下,之后第二次操作让编号是2和2的倍数的人全部站起来,然后第三次操作让编号是3和3的倍数的人全部做相反的动作(站着的人蹲下,蹲下的人站起来),以此类推...,最后第N此操作让编号为N的这个人也做相反的动作。请问N次操作后,从第A个人到第B个人之间(包括A和B这两个数字,且A<B)有多少人是站着的?

    输入描述:

    输入数据为T组数据(1<=T<=10)。
    每组数据输入包含三个数字N,A,B(1<=N<=1000000,1<=A<B<=N)。

    输出描述:

    对于每组数据,输出一个整数,表示从第A个人到第B个人之间有多少人站着。
    示例1

    输入

    复制
    1
    5 1 3

    输出

    复制
    2
    思路:神仙找规律
    i^2的人都是蹲着的
    #include<iostream>
    using namespace std;
    int main(){
        int t;
        int a,n,b;
        cin>>t;
        for(int i=1;i<=t;i++){
            cin>>n>>a>>b;
            int sum=b-a+1;
            int j=1;
            while(j*j<=b){
                if(j*j>=a)
                sum--;
                j++;
            }
            cout<<sum<<endl;
        }
        return 0;
    } 
    
    
  • 相关阅读:
    残缺的字符串
    [BZOJ3513: [MUTC2013]idiots]
    FFT感性瞎扯
    Quartz框架简介
    异常状态码总结
    【SSM】拦截器的原理、实现
    FastDFS实现文件上传下载实战
    分布式文件系统FastDFS设计原理(转)
    FastDFS简介
    【设计模式】观察者模式
  • 原文地址:https://www.cnblogs.com/yfr2zaz/p/10652377.html
Copyright © 2011-2022 走看看