zoukankan      html  css  js  c++  java
  • AIM Tech Round 3 (Div. 2) A , B , C

    A. Juicer
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Kolya is going to make fresh orange juice. He has n oranges of sizes a1, a2, ..., an. Kolya will put them in the juicer in the fixed order, starting with orange of size a1, then orange of size a2 and so on. To be put in the juicer the orange must have size not exceeding b, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.

    The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than d. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section?

    Input

    The first line of the input contains three integers n, b and d (1 ≤ n ≤ 100 000, 1 ≤ b ≤ d ≤ 1 000 000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value d, which determines the condition when the waste section should be emptied.

    The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1 000 000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer.

    Output

    Print one integer — the number of times Kolya will have to empty the waste section.

    Examples
    Input
    2 7 10
    5 6
    Output
    1
    Input
    1 5 10
    7
    Output
    0
    Input
    3 10 10
    5 7 7
    Output
    1
    Input
    1 1 1
    1
    Output
    0
    Note

    In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.

    In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all.

    思路:按题意模拟;

    #include<bits/stdc++.h>
    using namespace std;
    #define ll __int64
    #define mod 1000000007
    #define pi (4*atan(1.0))
    const int N=1e5+10,M=4e6+10,inf=1e9+10;
    int main()
    {
        int x,y,z,i,t,l,r;
        scanf("%d%d%d",&x,&l,&r);
        int ans=0,sum=0;
        for(i=1;i<=x;i++)
        {
            scanf("%d",&y);
            if(l<y)continue;
            sum+=y;
            if(sum>r)
            {
                sum=0;
                ans++;
            }
        }
        printf("%d
    ",ans);
        return 0;
    }
    B. Checkpoints
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x1, x2, ..., xn. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary order.

    Vasya wants to pick such checkpoints and the order of visiting them that the total distance travelled is minimized. He asks you to calculate this minimum possible value.

    Input

    The first line of the input contains two integers n and a (1 ≤ n ≤ 100 000,  - 1 000 000 ≤ a ≤ 1 000 000) — the number of checkpoints and Vasya's starting position respectively.

    The second line contains n integers x1, x2, ..., xn ( - 1 000 000 ≤ xi ≤ 1 000 000) — coordinates of the checkpoints.

    Output

    Print one integer — the minimum distance Vasya has to travel in order to visit at least n - 1 checkpoint.

    Examples
    Input
    3 10
    1 7 12
    Output
    7
    Input
    2 0
    11 -10
    Output
    10
    Input
    5 0
    0 0 1000 0 0
    Output
    0
    Note

    In the first sample Vasya has to visit at least two checkpoints. The optimal way to achieve this is the walk to the third checkpoints (distance is 12 - 10 = 2) and then proceed to the second one (distance is 12 - 7 = 5). The total distance is equal to 2 + 5 = 7.

    In the second sample it's enough to visit only one checkpoint so Vasya should just walk to the point  - 10.

    题意:一个坐标轴,起始点a,n个点,求遍历n-1个点的最小距离;

    思路:显然放弃遍历的是最左边或最右边的点,将最小值改成次小值,这样的相当于放弃最左边的点;

       同理右边也是,1特判;

    #include<bits/stdc++.h>
    using namespace std;
    #define ll __int64
    #define mod 1000000007
    #define pi (4*atan(1.0))
    const int N=1e5+10,M=4e6+10,inf=1e9+10;
    int a[N];
    int getans(int x,int y)
    {
        if(a[1]>=y)
        return a[x]-y;
        if(a[x]<=y)
        return y-a[1];
        return min(2*(y-a[1])+a[x]-y,2*(a[x]-y)+(y-a[1]));
    }
    int main()
    {
        int x,y,z,i,t,l,r;
        scanf("%d%d",&x,&y);
        for(i=1;i<=x;i++)
        scanf("%d",&a[i]);
        sort(a+1,a+1+x);
        if(x==1)
        {
            printf("0
    ");
            return 0;
        }
        int ans=inf,a1=a[1];
        a[1]=a[2];
        ans=min(ans,getans(x,y));
        a[1]=a1,a[x]=a[x-1];
        ans=min(ans,getans(x,y));
        printf("%d
    ",ans);
        return 0;
    }
    C. Letters Cyclic Shift
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z' 'y' 'x' 'b' 'a' 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.

    What is the lexicographically minimum string that can be obtained from s by performing this shift exactly once?

    Input

    The only line of the input contains the string s (1 ≤ |s| ≤ 100 000) consisting of lowercase English letters.

    Output

    Print the lexicographically minimum string that can be obtained from s by shifting letters of exactly one non-empty substring.

    Examples
    Input
    codeforces
    Output
    bncdenqbdr
    Input
    abacaba
    Output
    aaacaba
    Note

    题意:将z可以变成y,在ascII码减一,a则变成z,可以改变一个非空子串(必须改变),求字典序最小的答案;

    思路:找到第一个非空且不含a的子串,全为a则改变最后一个;

    #include<bits/stdc++.h>
    using namespace std;
    #define ll __int64
    #define mod 1000000007
    #define pi (4*atan(1.0))
    const int N=1e5+10,M=4e6+10,inf=1e9+10;
    char a[N];
    int main()
    {
        int x,y,z,i,t,l,r;
        scanf("%s",a);
        x=strlen(a);
        for(i=0;i<x;i++)
        if(a[i]!='a')
        break;
        int flag=1;
        for(t=i;t<x;t++)
        {
            if(a[t]=='a')
            break;
            a[t]=a[t]-1;
            flag=0;
        }
        if(flag)
        a[x-1]='z';
        printf("%s
    ",a);
        return 0;
    }
  • 相关阅读:
    把图片转换成二进制--把二进制转换成图片
    .NET 读取视频文件
    winform ListView创建columnHeader的方法
    VUE篇 3、this指向问题、双向数据绑定 、局部/全局组件、父子传值 、兄弟传值(平行组件传值)
    爬虫 5 scrapy框架 虎牙scrapy示例
    爬虫 空气质量爬取分析
    爬虫 4 selenium
    爬虫3 request3高级 代理操作、模拟登录、单线程+多任务异步协程
    爬虫2 数据解析 --图片 、bs4 、xpath 、l乱码的一个解决方法 “|”
    vue篇 2、简单的轮播图 ajax、简单的音乐播放器、计算属性computed
  • 原文地址:https://www.cnblogs.com/jhz033/p/5805885.html
Copyright © 2011-2022 走看看