zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 13 A、B、C、D

    A. Johny Likes Numbers
    time limit per test
    0.5 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Johny likes numbers n and k very much. Now Johny wants to find the smallest integer x greater than n, so it is divisible by the number k.

    Input

    The only line contains two integers n and k (1 ≤ n, k ≤ 109).

    Output

    Print the smallest integer x > n, so it is divisible by the number k.

    Examples
    input
    5 3
    output
    6
    input
    25 13
    output
    26
    input
    26 13
    output
    39
    题意:找到一个大于n并且被k整除的最小的数;
    思路:除+1;
    #include<bits/stdc++.h>
    using namespace std;
    #define ll __int64
    #define mod 1000000007
    #define pi (4*atan(1.0))
    const int N=1e3+10,M=1e6+10,inf=1e9+10;
    int main()
    {
        int x,y,z,i,t;
        scanf("%d%d",&x,&y);
        printf("%I64d
    ",(ll)(x/y+1)*y);
        return 0;
    }
    代码
    B. The Same Calendar
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    The girl Taylor has a beautiful calendar for the year y. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday.

    The calendar is so beautiful that she wants to know what is the next year after y when the calendar will be exactly the same. Help Taylor to find that year.

    Note that leap years has 366 days. The year is leap if it is divisible by 400 or it is divisible by 4, but not by 100(https://en.wikipedia.org/wiki/Leap_year).

    Input

    The only line contains integer y (1000 ≤ y < 100'000) — the year of the calendar.

    Output

    Print the only integer y' — the next year after y when the calendar will be the same. Note that you should find the first year after y with the same calendar.

    Examples
    input
    2016
    output
    2044
    input
    2000
    output
    2028
    input
    50501
    output
    50507
    Note

    Today is Monday, the 13th of June, 2016.

     题意:找到这年之后日历相同的年份;

    思路:天数整除7并且是同是闰年或平年;

    #include<bits/stdc++.h>
    using namespace std;
    #define ll __int64
    #define mod 1000000007
    #define pi (4*atan(1.0))
    const int N=1e3+10,M=1e6+10,inf=1e9+10;
    int check(int x)
    {
        if((x%4==0&&x%100!=0)||x%400==0)
        return 366;
        return 365;
    }
    int main()
    {
        int x,y,z,i,t;
        scanf("%d",&x);
        int ans=0;
        for(i=x;;i++)
        {
            ans+=check(i)%7;
            if(ans%7==0&&(check(x)==check(i+1)))
                break;
        }
        cout<<i+1<<endl;
        return 0;
    }
    代码
    C. Joty and Chocolate
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Little Joty has got a task to do. She has a line of n tiles indexed from 1 to n. She has to paint them in a strange pattern.

    An unpainted tile should be painted Red if it's index is divisible by a and an unpainted tile should be painted Blue if it's index is divisible by b. So the tile with the number divisible by a and b can be either painted Red or Blue.

    After her painting is done, she will get p chocolates for each tile that is painted Red and q chocolates for each tile that is painted Blue.

    Note that she can paint tiles in any order she wants.

    Given the required information, find the maximum number of chocolates Joty can get.

    Input

    The only line contains five integers nabp and q (1 ≤ n, a, b, p, q ≤ 109).

    Output

    Print the only integer s — the maximum number of chocolates Joty can get.

    Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.

    Examples
    input
    5 2 3 12 15
    output
    39
    input
    20 2 3 3 5
    output
    51

     题意:1-n中每个整除a的数可以得到p;1-n中每个整除b的数可以得到q;

        问最多可以得到多少;

    思路:简单的容斥;

    #include<bits/stdc++.h>
    using namespace std;
    #define ll __int64
    #define mod 1000000007
    #define pi (4*atan(1.0))
    const int N=1e3+10,M=1e6+10,inf=1e9+10;
    ll gcd(ll x,ll y)
    {
        return y==0?x:gcd(y,x%y);
    }
    int main()
    {
        int x,y,z,i,t;
        ll n,a,b,p,q;
        scanf("%I64d%I64d%I64d%I64d%I64d",&n,&a,&b,&p,&q);
        ll aa=n/a;
        ll bb=n/b;
        ll ans=aa*p+bb*q;
        ll lcm=a*b/gcd(a,b);
        ans-=n/lcm*min(p,q);
        printf("%I64d
    ",ans);
        return 0;
    }
    代码
    D. Iterated Linear Function
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Consider a linear function f(x) = Ax + B. Let's define g(0)(x) = x and g(n)(x) = f(g(n - 1)(x)) for n > 0. For the given integer values AB,n and x find the value of g(n)(x) modulo 109 + 7.

    Input

    The only line contains four integers ABn and x (1 ≤ A, B, x ≤ 109, 1 ≤ n ≤ 1018) — the parameters from the problem statement.

    Note that the given value n can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long longinteger type and in Java you can use long integer type.

    Output

    Print the only integer s — the value g(n)(x) modulo 109 + 7.

    Examples
    input
    3 4 1 1
    output
    7
    input
    3 4 2 1
    output
    25
    input
    3 4 3 1
    output
    79

     思路:赤裸裸的矩阵快速幂;

    #include<bits/stdc++.h>
    using namespace std;
    #define ll __int64
    #define mod 1000000007
    #define pi (4*atan(1.0))
    const int N=1e3+10,M=1e6+10,inf=1e9+10;
    struct is
    {
        ll a[10][10];
    };
    ll x,m,k,c;
    is juzhenmul(is a,is b,ll hang ,ll lie)
    {
        int i,t,j;
        is ans;
        memset(ans.a,0,sizeof(ans.a));
        for(i=1;i<=hang;i++)
        for(t=1;t<=lie;t++)
        for(j=1;j<=lie;j++)
        {
            ans.a[i][t]+=(a.a[i][j]*b.a[j][t]);
            ans.a[i][t]%=mod;
        }
        return ans;
    }
    is quickpow(is ans,is a,ll x)
    {
        while(x)
        {
            if(x&1)  ans=juzhenmul(ans,a,2,2);
            a=juzhenmul(a,a,2,2);
            x>>=1;
        }
        return ans;
    }
    int main()
    {
        int y,z,i,t;
        ll a,b,n,x;
        scanf("%I64d%I64d%I64d%I64d",&a,&b,&n,&x);
        is base;
        base.a[1][1]=a;
        base.a[1][2]=0;
        base.a[2][1]=b;
        base.a[2][2]=1;
        is ans;
        memset(ans.a,0,sizeof(ans.a));
        ans.a[1][1]=1;
        ans.a[2][2]=1;
        ans=quickpow(ans,base,n);
        printf("%I64d
    ",(x*ans.a[1][1]+ans.a[2][1])%mod);
        return 0;
    }
    代码
  • 相关阅读:
    NPM下载模块包说明
    Keycode对照表
    iframe的document操作
    JS中鼠标左右键以及中键的事件
    BOM函数之history对象
    31、开发一个简单错误记录功能小模块,能够记录出错的代码所在的文件名称和行号。 处理: 1.记录最多8条错误记录,对相同的错误记录(即文件名称和行号完全匹配)只记录一条,错误计数增加;(文件所在的目录不同,文件名和行号相同也要合并) 2.超过16个字符的文件名称,只记录文件的最后有效16个字符;(如果文件名不同,而只是文件名的后16个字符和行号相同,也不要合并) 3.输入的文件可能带路径,记录文
    30、最高分是多少 老师想知道从某某同学当中,分数最高的是多少,现在请你编程模拟老师的询问。当然,老师有时候需要更新某位同学的成绩.
    二叉树遍历的算法
    28、输入两棵二叉树A,B,判断B是不是A的子结构。(ps:我们约定空树不是任意一个树的子结构)
    27、输入两个单调递增的链表,输出两个链表合成后的链表,当然我们需要合成后的链表满足单调不减规则。
  • 原文地址:https://www.cnblogs.com/jhz033/p/5603851.html
Copyright © 2011-2022 走看看