zoukankan      html  css  js  c++  java
  • 8 9 个人赛(第三题map)

    一:Allen wants to enter a fan zone that occupies a round square and has n entrances.

    There already is a queue of ai people in front of the i-th entrance. Each entrance allows one person from its queue to enter the fan zone in one minute.

    Allen uses the following strategy to enter the fan zone:

    • Initially he stands in the end of the queue in front of the first entrance.
    • Each minute, if he is not allowed into the fan zone during the minute (meaning he is not the first in the queue), he leaves the current queue and stands in the end of the queue of the next entrance (or the first entrance if he leaves the last entrance).

    Determine the entrance through which Allen will finally enter the fan zone.

    Input

    The first line contains a single integer n(2≤n≤105) — the number of entrances.

    The second line contains n integers a1,a2,…,an (0≤ai≤109) — the number of people in queues. These numbers do not include Allen.

    Output

    Print a single integer — the number of entrance that Allen will use.

    Sample Input

    Input

    4
    2 3 2 0

    Output

    3

    Input

    2
    10 10
    

    Output

    1

    Input

    6
    5 2 6 5 7 4

    Output

    6

    Hint

    In the first example the number of people (not including Allen) changes as follows: [2,3,2,0]→[1,2,1,0]→[0,1,0,0]. The number in bold is the queue Alles stands in. We see that he will enter the fan zone through the third entrance.

     题意:排队 开始站在第一队  每分钟进去一个人  每分钟换一次位置  问在第几个门口进去的

    #include <algorithm>
    #include <iostream>
    #include <cstring>
    #include <cstdlib>
    #include <cstdio>
    #include <vector>
    #include <queue>
    #include <deque>
    #include <map>
    using namespace std;
    const int MAX=1e5+10;
    typedef long long ll;
    map <int,int> M;
    int a[MAX];
    int main()
    {
        int i,n;
        scanf("%d",&n);
        for(i=1;i<=n;i++)
            scanf("%d",&a[i]);
        int k=0;
        for(k=0;;k++)
        {
            for(i=1;i<=n;i++)
            {
                if(a[i]-n*k<=i-1)
                {
                    printf("%d
    ",i);
                    return 0;
                }
            }
        }
        return 0;
    }
    

    有一个问题  为什么改成long long 就时间超限?

    二:

    Rudolf is on his way to the castle. Before getting into the castle, the security staff asked him a question:

    Given two binary numbers a and b of length n. How many different ways of swapping two digits in a (only in a, not b) so that bitwise OR of these two numbers will be changed? In other words, let c be the bitwise OR of a and b, you need to find the number of ways of swapping two bits in a so that bitwise OR will not be equal to c.

    Note that binary numbers can contain leading zeros so that length of each number is exactly n.

    Bitwise OR is a binary operation. A result is a binary number which contains a one in each digit if there is a one in at least one of the two numbers. For example, 010102

    OR 100112 = 110112.Well, to your surprise, you are not Rudolf, and you don't need to help him…

    You are the security staff! Please find the number of ways of swapping two bits in a

    so that bitwise OR will be changed.

    Input

    The first line contains one integer n(2≤n≤105) — the number of bits in each number.

    The second line contains a binary number a of length n.The third line contains a binary number b of length n.

    Output

    Print the number of ways to swap two bits in a so that bitwise OR will be changed.

    Sample Input

    Input

    5
    01011
    11001

    Output

    4

    Input

    6
    011000
    010011

    Output

    6

    Hint

    In the first sample, you can swap bits that have indexes (1,4), (2,3), (3,4), and (3,5).

    In the second example, you can swap bits that have indexes (1,2), (1,3), (2,4), (3,4), (3,5), and (3,6).

    题意:两个字符串a b 问有多少种方式使得a中两个位置互换后与b的或结果不同(或的意思是有1就为1)

    思路:上下两位都是1的时候a变不变结果是一样的所以把上下都是0的跟上面是1的换   然后01的跟10的换

    #include <algorithm>
    #include <iostream>
    #include <cstring>
    #include <cstdlib>
    #include <cstdio>
    #include <vector>
    #include <queue>
    #include <deque>
    #include <map>
    using namespace std;
    const int MAX=1e5+10;
    typedef long long ll;
    map <int,int> M;
    int main()
    {
        ll i,j,n;
        char a[101010],b[101010];
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        ll x=0,y=0,p=0,q=0;
        scanf("%lld",&n);
        getchar();
        gets(a);
        gets(b);
        for(i=0;i<n;i++)
        {
            if(a[i]=='1'&&b[i]=='1')
                x++;
            if(a[i]=='0'&&b[i]=='0')
                y++;
            if(a[i]=='1'&&b[i]=='0')
                p++;
            if(a[i]=='0'&&b[i]=='1')
                q++;
        }
        ll ans=x*y+p*(y+q);
        printf("%lld
    ",ans);
        return 0;
    }
    

    三:

    You are given two strings s and t, both consisting only of lowercase Latin letters.

    The substring s[l..r] is the string which is obtained by taking characters sl,sl+1,…,sr without changing the order.

    Each of the occurrences of string a in a string b is a position i (1≤i≤|b|−|a|+1) such that b[i..i+|a|−1]=a (|a| is the length of string a).

    You are asked q queries: for the i-th query you are required to calculate the number of occurrences of string t in a substring s[li..ri].

    Input

    The first line contains three integer numbers n, m and q (1≤n,m≤103, 1≤q≤105) — the length of string s, the length of string t

    and the number of queries, respectively.

    The second line is a string s(|s|=n), consisting only of lowercase Latin letters.

    The third line is a string t(|t|=m), consisting only of lowercase Latin letters.

    Each of the next q lines contains two integer numbers li and ri (1≤li≤ri≤n) — the arguments for the i-th query.

    Output

    Print q lines — the i-th line should contain the answer to the i-th query, that is the number of occurrences of string t in a substring s[li..ri].

    Sample Input

    Input

    10 3 4
    codeforces
    for
    1 3
    3 10
    5 6
    5 7

    Output

    0
    1
    0
    1

    Input

    15 2 3
    abacabadabacaba
    ba
    1 15
    3 4
    2 14

    Output

    4
    0
    3

    Input

    3 5 2
    aaa
    baaab
    1 3
    1 1

    Output

    0
    0

    题意:求t串在s中指定位置出现过几次

    #include <algorithm>
    #include <iostream>
    #include <cstring>
    #include <cstdlib>
    #include <cstdio>
    #include <vector>
    #include <queue>
    #include <deque>
    #include <map>
    using namespace std;
    const int MAX=1e5+10;
    typedef long long ll;
    map <int,int> M;
    int main()
    {
        int n,m,q,i,j,l,r;
        string s,t;
        scanf("%d%d%d",&n,&m,&q);
        cin>>s>>t;
        while(1)
        {
            int tt=s.find(t);
            if(tt!=-1)
            {
                M[tt]++;
                s[tt]='1';
            }
            else
                break;
        }
        while(q--)
        {
            scanf("%d%d",&l,&r);
            l--,r--;
            ll sum=0;
            map<int,int>::iterator it;
            for(it=M.begin();it!=M.end();it++)
            {
                if(it->first>=l&&it->first<=r-m+1)
                    sum++;
            }
            printf("%d
    ",sum);
        }
    
        return 0;
    }
    

    四:

    You received a notebook which is called Death Note. This notebook has infinite number of pages. A rule is written on the last page (huh) of this notebook. It says: "You have to write names in this notebook during n consecutive days. During the i-th day you have to write exactly ai names.". You got scared (of course you got scared, who wouldn't get scared if he just receive a notebook which is named Death Note with a some strange rule written in it?).

    Of course, you decided to follow this rule. When you calmed down, you came up with a strategy how you will write names in the notebook. You have calculated that each page of the notebook can contain exactly m names. You will start writing names from the first page. You will write names on the current page as long as the limit on the number of names on this page is not exceeded. When the current page is over, you turn the page. Note that you always turn the page when it ends, it doesn't matter if it is the last day or not. If after some day the current page still can hold at least one name, during the next day you will continue writing the names from the current page.

    Now you are interested in the following question: how many times will you turn the page during each day? You are interested in the number of pages you will turn each day from 1 to n.

    Input

    The first line of the input contains two integers n, m (1≤n≤2⋅105, 1≤m≤109) — the number of days you will write names in the notebook and the number of names which can be written on each page of the notebook.

    The second line contains n integers a1,a2,…,an (1≤ai≤109), where ai means the number of names you will write in the notebook during the i-th day.

    Output

    Print exactly n integers t1,t2,…,tn, where ti is the number of times you will turn the page during the i-th day.

    Sample Input

    Input

    3 5
    3 7 9

    Output

    0 2 1 

    Input

    4 20
    10 9 19 2

    Output

    0 0 1 1 

    Input

    1 100
    99

    Output

    0 

    Hint

    In the first example pages of the Death Note will look like this [1,1,1,2,2],[2,2,2,2,2],[3,3,3,3,3],[3,3,3,3]. Each number of the array describes during which day name on the corresponding position will be written. It is easy to see that you should turn the first and the second page during the second day and the third page during the third day.

    题意:有n天  一张纸可以写m个字  有n个数字 代表第n天要写几个字  求这写天分别用几张纸

    #include <algorithm>
    #include <iostream>
    #include <cstring>
    #include <cstdlib>
    #include <cstdio>
    #include <vector>
    #include <queue>
    #include <deque>
    #include <map>
    using namespace std;
    const int MAX=1e6;
    typedef long long ll;
    ll a[MAX],b[MAX];
    map<string,ll> m;
    int main()
    {
        ll n,m,i,j;
        scanf("%lld%lld",&n,&m);
        for(i=0;i<n;i++)
            scanf("%lld",&a[i]);
        ll p=0;
        for(i=0;i<n;i++)
        {
            ll x=a[i]/m;
            ll y=a[i]%m;
            if(p+y<m)
            {
                p=p+y;
                b[i]=x;
            }
            else
            {
                p=(p+y)%m;
                b[i]=x+1;
            }
        }
        printf("%lld",b[0]);
        for(i=1;i<n;i++)
            printf(" %lld",b[i]);
        return 0;
    }

    五:

    Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition.There are n flowers in a row in the exhibition. Sonya can put either a rose or a lily in the i-th position. Thus each of n positions should contain exactly one flower: a rose or a lily.

    She knows that exactly m people will visit this exhibition. The i-th visitor will visit all flowers from li to ri inclusive. The girl knows that each segment has its own beauty that is equal to the product of the number of roses and the number of lilies.

    Sonya wants her exhibition to be liked by a lot of people. That is why she wants to put the flowers in such way that the sum of beauties of all segments would be maximum possible.

    Input

    The first line contains two integers n and m (1≤n,m≤103) — the number of flowers and visitors respectively.

    Each of the next m lines contains two integers li and ri (1≤li≤ri≤n), meaning that i-th visitor will visit all flowers from li to riinclusive.

    Output

    Print the string of n characters. The i-th symbol should be «0» if you want to put a rose in the i-th position, otherwise «1» if you want to put a lily.

    If there are multiple answers, print any.

    Sample Input

    Input

    5 3
    1 3
    2 4
    2 5

    Output

    01100

    Input

    6 3
    5 6
    1 4
    4 6
    

    Output

    110010

    Hint

    In the first example, Sonya can put roses in the first, fourth, and fifth positions, and lilies in the second and third positions;

    • in the segment [1…3], there are one rose and two lilies, so the beauty is equal to 1⋅2=2;
    • in the segment [2…4], there are one rose and two lilies, so the beauty is equal to 1⋅2=2;
    • in the segment [2…5], there are two roses and two lilies, so the beauty is equal to 2⋅2=4.
    • The total beauty is equal to 2+2+4=8.

      In the second example, Sonya can put roses in the third, fourth, and sixth positions, and lilies in the first, second, and fifth positions;

      • in the segment [5…6] , there are one rose and one lily, so the beauty is equal to 1⋅1=1;
    •  in the segment [1…4], there are two roses and two lilies, so the beauty is equal to 2⋅2=4;
    • in the segment [4…6], there are two roses and one lily, so the beauty is equal to 2⋅1=2.
    • The total beauty is equal to 1+4+2=7.

     题意:有一排n个格子,每个格子里能放一种花,一共有两种花,一种用 0 代表,另一种用 1 代表,然后给你m各区间,每个区间的价值就是这个区间内的两种花的数量之积。问你应该怎么放花,使得这些区间的价值和最大。

    #include <algorithm>
    #include <iostream>
    #include <cstring>
    #include <cstdlib>
    #include <cstdio>
    #include <vector>
    #include <queue>
    #include <deque>
    #include <map>
    using namespace std;
    const int MAX=1e5+10;
    typedef long long ll;
    map <int,int> M;
    int a[MAX];
    int main()
    {
        int i,n,m,l,r;
        scanf("%d%d",&n,&m);
        while(m--)
            scanf("%d%d",&l,&r);
        for(i=0;i<n;i++)
        {
            if(i%2==0)
                a[i]=1;
            else
                a[i]=0;
            printf("%d",a[i]);
        }
        return 0;
    }
    
  • 相关阅读:
    使用iScroll时,input等不能输入内容的解决方法
    用jquery 写的类似微博发布的效果
    jq 中each的用法 (share)
    Android SDK 安装中组件的离线安装方法 (share)
    HTML5开发手机应用viewport的作用
    Android开发环境搭建及配置phoneGap
    flipsnap手机屏幕水平滑动框架
    解读网站PR值
    文档碎片
    解读SEO 黑帽白帽 (share)
  • 原文地址:https://www.cnblogs.com/zcy19990813/p/9702714.html
Copyright © 2011-2022 走看看